Commit d1be68d05b4237366f5971705b10029dfd787ce9

Authored by fengtao
1 parent ca012108

feat:首页新增饼状图和调整部分样式

@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:mr-4" 5 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:mr-4"
6 style="color: #666; width: 50%" 6 style="color: #666; width: 50%"
7 > 7 >
8 - <div class="flex"> 8 + <div class="flex container">
9 <div class="mr-4 flex chart-top"> 9 <div class="mr-4 flex chart-top">
10 <PieChartDeviceSub :legendData="legendData" :seriesData="seriesData" /> 10 <PieChartDeviceSub :legendData="legendData" :seriesData="seriesData" />
11 </div> 11 </div>
@@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
21 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:ml-1" 21 class="md:w-1/3 w-full !md:mt-0 !mt-4 !md:ml-1"
22 style="color: #666; width: 50%" 22 style="color: #666; width: 50%"
23 > 23 >
24 - <div class="flex"> 24 + <div class="flex container">
25 <div class="mr-4 flex chart-top"> 25 <div class="mr-4 flex chart-top">
26 <PieChartDeviceSub :legendData="legendStatusData" :seriesData="seriesStatusData" /> 26 <PieChartDeviceSub :legendData="legendStatusData" :seriesData="seriesStatusData" />
27 </div> 27 </div>
@@ -76,15 +76,15 @@ @@ -76,15 +76,15 @@
76 const growCardList = ref<CardList>(); 76 const growCardList = ref<CardList>();
77 const legendData = ref<string[]>(['gateway', 'directly', 'sub-device']); 77 const legendData = ref<string[]>(['gateway', 'directly', 'sub-device']);
78 const seriesData = ref([ 78 const seriesData = ref([
79 - { value: 1048, name: 'gateway' },  
80 - { value: 735, name: 'directly' },  
81 - { value: 580, name: 'sub-device' }, 79 + { value: 1048, name: 'gateway', itemStyle: { color: '#3aa0ff' } },
  80 + { value: 735, name: 'directly', itemStyle: { color: '#36cbcb' } },
  81 + { value: 580, name: 'sub-device', itemStyle: { color: '#4ecb73' } },
82 ]); 82 ]);
83 const legendStatusData = ref<string[]>(['inactive', 'online', 'offline']); 83 const legendStatusData = ref<string[]>(['inactive', 'online', 'offline']);
84 const seriesStatusData = ref([ 84 const seriesStatusData = ref([
85 - { value: 1048, name: 'inactive' },  
86 - { value: 735, name: 'online' },  
87 - { value: 580, name: 'offline' }, 85 + { value: 1048, name: 'inactive', itemStyle: { color: '#3aa0ff' } },
  86 + { value: 735, name: 'online', itemStyle: { color: '#36cbcb' } },
  87 + { value: 580, name: 'offline', itemStyle: { color: '#4ecb73' } },
88 ]); 88 ]);
89 onMounted(async () => { 89 onMounted(async () => {
90 const res = await getHomeData(); 90 const res = await getHomeData();
@@ -94,19 +94,27 @@ @@ -94,19 +94,27 @@
94 94
95 <style lang="css"> 95 <style lang="css">
96 .right-text { 96 .right-text {
  97 + width: 40%;
97 flex-direction: column; 98 flex-direction: column;
98 - height: 200px; 99 + height: 240px;
99 margin: 10px 0 10px 50px; 100 margin: 10px 0 10px 50px;
100 - flex-wrap: nowrap;  
101 } 101 }
102 102
103 .text { 103 .text {
104 color: #333; 104 color: #333;
105 font-weight: bold; 105 font-weight: bold;
  106 + display: flex;
  107 + flex-wrap: nowrap;
106 } 108 }
107 109
108 .chart-top { 110 .chart-top {
  111 + width: 60%;
  112 + height: 300px;
109 align-items: center; 113 align-items: center;
110 margin-top: -30px; 114 margin-top: -30px;
111 } 115 }
  116 +
  117 + .container {
  118 + width: 100%;
  119 + }
112 </style> 120 </style>
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 props: { 9 props: {
10 width: { 10 width: {
11 type: String as PropType<string>, 11 type: String as PropType<string>,
12 - default: '300px', 12 + default: '100%',
13 }, 13 },
14 height: { 14 height: {
15 type: String as PropType<string>, 15 type: String as PropType<string>,
@@ -28,26 +28,29 @@ @@ -28,26 +28,29 @@
28 const { legendData, seriesData } = toRefs(props); 28 const { legendData, seriesData } = toRefs(props);
29 const dataSeries = ref<any>([]); 29 const dataSeries = ref<any>([]);
30 const legendDatas = ref<any>([]); 30 const legendDatas = ref<any>([]);
31 - dataSeries.value = seriesData;  
32 - legendDatas.value = legendData; 31 + dataSeries.value = seriesData.value;
  32 + legendDatas.value = legendData.value;
  33 +
33 const chartRef = ref<HTMLDivElement | null>(null); 34 const chartRef = ref<HTMLDivElement | null>(null);
34 - const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>); 35 + const { setOptions, resize } = useECharts(chartRef as Ref<HTMLDivElement>);
35 onMounted(() => { 36 onMounted(() => {
36 setOptions({ 37 setOptions({
37 backgroundColor: '#ffffff', 38 backgroundColor: '#ffffff',
38 tooltip: { 39 tooltip: {
39 trigger: 'item', 40 trigger: 'item',
  41 + formatter: '{b} ({d}%)',
40 }, 42 },
41 legend: { 43 legend: {
42 - bottom: 10, 44 + bottom: 0,
43 left: 'center', 45 left: 'center',
44 data: legendDatas, 46 data: legendDatas,
45 }, 47 },
  48 + color: ['red', '#5470c6', '#91cd77'],
46 series: [ 49 series: [
47 { 50 {
48 name: 'Access From', 51 name: 'Access From',
49 type: 'pie', 52 type: 'pie',
50 - radius: '50%', 53 + radius: '60%',
51 data: dataSeries, 54 data: dataSeries,
52 emphasis: { 55 emphasis: {
53 itemStyle: { 56 itemStyle: {
@@ -59,6 +62,8 @@ @@ -59,6 +62,8 @@
59 }, 62 },
60 ], 63 ],
61 }); 64 });
  65 + //自适应
  66 + window.addEventListener('resize', () => resize());
62 }); 67 });
63 return { chartRef }; 68 return { chartRef };
64 }, 69 },