From 8ce0c11e0f82e6833047e302753ea8dc9102157d Mon Sep 17 00:00:00 2001
From: haoliang <821644@qq.com>
Date: Tue, 28 Apr 2026 12:36:56 +0800
Subject: [PATCH] =?UTF-8?q?feat(dashboard):=20=E8=BD=A6=E9=97=B4=E4=BA=A7?=
=?UTF-8?q?=E9=87=8F/=E6=9C=BA=E5=BA=8A=E6=8E=92=E8=A1=8C/=E5=B7=A5?=
=?UTF-8?q?=E4=BA=BA=E6=8E=92=E8=A1=8C=E5=A2=9E=E5=8A=A0=E7=8B=AC=E7=AB=8B?=
=?UTF-8?q?=E6=97=A5=E6=9C=9F=E7=AD=9B=E9=80=89=EF=BC=88=E4=BB=8A=E6=97=A5?=
=?UTF-8?q?/=E6=98=A8=E6=97=A5/=E8=BF=913=E5=A4=A9/=E8=BF=917=E5=A4=A9/?=
=?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
frontend/mock/dashboard.ts | 107 ++++++++----
.../src/views/dashboard/DashboardPage.vue | 164 ++++++++++++++----
2 files changed, 201 insertions(+), 70 deletions(-)
diff --git a/frontend/mock/dashboard.ts b/frontend/mock/dashboard.ts
index 752271e..b0c9532 100644
--- a/frontend/mock/dashboard.ts
+++ b/frontend/mock/dashboard.ts
@@ -1,4 +1,45 @@
-import type { MockMethod } from './types'
+import type { MockMethod, MockRequest } from './types'
+
+// 日期工具
+function getToday(): string { return new Date().toISOString().slice(0, 10) }
+function daysAgo(n: number): string { const d = new Date(); d.setDate(d.getDate() - n); return d.toISOString().slice(0, 10) }
+
+// 不同日期范围的数据倍率(模拟不同日期的数据差异)
+function getMultiplier(startDate: string, endDate: string): number {
+ const today = getToday()
+ if (startDate === today && endDate === today) return 1.0 // 今日
+ if (startDate === daysAgo(1) && endDate === daysAgo(1)) return 0.92 // 昨日
+ if (startDate === daysAgo(2) && endDate === today) return 0.95 // 近3天
+ if (startDate === daysAgo(6) && endDate === today) return 0.93 // 近7天
+ return 0.88 // 自定义
+}
+
+const baseMachineRank = [
+ { rank: 1, machineId: 1, machineName: '西-1.8', program: '1566.NC', quantity: 580, status: 1 },
+ { rank: 2, machineId: 2, machineName: '西-1.10', program: 'O123.NC', quantity: 420, status: 1 },
+ { rank: 3, machineId: 3, machineName: '东-2.0', program: 'A456.NC', quantity: 380, status: 1 },
+ { rank: 4, machineId: 4, machineName: '东-2.5', program: 'B789.NC', quantity: 310, status: 0 },
+ { rank: 5, machineId: 5, machineName: '南-3.1', program: 'C012.NC', quantity: 290, status: 1 },
+ { rank: 6, machineId: 6, machineName: '南-3.2', program: 'D345.NC', quantity: 240, status: 1 },
+ { rank: 7, machineId: 7, machineName: '北-4.0', program: 'E678.NC', quantity: 210, status: 1 },
+ { rank: 8, machineId: 8, machineName: '北-4.1', program: 'F901.NC', quantity: 180, status: 0 },
+ { rank: 9, machineId: 9, machineName: '西-1.5', program: 'G234.NC', quantity: 150, status: 1 },
+ { rank: 10, machineId: 10, machineName: '东-2.8', program: 'H567.NC', quantity: 87, status: 1 },
+]
+
+const baseWorkerRank = [
+ { rank: 1, workerId: 1, workerName: '张三', machineCount: 3, totalQuantity: 1240 },
+ { rank: 2, workerId: 2, workerName: '李四', machineCount: 2, totalQuantity: 980 },
+ { rank: 3, workerId: 3, workerName: '王五', machineCount: 4, totalQuantity: 870 },
+ { rank: 4, workerId: 4, workerName: '赵六', machineCount: 2, totalQuantity: 650 },
+ { rank: 5, workerId: 5, workerName: '孙七', machineCount: 3, totalQuantity: 520 },
+]
+
+const baseWorkshopProduction = [
+ { workshopName: 'A栋', quantity: 1280, machineCount: 80, avgQuantity: 16.0 },
+ { workshopName: 'B栋', quantity: 860, machineCount: 45, avgQuantity: 19.1 },
+ { workshopName: 'C栋', quantity: 707, machineCount: 35, avgQuantity: 20.2 },
+]
const mock: MockMethod[] = [
{
@@ -35,38 +76,27 @@ const mock: MockMethod[] = [
{
url: '/mock-api/admin/dashboard/machine-rank',
method: 'get',
- response: {
- code: 0,
- data: {
- items: [
- { rank: 1, machineId: 1, machineName: '西-1.8', program: '1566.NC', quantity: 580, status: 1 },
- { rank: 2, machineId: 2, machineName: '西-1.10', program: 'O123.NC', quantity: 420, status: 1 },
- { rank: 3, machineId: 3, machineName: '东-2.0', program: 'A456.NC', quantity: 380, status: 1 },
- { rank: 4, machineId: 4, machineName: '东-2.5', program: 'B789.NC', quantity: 310, status: 0 },
- { rank: 5, machineId: 5, machineName: '南-3.1', program: 'C012.NC', quantity: 290, status: 1 },
- { rank: 6, machineId: 6, machineName: '南-3.2', program: 'D345.NC', quantity: 240, status: 1 },
- { rank: 7, machineId: 7, machineName: '北-4.0', program: 'E678.NC', quantity: 210, status: 1 },
- { rank: 8, machineId: 8, machineName: '北-4.1', program: 'F901.NC', quantity: 180, status: 0 },
- { rank: 9, machineId: 9, machineName: '西-1.5', program: 'G234.NC', quantity: 150, status: 1 },
- { rank: 10, machineId: 10, machineName: '东-2.8', program: 'H567.NC', quantity: 87, status: 1 },
- ],
- },
+ response: (req: MockRequest) => {
+ const m = getMultiplier(req.query.startDate, req.query.endDate)
+ return {
+ code: 0,
+ data: {
+ items: baseMachineRank.map(r => ({ ...r, quantity: Math.round(r.quantity * m) })),
+ },
+ }
},
},
{
url: '/mock-api/admin/dashboard/worker-rank',
method: 'get',
- response: {
- code: 0,
- data: {
- items: [
- { rank: 1, workerId: 1, workerName: '张三', machineCount: 3, totalQuantity: 1240 },
- { rank: 2, workerId: 2, workerName: '李四', machineCount: 2, totalQuantity: 980 },
- { rank: 3, workerId: 3, workerName: '王五', machineCount: 4, totalQuantity: 870 },
- { rank: 4, workerId: 4, workerName: '赵六', machineCount: 2, totalQuantity: 650 },
- { rank: 5, workerId: 5, workerName: '孙七', machineCount: 3, totalQuantity: 520 },
- ],
- },
+ response: (req: MockRequest) => {
+ const m = getMultiplier(req.query.startDate, req.query.endDate)
+ return {
+ code: 0,
+ data: {
+ items: baseWorkerRank.map(r => ({ ...r, totalQuantity: Math.round(r.totalQuantity * m) })),
+ },
+ }
},
},
// ===== 新增:产量趋势(近7天) =====
@@ -92,15 +122,18 @@ const mock: MockMethod[] = [
{
url: '/mock-api/admin/dashboard/workshop-production',
method: 'get',
- response: {
- code: 0,
- data: {
- items: [
- { workshopName: 'A栋', quantity: 1280, machineCount: 80, avgQuantity: 16.0 },
- { workshopName: 'B栋', quantity: 860, machineCount: 45, avgQuantity: 19.1 },
- { workshopName: 'C栋', quantity: 707, machineCount: 35, avgQuantity: 20.2 },
- ],
- },
+ response: (req: MockRequest) => {
+ const m = getMultiplier(req.query.startDate, req.query.endDate)
+ return {
+ code: 0,
+ data: {
+ items: baseWorkshopProduction.map(w => ({
+ ...w,
+ quantity: Math.round(w.quantity * m),
+ avgQuantity: Math.round(w.avgQuantity * m * 10) / 10,
+ })),
+ },
+ }
},
},
// ===== 新增:机床状态分布 =====
diff --git a/frontend/src/views/dashboard/DashboardPage.vue b/frontend/src/views/dashboard/DashboardPage.vue
index 17d4ec2..0fea062 100644
--- a/frontend/src/views/dashboard/DashboardPage.vue
+++ b/frontend/src/views/dashboard/DashboardPage.vue
@@ -134,7 +134,21 @@
- 车间平均单机产量(今日)ⓘ
+
+
+
@@ -181,8 +195,17 @@
@@ -206,8 +229,17 @@
@@ -223,7 +255,7 @@