From 8b52b3d872a1ae4ef7108ed036804e9e1f3f1c4e Mon Sep 17 00:00:00 2001 From: haoliang <821644@qq.com> Date: Tue, 28 Apr 2026 11:53:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(dashboard):=20=E4=BB=AA=E8=A1=A8=E7=9B=98?= =?UTF-8?q?=E5=A2=9E=E5=BC=BA=20=E2=80=94=20=E6=96=B0=E5=A2=9E=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=8D=A1=E7=89=87+=E5=9B=BE=E8=A1=A8+=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增: 采集成功率/切削总时/运行机床/数据缺失 统计卡片 新增: 产量趋势折线图(近7天) + 车间产量对比柱状图 + 机床状态分布饼图 新增: 最新告警列表(5条) 新增: 4个Mock API + ECharts PieChart/Legend按需导入 Ultraworked with Sisyphus Co-authored-by: Sisyphus --- frontend/mock/dashboard.ts | 64 ++++ frontend/src/types/index.ts | 37 ++ frontend/src/utils/echarts.ts | 6 +- .../src/views/dashboard/DashboardPage.vue | 360 +++++++++++++----- 4 files changed, 372 insertions(+), 95 deletions(-) diff --git a/frontend/mock/dashboard.ts b/frontend/mock/dashboard.ts index 2bfc4ad..7525cbc 100644 --- a/frontend/mock/dashboard.ts +++ b/frontend/mock/dashboard.ts @@ -11,6 +11,10 @@ const mock: MockMethod[] = [ totalMachines: 160, todayProduction: 2847, activeAlerts: 3, + collectSuccessRate: 99.2, + todayCuttingTime: 580, + runningMachines: 128, + dataMissingMachines: 3, }, }, }, @@ -65,6 +69,66 @@ const mock: MockMethod[] = [ }, }, }, + // ===== 新增:产量趋势(近7天) ===== + { + url: '/mock-api/admin/dashboard/trend', + method: 'get', + response: { + code: 0, + data: { + items: [ + { date: '2026-04-19', quantity: 3120 }, + { date: '2026-04-20', quantity: 2980 }, + { date: '2026-04-21', quantity: 3450 }, + { date: '2026-04-22', quantity: 3310 }, + { date: '2026-04-23', quantity: 3080 }, + { date: '2026-04-24', quantity: 3260 }, + { date: '2026-04-25', quantity: 2847 }, + ], + }, + }, + }, + // ===== 新增:车间产量对比 ===== + { + url: '/mock-api/admin/dashboard/workshop-production', + method: 'get', + response: { + code: 0, + data: { + items: [ + { workshopName: 'A栋', quantity: 1280 }, + { workshopName: 'B栋', quantity: 860 }, + { workshopName: 'C栋', quantity: 707 }, + ], + }, + }, + }, + // ===== 新增:机床状态分布 ===== + { + url: '/mock-api/admin/dashboard/machine-status-distribution', + method: 'get', + response: { + code: 0, + data: { online: 142, offline: 10, disabled: 8 }, + }, + }, + // ===== 新增:最新告警 ===== + { + url: '/mock-api/admin/dashboard/recent-alerts', + method: 'get', + response: { + code: 0, + data: { + items: [ + { id: 101, createdAt: '2026-04-25 17:30:00', alertType: 'collect_fail', machineName: '西-1.8', title: '连续采集失败5次', isResolved: false }, + { id: 100, createdAt: '2026-04-25 17:25:00', alertType: 'data_missing', machineName: '东-2.0', title: '数据缺失', isResolved: false }, + { id: 99, createdAt: '2026-04-25 16:50:00', alertType: 'device_offline', machineName: '北-4.1', title: '设备离线超30分钟', isResolved: false }, + { id: 98, createdAt: '2026-04-25 15:10:00', alertType: 'collect_fail', machineName: '东-2.5', title: '采集超时', isResolved: true }, + { id: 97, createdAt: '2026-04-25 14:30:00', alertType: 'new_device', machineName: '未知设备', title: '发现未注册设备device_99', isResolved: false }, + ], + }, + }, + }, ] export default mock diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index de82d58..de1ef84 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -188,6 +188,43 @@ export interface DashboardSummary { totalMachines: number todayProduction: number activeAlerts: number + /** 今日采集成功率(%) */ + collectSuccessRate: number + /** 今日切削总时(小时) */ + todayCuttingTime: number + /** 运行中机床数(有程序运行) */ + runningMachines: number + /** 数据缺失机床数(在线但采集失败) */ + dataMissingMachines: number +} + +/** 仪表盘产量趋势 */ +export interface DashboardTrendItem { + date: string + quantity: number +} + +/** 车间产量对比 */ +export interface WorkshopProduction { + workshopName: string + quantity: number +} + +/** 机床状态分布 */ +export interface MachineStatusDistribution { + online: number + offline: number + disabled: number +} + +/** 最新告警(仪表盘) */ +export interface RecentAlert { + id: number + createdAt: string + alertType: string + machineName: string + title: string + isResolved: boolean } // 机床产量排行榜行数据 diff --git a/frontend/src/utils/echarts.ts b/frontend/src/utils/echarts.ts index b0646c8..9b0bf29 100644 --- a/frontend/src/utils/echarts.ts +++ b/frontend/src/utils/echarts.ts @@ -1,11 +1,11 @@ // ECharts 按需导入工具,避免打包整个echarts库,提升构建体积 // 只注册需要的组件,确保三个页面的图表渲染正常 import * as echarts from 'echarts/core' -import { BarChart, LineChart } from 'echarts/charts' -import { GridComponent, TooltipComponent, TitleComponent } from 'echarts/components' +import { BarChart, LineChart, PieChart } from 'echarts/charts' +import { GridComponent, TooltipComponent, TitleComponent, LegendComponent } from 'echarts/components' import { CanvasRenderer } from 'echarts/renderers' // 注册所需的图表/组件/渲染器 -echarts.use([BarChart, LineChart, GridComponent, TooltipComponent, TitleComponent, CanvasRenderer]) +echarts.use([BarChart, LineChart, PieChart, GridComponent, TooltipComponent, TitleComponent, LegendComponent, CanvasRenderer]) export default echarts diff --git a/frontend/src/views/dashboard/DashboardPage.vue b/frontend/src/views/dashboard/DashboardPage.vue index b292f66..380db19 100644 --- a/frontend/src/views/dashboard/DashboardPage.vue +++ b/frontend/src/views/dashboard/DashboardPage.vue @@ -1,7 +1,7 @@