From 411231395336b5648abe7579b54c6b4f8d17c973 Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Fri, 24 Mar 2023 14:34:19 +0800 Subject: [PATCH] fix: bug#10559 --- src/views/device/DashBoard/index.vue | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/views/device/DashBoard/index.vue b/src/views/device/DashBoard/index.vue index 457a1466..edbd9b2a 100644 --- a/src/views/device/DashBoard/index.vue +++ b/src/views/device/DashBoard/index.vue @@ -84,6 +84,7 @@ import TopCard from '@/views/device/DashBoard/components/TopCard.vue'; import { useMenuStore } from '@/store/menu'; import Amap from './components/Amap.vue'; import { useSystem } from '@/store/system'; +import dayjs from 'dayjs' const system = useSystem(); const AmapKey = system.$state.configInfo.amap?.apiKey; let productTotal = ref(0); @@ -206,6 +207,9 @@ getDeviceData(); * 获取在线数量 */ const getOnline = () => { + const startTime = dayjs().subtract(0, 'days').startOf('day').format('YYYY-MM-DD HH:mm:ss'); + const endTime = dayjs().subtract(0, 'days').endOf('day').format('YYYY-MM-DD HH:mm:ss'); + dashboard([ { dashboard: 'device', @@ -215,26 +219,34 @@ const getOnline = () => { group: 'aggOnline', params: { state: 'online', - limit: 15, - from: 'now-15d', - time: '1d', - format: 'yyyy-MM-dd', + limit: 24, + from: startTime, + to: endTime, + time: '1h', + format: 'yyyy-MM-dd HH:mm:ss', }, }, ]).then((res) => { if (res.status == 200) { - const x = res.result - .map((item: any) => item.data.timeString) - .reverse(); - const y = res.result.map((item: any) => item.data.value); + // const x = res.result + // .map((item: any) => item.data.timeString) + // .reverse(); + // const y = res.result.map((item: any) => item.data.value); + const x: string[] = []; + const y: number[] = []; + (res.result as any)?.forEach((item: any) => { + x.push(item.data.timeString) + y.push(item.data.value) + }) + x.reverse() const onlineYdata = y; onlineYdata.reverse(); - setOnlineChartOpition(x, onlineYdata); + setOnlineChartOption(x, onlineYdata); onlineFooter.value[0].value = y?.[1]; } }); }; -const setOnlineChartOpition = (x: Array, y: Array): void => { +const setOnlineChartOption = (x: Array, y: Array): void => { onlineOptions.value = { xAxis: { type: 'category',