feat: home 1

This commit is contained in:
alwayssuper 2025-02-27 10:39:50 +08:00
parent d6eb0cd850
commit 1b9a3dd4fe
2 changed files with 84 additions and 5 deletions

View File

@ -3,8 +3,8 @@ import request from '@/config/axios'
// IoT 数据统计 API
export const ProductCategoryApi = {
// 查询首页所需数据统计信息
getIotMainStats: async () => {
return await request.get({ url: `/iot/statistics/main`})
getIotMainStats: async (params: any) => {
return await request.get({ url: `/iot/statistics/main`, params })
}
}

View File

@ -117,8 +117,25 @@
<el-col :span="24">
<el-card class="chart-card" shadow="never">
<template #header>
<div class="flex items-center">
<span class="text-base font-medium text-gray-600">消息量统计</span>
<div class="flex items-center justify-between">
<span class="text-base font-medium text-gray-600">上下行消息量统计</span>
<div class="flex items-center space-x-2">
<el-radio-group v-model="timeRange" size="small" @change="handleTimeRangeChange">
<el-radio-button label="1h">最近1小时</el-radio-button>
<el-radio-button label="24h">最近24小时</el-radio-button>
<el-radio-button label="7d">近一周</el-radio-button>
</el-radio-group>
<el-date-picker
v-model="dateRange"
type="datetimerange"
size="small"
range-separator="至"
start-placeholder="开始时间"
end-placeholder="结束时间"
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
@change="handleDateRangeChange"
/>
</div>
</div>
</template>
<div ref="chartMsgStat" class="h-[300px]"></div>
@ -142,6 +159,14 @@ import { Icon } from '@/components/Icon'
/** IoT 首页 */
defineOptions({ name: 'IotHome' })
const timeRange = ref('24h') // 24
const dateRange = ref<[Date, Date] | null>(null)
const queryParams = reactive({
startTime: undefined as number | undefined,
endTime: undefined as number | undefined
})
echarts.use([
TooltipComponent,
LegendComponent,
@ -174,9 +199,54 @@ const statsData = ref({
reportDataStats: []
})
/** 处理快捷时间范围选择 */
const handleTimeRangeChange = (value: string) => {
const now = Date.now()
let startTime: number
switch (value) {
case '1h':
startTime = now - 60 * 60 * 1000
break
case '24h':
startTime = now - 24 * 60 * 60 * 1000
break
case '7d':
startTime = now - 7 * 24 * 60 * 60 * 1000
break
default:
return
}
//
dateRange.value = null
//
queryParams.startTime = startTime
queryParams.endTime = now
//
getStats()
}
/** 处理自定义日期范围选择 */
const handleDateRangeChange = (value: [Date, Date] | null) => {
if (value) {
//
timeRange.value = ''
//
queryParams.startTime = value[0].getTime()
queryParams.endTime = value[1].getTime()
//
getStats()
}
}
/** 获取统计数据 */
const getStats = async () => {
const res = await ProductCategoryApi.getIotMainStats()
const res = await ProductCategoryApi.getIotMainStats(queryParams)
statsData.value = res
initCharts()
}
@ -435,4 +505,13 @@ onMounted(() => {
@apply text-gray-100;
}
}
//
:deep(.el-radio-group) {
@apply mr-4;
}
:deep(.el-date-editor) {
@apply w-[360px];
}
</style>