10
10
<span class =" text-gray-500 text-base font-medium" >品类数量</span >
11
11
<Icon icon =" ep:menu" class =" text-[32px] text-blue-400" />
12
12
</div >
13
- <span class =" text-3xl font-bold text-gray-700" >{{ statsData.categoryTotal }}</span >
13
+ <span class =" text-3xl font-bold text-gray-700" >{{ statsData.productCategoryCount }}</span >
14
14
<el-divider class =" my-2" />
15
15
<div class =" flex justify-between items-center text-gray-400 text-sm" >
16
16
<span >今日新增</span >
17
- <span class =" text-green-500" >↑ {{ statsData.categoryTodayTotal }}</span >
17
+ <span class =" text-green-500" >↑ {{ statsData.productCategoryTodayCount }}</span >
18
18
</div >
19
19
</div >
20
20
</el-card >
26
26
<span class =" text-gray-500 text-base font-medium" >产品数量</span >
27
27
<Icon icon =" ep:box" class =" text-[32px] text-orange-400" />
28
28
</div >
29
- <span class =" text-3xl font-bold text-gray-700" >{{ statsData.productTotal }}</span >
29
+ <span class =" text-3xl font-bold text-gray-700" >{{ statsData.productCount }}</span >
30
30
<el-divider class =" my-2" />
31
31
<div class =" flex justify-between items-center text-gray-400 text-sm" >
32
32
<span >今日新增</span >
33
- <span class =" text-green-500" >↑ {{ statsData.productTodayTotal }}</span >
33
+ <span class =" text-green-500" >↑ {{ statsData.productTodayCount }}</span >
34
34
</div >
35
35
</div >
36
36
</el-card >
42
42
<span class =" text-gray-500 text-base font-medium" >设备数量</span >
43
43
<Icon icon =" ep:cpu" class =" text-[32px] text-purple-400" />
44
44
</div >
45
- <span class =" text-3xl font-bold text-gray-700" >{{ statsData.deviceTotal }}</span >
45
+ <span class =" text-3xl font-bold text-gray-700" >{{ statsData.deviceCount }}</span >
46
46
<el-divider class =" my-2" />
47
47
<div class =" flex justify-between items-center text-gray-400 text-sm" >
48
48
<span >今日新增</span >
49
- <span class =" text-green-500" >↑ {{ statsData.deviceTodayTotal }}</span >
49
+ <span class =" text-green-500" >↑ {{ statsData.deviceTodayCount }}</span >
50
50
</div >
51
51
</div >
52
52
</el-card >
58
58
<span class =" text-gray-500 text-base font-medium" >物模型消息</span >
59
59
<Icon icon =" ep:message" class =" text-[32px] text-teal-400" />
60
60
</div >
61
- <span class =" text-3xl font-bold text-gray-700" >{{ statsData.reportTotal }}</span >
61
+ <span class =" text-3xl font-bold text-gray-700" >{{ statsData.deviceMessageCount }}</span >
62
62
<el-divider class =" my-2" />
63
63
<div class =" flex justify-between items-center text-gray-400 text-sm" >
64
64
<span >今日新增</span >
65
- <span class =" text-green-500" >↑ {{ statsData.reportTodayTotal }}</span >
65
+ <span class =" text-green-500" >↑ {{ statsData.deviceMessageTodayCount }}</span >
66
66
</div >
67
67
</div >
68
68
</el-card >
@@ -152,7 +152,7 @@ import { TooltipComponent, LegendComponent, TitleComponent, ToolboxComponent, Gr
152
152
import { PieChart , LineChart , GaugeChart } from ' echarts/charts'
153
153
import { LabelLayout , UniversalTransition } from ' echarts/features'
154
154
import { CanvasRenderer } from ' echarts/renderers'
155
- import { ProductCategoryApi } from ' @/api/iot/statistics'
155
+ import { ProductCategoryApi , IotStatisticsSummaryRespVO , IotStatisticsDeviceMessageSummaryRespVO } from ' @/api/iot/statistics'
156
156
import { formatDate } from ' @/utils/formatTime'
157
157
import { Icon } from ' @/components/Icon'
158
158
@@ -187,20 +187,27 @@ const chartDeviceOffline = ref()
187
187
const chartDeviceActive = ref ()
188
188
const chartMsgStat = ref ()
189
189
190
- const statsData = ref ({
191
- categoryTotal: 0 ,
192
- productTotal: 0 ,
193
- deviceTotal: 0 ,
194
- reportTotal: 0 ,
195
- categoryTodayTotal: 0 ,
196
- productTodayTotal: 0 ,
197
- deviceTodayTotal: 0 ,
198
- reportTodayTotal: 0 ,
199
- onlineTotal: 0 ,
200
- offlineTotal: 0 ,
201
- neverOnlineTotal: 0 ,
202
- deviceStatsOfCategory: [],
203
- reportDataStats: []
190
+
191
+ // 基础统计数据
192
+ const statsData = ref <IotStatisticsSummaryRespVO >({
193
+ productCategoryCount: 0 ,
194
+ productCount: 0 ,
195
+ deviceCount: 0 ,
196
+ deviceMessageCount: 0 ,
197
+ productCategoryTodayCount: 0 ,
198
+ productTodayCount: 0 ,
199
+ deviceTodayCount: 0 ,
200
+ deviceMessageTodayCount: 0 ,
201
+ deviceOnlineCount: 0 ,
202
+ deviceOfflineCount: 0 ,
203
+ deviceInactiveCount: 0 ,
204
+ productCategoryDeviceCounts: {}
205
+ })
206
+
207
+ // 消息统计数据
208
+ const messageStats = ref <IotStatisticsDeviceMessageSummaryRespVO >({
209
+ upstreamCounts: {},
210
+ downstreamCounts: {}
204
211
})
205
212
206
213
/** 处理快捷时间范围选择 */
@@ -250,8 +257,15 @@ const handleDateRangeChange = (value: [Date, Date] | null) => {
250
257
251
258
/** 获取统计数据 */
252
259
const getStats = async () => {
253
- const res = await ProductCategoryApi .getIotMainStats (queryParams )
254
- statsData .value = res
260
+ // 获取基础统计数据
261
+ const summaryRes = await ProductCategoryApi .getIotStatisticsSummary ()
262
+ statsData .value = summaryRes
263
+
264
+ // 获取消息统计数据
265
+ const messageRes = await ProductCategoryApi .getIotStatisticsDeviceMessageSummary (queryParams )
266
+ messageStats .value = messageRes
267
+
268
+ // 初始化图表
255
269
initCharts ()
256
270
}
257
271
@@ -290,19 +304,22 @@ const initCharts = () => {
290
304
labelLine: {
291
305
show: false
292
306
},
293
- data: statsData .value .deviceStatsOfCategory
307
+ data: Object .entries (statsData .value .productCategoryDeviceCounts ).map (([name , value ]) => ({
308
+ name ,
309
+ value
310
+ }))
294
311
}
295
312
]
296
313
})
297
314
298
315
// 在线设备统计
299
- initGaugeChart (chartDeviceOnline .value , statsData .value .onlineTotal , ' #0d9' )
316
+ initGaugeChart (chartDeviceOnline .value , statsData .value .deviceOnlineCount , ' #0d9' )
300
317
301
318
// 离线设备统计
302
- initGaugeChart (chartDeviceOffline .value , statsData .value .offlineTotal , ' #f50' )
319
+ initGaugeChart (chartDeviceOffline .value , statsData .value .deviceOfflineCount , ' #f50' )
303
320
304
321
// 待激活设备统计
305
- initGaugeChart (chartDeviceActive .value , statsData .value .neverOnlineTotal , ' #05b' )
322
+ initGaugeChart (chartDeviceActive .value , statsData .value .deviceInactiveCount , ' #05b' )
306
323
307
324
// 消息量统计
308
325
initMessageChart ()
@@ -317,7 +334,7 @@ const initGaugeChart = (el: any, value: number, color: string) => {
317
334
startAngle: 360 ,
318
335
endAngle: 0 ,
319
336
min: 0 ,
320
- max: statsData .value .deviceTotal || 100 , // 使用设备总数作为最大值
337
+ max: statsData .value .deviceCount || 100 , // 使用设备总数作为最大值
321
338
progress: {
322
339
show: true ,
323
340
width: 12 ,
@@ -356,18 +373,16 @@ const initGaugeChart = (el: any, value: number, color: string) => {
356
373
357
374
/** 初始化消息统计图表 */
358
375
const initMessageChart = () => {
359
- const xdata: string [] = []
360
- const upData: string [] = []
361
- const downData: string [] = []
362
-
363
- statsData .value .deviceUpMessageStats .forEach ((msg ) => {
364
- xdata .push (formatDate (msg .time , ' YYYY-MM-DD HH:mm' ))
365
- upData .push (msg .data )
366
- })
367
-
368
- statsData .value .deviceDownMessageStats .forEach ((msg ) => {
369
- downData .push (msg .data )
370
- })
376
+ const timestamps = Array .from (
377
+ new Set ([
378
+ ... Object .keys (messageStats .value .upstreamCounts ),
379
+ ... Object .keys (messageStats .value .downstreamCounts )
380
+ ])
381
+ ).sort ()
382
+
383
+ const xdata = timestamps .map (ts => formatDate (Number (ts ), ' YYYY-MM-DD HH:mm' ))
384
+ const upData = timestamps .map (ts => messageStats .value .upstreamCounts [Number (ts )] || 0 )
385
+ const downData = timestamps .map (ts => messageStats .value .downstreamCounts [Number (ts )] || 0 )
371
386
372
387
echarts .init (chartMsgStat .value ).setOption ({
373
388
tooltip: {
0 commit comments