diff --git a/frontend/mock/dashboard.ts b/frontend/mock/dashboard.ts index b0c9532..3fec756 100644 --- a/frontend/mock/dashboard.ts +++ b/frontend/mock/dashboard.ts @@ -4,6 +4,11 @@ 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 getDays(startDate: string, endDate: string): number { + return Math.max(1, Math.round((new Date(endDate).getTime() - new Date(startDate).getTime()) / 86400000) + 1) +} + // 不同日期范围的数据倍率(模拟不同日期的数据差异) function getMultiplier(startDate: string, endDate: string): number { const today = getToday() @@ -78,10 +83,11 @@ const mock: MockMethod[] = [ method: 'get', response: (req: MockRequest) => { const m = getMultiplier(req.query.startDate, req.query.endDate) + const days = getDays(req.query.startDate, req.query.endDate) return { code: 0, data: { - items: baseMachineRank.map(r => ({ ...r, quantity: Math.round(r.quantity * m) })), + items: baseMachineRank.map(r => ({ ...r, quantity: Math.round(r.quantity * m * days) })), }, } }, @@ -91,10 +97,11 @@ const mock: MockMethod[] = [ method: 'get', response: (req: MockRequest) => { const m = getMultiplier(req.query.startDate, req.query.endDate) + const days = getDays(req.query.startDate, req.query.endDate) return { code: 0, data: { - items: baseWorkerRank.map(r => ({ ...r, totalQuantity: Math.round(r.totalQuantity * m) })), + items: baseWorkerRank.map(r => ({ ...r, totalQuantity: Math.round(r.totalQuantity * m * days) })), }, } }, @@ -124,14 +131,15 @@ const mock: MockMethod[] = [ method: 'get', response: (req: MockRequest) => { const m = getMultiplier(req.query.startDate, req.query.endDate) + const days = getDays(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, - })), + items: baseWorkshopProduction.map(w => { + const totalQty = Math.round(w.quantity * m * days) // 多天总量 = 单天 × 天数 + const avgQty = Math.round(totalQty / days / w.machineCount * 10) / 10 // 日均单机产量 + return { ...w, quantity: totalQty, avgQuantity: avgQty } + }), }, } }, diff --git a/frontend/src/views/dashboard/DashboardPage.vue b/frontend/src/views/dashboard/DashboardPage.vue index 0fea062..6d14633 100644 --- a/frontend/src/views/dashboard/DashboardPage.vue +++ b/frontend/src/views/dashboard/DashboardPage.vue @@ -136,7 +136,16 @@