Commit 2b9f422b0e57695d9c47d9d94f777053ce1682b1

Authored by fengtao
1 parent 641a8948

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

... ... @@ -137,10 +137,14 @@
137 137 <div class="mr-4">
138 138 <img
139 139 v-if="!isAdmin(role)"
140   - src="/src/assets/images/msg-count.png"
  140 + src="/src/assets/images/product.png"
  141 + style="width: 5.625rem; height: 5.625rem"
  142 + />
  143 + <img
  144 + v-else
  145 + src="/src/assets/images/product.png"
141 146 style="width: 5.625rem; height: 5.625rem"
142 147 />
143   - <img v-else src="/src/assets/images/kf.png" style="width: 5.625rem; height: 5.625rem" />
144 148 </div>
145 149 <div class="flex-auto">
146 150 <div class="flex justify-between" style="align-items: center">
... ...
1 1 <template>
2   - <div ref="chartRef" :style="{ height, width }"></div>
  2 + <div v-show="dataSeries.length" ref="chartRef" :style="{ height, width }"></div>
  3 + <div v-show="!dataSeries.length"><Empty :image="Empty.PRESENTED_IMAGE_SIMPLE" /></div>
3 4 </template>
4 5 <script lang="ts">
5 6 import { defineComponent, PropType, ref, Ref, onMounted, toRefs } from 'vue';
6 7 import { useECharts } from '/@/hooks/web/useECharts';
  8 + import { Empty } from 'ant-design-vue';
7 9
8 10 export default defineComponent({
  11 + components: { Empty },
9 12 props: {
10 13 width: {
11 14 type: String as PropType<string>,
... ... @@ -65,7 +68,7 @@
65 68 //自适应
66 69 window.addEventListener('resize', () => resize());
67 70 });
68   - return { chartRef };
  71 + return { chartRef, Empty, dataSeries };
69 72 },
70 73 });
71 74 </script>
... ...
... ... @@ -23,15 +23,14 @@
23 23 />
24 24 </div>
25 25 </template>
26   - <div v-if="activeKey === '1'">
27   - <!-- 折线图 -->
  26 + <!-- <div v-if="activeKey === '1'">
28 27 <CustomerAlarmMessage
29 28 v-if="role === 'CUSTOMER_USER'"
30 29 type="CUSTOMER_ALARM_STATISTICAL"
31 30 :customerList="customerAlarmList"
32 31 />
33 32 <VisitAnalysis v-else :alarmList="state.alarmList" />
34   - </div>
  33 + </div> -->
35 34 <div v-if="activeKey === '2'">
36 35 <!-- 柱形图 -->
37 36 <CustomerAlarmMessage
... ... @@ -100,7 +99,7 @@
100 99 <script lang="ts" setup>
101 100 import { ref, reactive } from 'vue';
102 101 import { Card, DatePicker } from 'ant-design-vue';
103   - import VisitAnalysis from './VisitAnalysis.vue';
  102 + // import VisitAnalysis from './VisitAnalysis.vue';
104 103 import VisitAnalysisBar from './VisitAnalysisBar.vue';
105 104 import { isAdmin } from '/@/enums/roleEnum';
106 105 import { useWebSocket } from '@vueuse/core';
... ... @@ -197,7 +196,11 @@
197 196 latestValues: [
198 197 {
199 198 type: 'TIME_SERIES',
200   - key: 'createdAlarmsCountHourly',
  199 + key: 'transportMsgCountHourly',
  200 + },
  201 + {
  202 + type: 'TIME_SERIES',
  203 + key: 'transportDataPointsCountHourly',
201 204 },
202 205 ],
203 206 },
... ... @@ -210,7 +213,7 @@
210 213 {
211 214 cmdId: activeKey.value,
212 215 historyCmd: {
213   - keys: ['createdAlarmsCountHourly'],
  216 + keys: ['transportMsgCountHourly', 'transportDataPointsCountHourly'],
214 217 startTs: Date.now() - 2592000000,
215 218 endTs: Date.now(),
216 219 interval: 86400000,
... ... @@ -240,21 +243,26 @@
240 243 }
241 244 } else {
242 245 if (data) {
243   - const { transportDataPointsCountHourly, transportMsgCountHourly } =
244   - data.data[0].latest.TIME_SERIES;
245   - state.dataPoint = [
246   - transportDataPointsCountHourly.ts,
247   - transportDataPointsCountHourly.value,
248   - ];
249   - state.MsgCount = [
250   - transportDataPointsCountHourly.ts,
251   - transportDataPointsCountHourly.value,
252   - ];
253   - state.dataPointList.push([
254   - transportDataPointsCountHourly.ts,
255   - transportDataPointsCountHourly.value,
256   - ]);
257   - state.messageList.push([transportMsgCountHourly.ts, transportMsgCountHourly.value]);
  246 + console.log('消息数', data);
  247 + if (data) {
  248 + const { transportDataPointsCountHourly, transportMsgCountHourly } =
  249 + data.data[0].latest.TIME_SERIES;
  250 + state.dataPoint = [
  251 + transportDataPointsCountHourly?.ts,
  252 + transportDataPointsCountHourly?.value,
  253 + ];
  254 + state.MsgCount = [
  255 + transportDataPointsCountHourly?.ts,
  256 + transportDataPointsCountHourly?.value,
  257 + ];
  258 + state.dataPointList.push([
  259 + transportDataPointsCountHourly?.ts,
  260 + transportDataPointsCountHourly?.value,
  261 + ]);
  262 + console.log('state.dataPointList', state.dataPointList);
  263 + state.messageList.push([transportMsgCountHourly?.ts, transportMsgCountHourly?.value]);
  264 + console.log('state.messageList', state.messageList);
  265 + }
258 266 }
259 267 if (update) {
260 268 const { transportDataPointsCountHourly, transportMsgCountHourly } = update[0].timeseries;
... ... @@ -268,6 +276,8 @@
268 276 }
269 277 state.dataPointList = newArray;
270 278 state.messageList = newArray1;
  279 + console.log('newArray', state.dataPointList);
  280 + console.log('newArray1', state.messageList);
271 281 }
272 282 }
273 283 },
... ...
... ... @@ -5,7 +5,7 @@
5 5 </div>
6 6 </template>
7 7 <script lang="ts" setup>
8   - import { ref, Ref, watch, withDefaults } from 'vue';
  8 + import { ref, Ref, watch, withDefaults, onMounted } from 'vue';
9 9 import { useECharts } from '/@/hooks/web/useECharts';
10 10 import { Empty } from 'ant-design-vue';
11 11 type DataItem = [number, string];
... ... @@ -23,6 +23,62 @@
23 23 });
24 24 const chartRef = ref<HTMLDivElement | null>(null);
25 25 const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  26 + onMounted(() => {
  27 + // 计算总量
  28 + let dataPointTotal = 0;
  29 + let messageTotal = 0;
  30 + for (const item of props.dataPointList) {
  31 + dataPointTotal += Number(item[1]);
  32 + }
  33 + for (const item of props.messageList) {
  34 + messageTotal += Number(item[1]);
  35 + }
  36 + setOptions({
  37 + tooltip: {
  38 + trigger: 'axis',
  39 + axisPointer: {
  40 + type: 'shadow',
  41 + },
  42 + },
  43 + xAxis: {
  44 + type: 'time',
  45 + },
  46 + legend: {
  47 + data: ['传输数据点', '传输消息量'],
  48 + left: 'center',
  49 + formatter: (name) => {
  50 + return name === '传输数据点' ? `${name} ${dataPointTotal}` : `${name} ${messageTotal}`;
  51 + },
  52 + },
  53 +
  54 + yAxis: {},
  55 + grid: {
  56 + left: '3%',
  57 + right: '4%',
  58 + bottom: '3%',
  59 + containLabel: true,
  60 + },
  61 + series: [
  62 + {
  63 + name: '传输数据点',
  64 + type: 'line',
  65 + stack: 'total',
  66 + data: props.dataPointList,
  67 + // barWidth: '10%',
  68 + color: '#5AEEED',
  69 + },
  70 + {
  71 + name: '传输消息量',
  72 + type: 'line',
  73 + stack: 'total',
  74 + // barWidth: '10%',
  75 + data: props.messageList,
  76 + color: '#3C78FF',
  77 + },
  78 + ],
  79 + });
  80 + });
  81 +
26 82 watch(
27 83 () => [props.dataPointList, props.messageList],
28 84 ([newValue, newValue1]) => {
... ...