Commit 9c6698b8e1bc9a9bc4f2c993b0185e824905bfe8

Authored by fengtao
1 parent 4a40499a

pref:优化代码和优化离线饼图颜色

@@ -212,9 +212,14 @@ @@ -212,9 +212,14 @@
212 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:mr-4" 212 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:mr-4"
213 style="color: #666; width: 50%" 213 style="color: #666; width: 50%"
214 > 214 >
215 - <div class="flex container"> 215 + <div class="flex container ml-4">
216 <div class="mr-4 flex chart-top"> 216 <div class="mr-4 flex chart-top">
217 - <PieChartDeviceSub :legendData="legendData" :seriesData="seriesData" :isCircle="true" /> 217 + <PieChartDeviceSub
  218 + v-if="seriesData.length > 0"
  219 + :legendData="legendData"
  220 + :seriesData="seriesData"
  221 + :isCircle="true"
  222 + />
218 </div> 223 </div>
219 <div class="ml-20 flex justify-around right-text"> 224 <div class="ml-20 flex justify-around right-text">
220 <div class="text"> 225 <div class="text">
@@ -230,9 +235,10 @@ @@ -230,9 +235,10 @@
230 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:ml-1" 235 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:ml-1"
231 style="color: #666; width: 50%" 236 style="color: #666; width: 50%"
232 > 237 >
233 - <div class="flex container"> 238 + <div class="flex container ml-4">
234 <div class="mr-4 flex chart-top"> 239 <div class="mr-4 flex chart-top">
235 <PieChartDeviceSub 240 <PieChartDeviceSub
  241 + v-if="seriesStatusData.length > 0"
236 :legendData="legendStatusData" 242 :legendData="legendStatusData"
237 :seriesData="seriesStatusData" 243 :seriesData="seriesStatusData"
238 :isCircle="false" 244 :isCircle="false"
@@ -282,42 +288,30 @@ @@ -282,42 +288,30 @@
282 288
283 const growCardList = ref<CardList>(); 289 const growCardList = ref<CardList>();
284 290
  291 + const devicePieColor = [
  292 + { key: 'directConnection', itemStyle: { color: '#5C7BD9' }, value: '直连设备' },
  293 + { key: 'gateWay', itemStyle: { color: '#91CC75' }, value: '网关设备' },
  294 + { key: 'sensor', itemStyle: { color: '#FAC859' }, value: '网关子设备' },
  295 + { key: 'inActive', itemStyle: { color: '#5C7BD9' }, value: '待激活' },
  296 + { key: 'onLine', itemStyle: { color: '#91CC75 ' }, value: '在线' },
  297 + { key: 'offLine', itemStyle: { color: '#EC4040' }, value: '离线' },
  298 + ];
  299 +
285 onMounted(async () => { 300 onMounted(async () => {
286 const res = await getHomeData(); 301 const res = await getHomeData();
287 growCardList.value = res; 302 growCardList.value = res;
288 - const devObj = growCardList.value?.deviceInfo;  
289 - for (let o in devObj) {  
290 - if (o === 'directConnection' || o === 'gateWay' || o === 'sensor') {  
291 - seriesData.value.push({  
292 - value:  
293 - o === 'directConnection'  
294 - ? devObj?.directConnection  
295 - : o === 'gateWay'  
296 - ? devObj?.gateWay  
297 - : devObj?.sensor,  
298 - name: o === 'directConnection' ? '直连设备' : o === 'gateWay' ? '网关设备' : '网关子设备',  
299 - itemStyle:  
300 - o === 'directConnection'  
301 - ? { color: '#5C7BD9' }  
302 - : o === 'gateWay'  
303 - ? { color: '#91CC75' }  
304 - : { color: '#FAC859' },  
305 - });  
306 - }  
307 - if (o === 'inActive' || o === 'onLine' || o === 'offLine') {  
308 - seriesStatusData.value.push({  
309 - value:  
310 - o === 'inActive' ? devObj?.inActive : o === 'onLine' ? devObj?.onLine : devObj?.offLine,  
311 - name: o === 'inActive' ? '待激活' : o === 'onLine' ? '在线' : '离线',  
312 - itemStyle:  
313 - o === 'inActive'  
314 - ? { color: '#5C7BD9' }  
315 - : o === 'onLine'  
316 - ? { color: '#91CC75' }  
317 - : { color: '#FAC859' },  
318 - });  
319 - }  
320 - } 303 + const { deviceInfo } = growCardList.value!;
  304 + let data = Object.entries(deviceInfo).map(([key, value]) => {
  305 + const name = devicePieColor?.find((f) => f.key === key)?.value;
  306 + const itemStyle = devicePieColor?.find((f) => f.key === key)?.itemStyle;
  307 + return { key, value, itemStyle, name };
  308 + });
  309 + seriesData.value = data.filter(
  310 + (f) => f.key === 'directConnection' || f.key === 'gateWay' || f.key === 'sensor'
  311 + );
  312 + seriesStatusData.value = data.filter(
  313 + (f) => f.key === 'inActive' || f.key === 'onLine' || f.key === 'offLine'
  314 + );
321 }); 315 });
322 </script> 316 </script>
323 <style lang="css"> 317 <style lang="css">
@@ -43,6 +43,12 @@ @@ -43,6 +43,12 @@
43 43
44 const chartRef = ref<HTMLDivElement | null>(null); 44 const chartRef = ref<HTMLDivElement | null>(null);
45 const { setOptions, resize } = useECharts(chartRef as Ref<HTMLDivElement>); 45 const { setOptions, resize } = useECharts(chartRef as Ref<HTMLDivElement>);
  46 + const labelLine = {
  47 + normal: {
  48 + show: true,
  49 + length2: 1,
  50 + },
  51 + } as any;
46 onMounted(() => { 52 onMounted(() => {
47 setOptions({ 53 setOptions({
48 backgroundColor: '#ffffff', 54 backgroundColor: '#ffffff',
@@ -70,12 +76,7 @@ @@ -70,12 +76,7 @@
70 shadowColor: 'rgba(0, 0, 0, 0.5)', 76 shadowColor: 'rgba(0, 0, 0, 0.5)',
71 }, 77 },
72 }, 78 },
73 - labelLine: {  
74 - normal: {  
75 - show: true,  
76 - length2: 1,  
77 - },  
78 - }, 79 + labelLine,
79 }, 80 },
80 ], 81 ],
81 }); 82 });
@@ -44,6 +44,7 @@ export interface CardList { @@ -44,6 +44,7 @@ export interface CardList {
44 } 44 }
45 export type seriesDataT = { 45 export type seriesDataT = {
46 value: number | undefined; 46 value: number | undefined;
47 - name: string;  
48 - itemStyle: object; 47 + name: string | undefined;
  48 + itemStyle: object | undefined;
  49 + key?: string | undefined;
49 }; 50 };