From a1e6982a282b12ba79e14dd673e82c5e7ccf9956 Mon Sep 17 00:00:00 2001 From: haohao <1036606149@qq.com> Date: Sun, 23 Nov 2025 15:07:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=E3=80=90antd=E3=80=91=E3=80=90iot?= =?UTF-8?q?=E3=80=91=E9=87=8D=E6=9E=84=E9=A6=96=E9=A1=B5=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=EF=BC=8C=E4=BC=98=E5=8C=96=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=92=8C=E6=95=B0=E6=8D=AE=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A7=BB=E9=99=A4=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=AF=94=E8=BE=83=E5=8D=A1=E7=89=87=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/iot/home/chart-options.ts | 185 ++++++++++--- apps/web-antd/src/views/iot/home/data.ts | 90 +----- apps/web-antd/src/views/iot/home/index.vue | 70 ++++- .../iot/home/modules/comparison-card.vue | 81 ------ .../iot/home/modules/device-count-card.vue | 83 +----- .../home/modules/device-state-count-card.vue | 111 +++----- .../iot/home/modules/message-trend-card.vue | 260 ++++++------------ .../card/comparison-card/comparison-card.vue | 66 +++++ .../components/card/comparison-card/index.ts | 4 + .../components/card/comparison-card/types.ts | 15 + .../effects/common-ui/src/components/index.ts | 1 + 11 files changed, 429 insertions(+), 537 deletions(-) delete mode 100644 apps/web-antd/src/views/iot/home/modules/comparison-card.vue create mode 100644 packages/effects/common-ui/src/components/card/comparison-card/comparison-card.vue create mode 100644 packages/effects/common-ui/src/components/card/comparison-card/index.ts create mode 100644 packages/effects/common-ui/src/components/card/comparison-card/types.ts diff --git a/apps/web-antd/src/views/iot/home/chart-options.ts b/apps/web-antd/src/views/iot/home/chart-options.ts index 2d481a69e..b581afcdb 100644 --- a/apps/web-antd/src/views/iot/home/chart-options.ts +++ b/apps/web-antd/src/views/iot/home/chart-options.ts @@ -1,39 +1,74 @@ -/** 设备数量饼图配置 */ -// TODO @haohao:貌似没用到?? -export function getDeviceCountChartOptions( - productCategoryDeviceCounts: Record, +/** + * 消息趋势图表配置 + */ +export function getMessageTrendChartOptions( + times: string[], + upstreamData: number[], + downstreamData: number[], ): any { - const data = Object.entries(productCategoryDeviceCounts).map( - ([name, value]) => ({ name, value }), - ); - return { tooltip: { - trigger: 'item', - formatter: '{b}: {c} 个 ({d}%)', + trigger: 'axis', + axisPointer: { + type: 'cross', + label: { + backgroundColor: '#6a7985', + }, + }, }, legend: { + data: ['上行消息', '下行消息'], top: '5%', - right: '10%', - orient: 'vertical', }, + grid: { + left: '3%', + right: '4%', + bottom: '3%', + top: '15%', + containLabel: true, + }, + xAxis: [ + { + type: 'category', + boundaryGap: false, + data: times, + }, + ], + yAxis: [ + { + type: 'value', + name: '消息数量', + }, + ], series: [ { - name: '设备数量', - type: 'pie', - radius: ['50%', '80%'], - center: ['30%', '50%'], - data, - emphasis: { - itemStyle: { - shadowBlur: 10, - shadowOffsetX: 0, - shadowColor: 'rgba(0, 0, 0, 0.5)', - }, + name: '上行消息', + type: 'line', + smooth: true, + areaStyle: { + opacity: 0.3, }, - label: { - show: true, - formatter: '{b}: {c}', + emphasis: { + focus: 'series', + }, + data: upstreamData, + itemStyle: { + color: '#1890ff', + }, + }, + { + name: '下行消息', + type: 'line', + smooth: true, + areaStyle: { + opacity: 0.3, + }, + emphasis: { + focus: 'series', + }, + data: downstreamData, + itemStyle: { + color: '#52c41a', }, }, ], @@ -41,9 +76,9 @@ export function getDeviceCountChartOptions( } /** - * 仪表盘图表配置 + * 设备状态仪表盘图表配置 */ -export function getGaugeChartOptions( +export function getDeviceStateGaugeChartOptions( value: number, max: number, color: string, @@ -53,12 +88,12 @@ export function getGaugeChartOptions( series: [ { type: 'gauge', - startAngle: 180, - endAngle: 0, + startAngle: 225, + endAngle: -45, min: 0, max, - center: ['50%', '70%'], - radius: '120%', + center: ['50%', '50%'], + radius: '80%', progress: { show: true, width: 12, @@ -69,29 +104,95 @@ export function getGaugeChartOptions( axisLine: { lineStyle: { width: 12, - color: [[1, '#E5E7EB']], + color: [[1, '#E5E7EB']] as [number, string][], }, }, axisTick: { show: false }, splitLine: { show: false }, axisLabel: { show: false }, pointer: { show: false }, - detail: { - valueAnimation: true, - fontSize: 24, - fontWeight: 'bold', - color, - offsetCenter: [0, '-20%'], - formatter: '{value}', - }, title: { show: true, - offsetCenter: [0, '20%'], + offsetCenter: [0, '80%'], fontSize: 14, color: '#666', }, + detail: { + valueAnimation: true, + fontSize: 32, + fontWeight: 'bold', + color, + offsetCenter: [0, '10%'], + formatter: (val: number) => `${val} 个`, + }, data: [{ value, name: title }], }, ], }; } + +/** + * 设备数量饼图配置 + */ +export function getDeviceCountPieChartOptions( + data: Array<{ name: string; value: number }>, +): any { + return { + tooltip: { + trigger: 'item', + formatter: '{b}: {c} 个 ({d}%)', + }, + legend: { + type: 'scroll', + orient: 'horizontal', + bottom: '10px', + left: 'center', + icon: 'circle', + itemWidth: 10, + itemHeight: 10, + itemGap: 12, + textStyle: { + fontSize: 12, + }, + pageButtonPosition: 'end', + pageIconSize: 12, + pageTextStyle: { + fontSize: 12, + }, + pageFormatter: '{current}/{total}', + }, + series: [ + { + name: '设备数量', + type: 'pie', + radius: ['35%', '55%'], + center: ['50%', '40%'], + avoidLabelOverlap: false, + itemStyle: { + borderRadius: 8, + borderColor: '#fff', + borderWidth: 2, + }, + label: { + show: false, + }, + emphasis: { + label: { + show: true, + fontSize: 16, + fontWeight: 'bold', + }, + itemStyle: { + shadowBlur: 10, + shadowOffsetX: 0, + shadowColor: 'rgba(0, 0, 0, 0.5)', + }, + }, + labelLine: { + show: false, + }, + data, + }, + ], + }; +} diff --git a/apps/web-antd/src/views/iot/home/data.ts b/apps/web-antd/src/views/iot/home/data.ts index 164557968..7b00cb196 100644 --- a/apps/web-antd/src/views/iot/home/data.ts +++ b/apps/web-antd/src/views/iot/home/data.ts @@ -1,18 +1,11 @@ /** * IoT 首页数据配置文件 * - * 该文件封装了 IoT 首页所需的: - * - 统计数据接口定义 - * - 业务逻辑函数 - * - 工具函数 + * 该文件只包含统计数据接口定义 */ import type { IotStatisticsApi } from '#/api/iot/statistics'; -import { onMounted, ref } from 'vue'; - -import { getStatisticsSummary } from '#/api/iot/statistics'; - /** 统计数据接口 - 使用 API 定义的类型 */ export type StatsData = IotStatisticsApi.StatisticsSummary; @@ -31,84 +24,3 @@ export const defaultStatsData: StatsData = { deviceInactiveCount: 0, productCategoryDeviceCounts: {}, }; - -/** - * 加载统计数据 - * @returns Promise - */ -export async function loadStatisticsData(): Promise { - try { - const data = await getStatisticsSummary(); - return data; - } catch (error) { - console.error('获取统计数据出错:', error); - console.warn('使用 Mock 数据,请检查后端接口是否已实现'); - - // 返回 Mock 数据用于开发调试 - return { - productCategoryCount: 12, - productCount: 45, - deviceCount: 328, - deviceMessageCount: 15_678, - productCategoryTodayCount: 2, - productTodayCount: 5, - deviceTodayCount: 23, - deviceMessageTodayCount: 1234, - deviceOnlineCount: 256, - deviceOfflineCount: 48, - deviceInactiveCount: 24, - productCategoryDeviceCounts: { - 智能家居: 120, - 工业设备: 98, - 环境监测: 65, - 智能穿戴: 45, - }, - }; - } -} - -/** - * IoT 首页业务逻辑 Hook - * 封装了首页的所有业务逻辑和状态管理 - */ -export function useIotHome() { - const loading = ref(true); - const statsData = ref(defaultStatsData); - - /** - * 加载数据 - */ - async function loadData() { - loading.value = true; - try { - statsData.value = await loadStatisticsData(); - } catch (error) { - console.error('获取统计数据出错:', error); - } finally { - loading.value = false; - } - } - - // 组件挂载时加载数据 - onMounted(() => { - loadData(); - }); - - return { - loading, - statsData, - loadData, - }; -} - -// TODO @haohao:是不是删除下哈; -/** 格式化数字 - 大数字显示为 K/M */ -export function formatNumber(num: number): string { - if (num >= 1_000_000) { - return `${(num / 1_000_000).toFixed(1)}M`; - } - if (num >= 1000) { - return `${(num / 1000).toFixed(1)}K`; - } - return num.toString(); -} diff --git a/apps/web-antd/src/views/iot/home/index.vue b/apps/web-antd/src/views/iot/home/index.vue index 20bac8fa5..5ceacbde6 100644 --- a/apps/web-antd/src/views/iot/home/index.vue +++ b/apps/web-antd/src/views/iot/home/index.vue @@ -1,18 +1,78 @@