Commit d1be68d05b4237366f5971705b10029dfd787ce9

Authored by fengtao
1 parent ca012108

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

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