Skip to content

Commit 1b9a3dd

Browse files
committed
feat: home 1
1 parent d6eb0cd commit 1b9a3dd

File tree

2 files changed

+84
-5
lines changed

2 files changed

+84
-5
lines changed

src/api/iot/statistics/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import request from '@/config/axios'
33
// IoT 数据统计 API
44
export const ProductCategoryApi = {
55
// 查询首页所需数据统计信息
6-
getIotMainStats: async () => {
7-
return await request.get({ url: `/iot/statistics/main`})
6+
getIotMainStats: async (params: any) => {
7+
return await request.get({ url: `/iot/statistics/main`, params })
88
}
99

1010
}

src/views/iot/home/index.vue

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,25 @@
117117
<el-col :span="24">
118118
<el-card class="chart-card" shadow="never">
119119
<template #header>
120-
<div class="flex items-center">
121-
<span class="text-base font-medium text-gray-600">消息量统计</span>
120+
<div class="flex items-center justify-between">
121+
<span class="text-base font-medium text-gray-600">上下行消息量统计</span>
122+
<div class="flex items-center space-x-2">
123+
<el-radio-group v-model="timeRange" size="small" @change="handleTimeRangeChange">
124+
<el-radio-button label="1h">最近1小时</el-radio-button>
125+
<el-radio-button label="24h">最近24小时</el-radio-button>
126+
<el-radio-button label="7d">近一周</el-radio-button>
127+
</el-radio-group>
128+
<el-date-picker
129+
v-model="dateRange"
130+
type="datetimerange"
131+
size="small"
132+
range-separator=""
133+
start-placeholder="开始时间"
134+
end-placeholder="结束时间"
135+
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
136+
@change="handleDateRangeChange"
137+
/>
138+
</div>
122139
</div>
123140
</template>
124141
<div ref="chartMsgStat" class="h-[300px]"></div>
@@ -142,6 +159,14 @@ import { Icon } from '@/components/Icon'
142159
/** IoT 首页 */
143160
defineOptions({ name: 'IotHome' })
144161
162+
const timeRange = ref('24h') // 默认选择最近24小时
163+
const dateRange = ref<[Date, Date] | null>(null)
164+
165+
const queryParams = reactive({
166+
startTime: undefined as number | undefined,
167+
endTime: undefined as number | undefined
168+
})
169+
145170
echarts.use([
146171
TooltipComponent,
147172
LegendComponent,
@@ -174,9 +199,54 @@ const statsData = ref({
174199
reportDataStats: []
175200
})
176201
202+
/** 处理快捷时间范围选择 */
203+
const handleTimeRangeChange = (value: string) => {
204+
const now = Date.now()
205+
let startTime: number
206+
207+
switch (value) {
208+
case '1h':
209+
startTime = now - 60 * 60 * 1000
210+
break
211+
case '24h':
212+
startTime = now - 24 * 60 * 60 * 1000
213+
break
214+
case '7d':
215+
startTime = now - 7 * 24 * 60 * 60 * 1000
216+
break
217+
default:
218+
return
219+
}
220+
221+
// 清空日期选择器
222+
dateRange.value = null
223+
224+
// 更新查询参数
225+
queryParams.startTime = startTime
226+
queryParams.endTime = now
227+
228+
// 重新获取数据
229+
getStats()
230+
}
231+
232+
/** 处理自定义日期范围选择 */
233+
const handleDateRangeChange = (value: [Date, Date] | null) => {
234+
if (value) {
235+
// 清空快捷选项
236+
timeRange.value = ''
237+
238+
// 更新查询参数
239+
queryParams.startTime = value[0].getTime()
240+
queryParams.endTime = value[1].getTime()
241+
242+
// 重新获取数据
243+
getStats()
244+
}
245+
}
246+
177247
/** 获取统计数据 */
178248
const getStats = async () => {
179-
const res = await ProductCategoryApi.getIotMainStats()
249+
const res = await ProductCategoryApi.getIotMainStats(queryParams)
180250
statsData.value = res
181251
initCharts()
182252
}
@@ -435,4 +505,13 @@ onMounted(() => {
435505
@apply text-gray-100;
436506
}
437507
}
508+
509+
// 添加时间选择器样式
510+
:deep(.el-radio-group) {
511+
@apply mr-4;
512+
}
513+
514+
:deep(.el-date-editor) {
515+
@apply w-[360px];
516+
}
438517
</style>

0 commit comments

Comments
 (0)