Skip to content

Commit 5137b4a

Browse files
committed
home
1 parent 4547fbf commit 5137b4a

File tree

2 files changed

+95
-46
lines changed

2 files changed

+95
-46
lines changed

src/api/iot/statistics/index.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,44 @@
11
import request from '@/config/axios'
22

3+
/** 统计数据类型 */
4+
export interface IotStatisticsSummaryRespVO {
5+
productCategoryCount: number
6+
productCount: number
7+
deviceCount: number
8+
deviceMessageCount: number
9+
productCategoryTodayCount: number
10+
productTodayCount: number
11+
deviceTodayCount: number
12+
deviceMessageTodayCount: number
13+
deviceOnlineCount: number
14+
deviceOfflineCount: number
15+
deviceInactiveCount: number
16+
productCategoryDeviceCounts: Record<string, number>
17+
}
18+
19+
/** 消息统计数据类型 */
20+
export interface IotStatisticsDeviceMessageSummaryRespVO {
21+
upstreamCounts: Record<number, number>
22+
downstreamCounts: Record<number, number>
23+
}
24+
325
// IoT 数据统计 API
426
export const ProductCategoryApi = {
5-
// 查询首页所需数据统计信息
6-
getIotMainStats: async (params: any) => {
7-
return await request.get({ url: `/iot/statistics/main`, params })
8-
}
27+
// 查询IoT基础数据统计
28+
getIotStatisticsSummary: async () => {
29+
return await request.get<IotStatisticsSummaryRespVO>({
30+
url: `/iot/statistics/get-summary`
31+
})
32+
},
933

34+
// 查询IoT上下行消息数据统计
35+
getIotStatisticsDeviceMessageSummary: async (params: {
36+
startTime: number
37+
endTime: number
38+
}) => {
39+
return await request.get<IotStatisticsDeviceMessageSummaryRespVO>({
40+
url: `/iot/statistics/get-log-summary`,
41+
params
42+
})
43+
}
1044
}

src/views/iot/home/index.vue

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<span class="text-gray-500 text-base font-medium">品类数量</span>
1111
<Icon icon="ep:menu" class="text-[32px] text-blue-400" />
1212
</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>
1414
<el-divider class="my-2" />
1515
<div class="flex justify-between items-center text-gray-400 text-sm">
1616
<span>今日新增</span>
17-
<span class="text-green-500">↑ {{ statsData.categoryTodayTotal }}</span>
17+
<span class="text-green-500">↑ {{ statsData.productCategoryTodayCount }}</span>
1818
</div>
1919
</div>
2020
</el-card>
@@ -26,11 +26,11 @@
2626
<span class="text-gray-500 text-base font-medium">产品数量</span>
2727
<Icon icon="ep:box" class="text-[32px] text-orange-400" />
2828
</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>
3030
<el-divider class="my-2" />
3131
<div class="flex justify-between items-center text-gray-400 text-sm">
3232
<span>今日新增</span>
33-
<span class="text-green-500">↑ {{ statsData.productTodayTotal }}</span>
33+
<span class="text-green-500">↑ {{ statsData.productTodayCount }}</span>
3434
</div>
3535
</div>
3636
</el-card>
@@ -42,11 +42,11 @@
4242
<span class="text-gray-500 text-base font-medium">设备数量</span>
4343
<Icon icon="ep:cpu" class="text-[32px] text-purple-400" />
4444
</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>
4646
<el-divider class="my-2" />
4747
<div class="flex justify-between items-center text-gray-400 text-sm">
4848
<span>今日新增</span>
49-
<span class="text-green-500">↑ {{ statsData.deviceTodayTotal }}</span>
49+
<span class="text-green-500">↑ {{ statsData.deviceTodayCount }}</span>
5050
</div>
5151
</div>
5252
</el-card>
@@ -58,11 +58,11 @@
5858
<span class="text-gray-500 text-base font-medium">物模型消息</span>
5959
<Icon icon="ep:message" class="text-[32px] text-teal-400" />
6060
</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>
6262
<el-divider class="my-2" />
6363
<div class="flex justify-between items-center text-gray-400 text-sm">
6464
<span>今日新增</span>
65-
<span class="text-green-500">↑ {{ statsData.reportTodayTotal }}</span>
65+
<span class="text-green-500">↑ {{ statsData.deviceMessageTodayCount }}</span>
6666
</div>
6767
</div>
6868
</el-card>
@@ -152,7 +152,7 @@ import { TooltipComponent, LegendComponent, TitleComponent, ToolboxComponent, Gr
152152
import { PieChart, LineChart, GaugeChart } from 'echarts/charts'
153153
import { LabelLayout, UniversalTransition } from 'echarts/features'
154154
import { CanvasRenderer } from 'echarts/renderers'
155-
import { ProductCategoryApi } from '@/api/iot/statistics'
155+
import { ProductCategoryApi,IotStatisticsSummaryRespVO, IotStatisticsDeviceMessageSummaryRespVO} from '@/api/iot/statistics'
156156
import { formatDate } from '@/utils/formatTime'
157157
import { Icon } from '@/components/Icon'
158158
@@ -187,20 +187,27 @@ const chartDeviceOffline = ref()
187187
const chartDeviceActive = ref()
188188
const chartMsgStat = ref()
189189
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: {}
204211
})
205212
206213
/** 处理快捷时间范围选择 */
@@ -250,8 +257,15 @@ const handleDateRangeChange = (value: [Date, Date] | null) => {
250257
251258
/** 获取统计数据 */
252259
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+
// 初始化图表
255269
initCharts()
256270
}
257271
@@ -290,19 +304,22 @@ const initCharts = () => {
290304
labelLine: {
291305
show: false
292306
},
293-
data: statsData.value.deviceStatsOfCategory
307+
data: Object.entries(statsData.value.productCategoryDeviceCounts).map(([name, value]) => ({
308+
name,
309+
value
310+
}))
294311
}
295312
]
296313
})
297314
298315
// 在线设备统计
299-
initGaugeChart(chartDeviceOnline.value, statsData.value.onlineTotal, '#0d9')
316+
initGaugeChart(chartDeviceOnline.value, statsData.value.deviceOnlineCount, '#0d9')
300317
301318
// 离线设备统计
302-
initGaugeChart(chartDeviceOffline.value, statsData.value.offlineTotal, '#f50')
319+
initGaugeChart(chartDeviceOffline.value, statsData.value.deviceOfflineCount, '#f50')
303320
304321
// 待激活设备统计
305-
initGaugeChart(chartDeviceActive.value, statsData.value.neverOnlineTotal, '#05b')
322+
initGaugeChart(chartDeviceActive.value, statsData.value.deviceInactiveCount, '#05b')
306323
307324
// 消息量统计
308325
initMessageChart()
@@ -317,7 +334,7 @@ const initGaugeChart = (el: any, value: number, color: string) => {
317334
startAngle: 360,
318335
endAngle: 0,
319336
min: 0,
320-
max: statsData.value.deviceTotal || 100, // 使用设备总数作为最大值
337+
max: statsData.value.deviceCount || 100, // 使用设备总数作为最大值
321338
progress: {
322339
show: true,
323340
width: 12,
@@ -356,18 +373,16 @@ const initGaugeChart = (el: any, value: number, color: string) => {
356373
357374
/** 初始化消息统计图表 */
358375
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)
371386
372387
echarts.init(chartMsgStat.value).setOption({
373388
tooltip: {

0 commit comments

Comments
 (0)