1. 新增SSE看板广播机制,业务操作后主动推送刷新事件 2. 新增产线工序横道图与工位状态展示面板 3. 移除dashboard无用的three.js依赖 4. 重构WMS客户端布局与WMS前端资源哈希 5. 新增工位终端时钟图标与大屏自适应布局 6. 新增系统截图脚本与说明书生成工具 7. 修复多处代码细节与空值处理逻辑
227 lines
7.2 KiB
TypeScript
227 lines
7.2 KiB
TypeScript
import type {
|
|
DashboardData,
|
|
Station,
|
|
ToolStatus,
|
|
TraceItem,
|
|
TraceStep,
|
|
} from './types';
|
|
|
|
/** 工序名(12 序装配线) */
|
|
const PROCESS_NAMES = [
|
|
'上料扫码',
|
|
'外壳组装',
|
|
'端子排安装',
|
|
'电路板装配',
|
|
'线缆连接',
|
|
'密封圈压装',
|
|
'面板固定',
|
|
'功能初检',
|
|
'绝缘耐压测试',
|
|
'计量精度校准',
|
|
'外观终检',
|
|
'铭牌绑定',
|
|
];
|
|
|
|
/** 作业人员(责任到人展示用) */
|
|
const OPERATORS = ['张伟', '李强', '王芳', '赵敏', '刘洋', '陈静'];
|
|
|
|
/** 单工件拧紧颗数 */
|
|
const SCREWS_PER_STEP = 10;
|
|
|
|
function pad2(n: number): string {
|
|
return n < 10 ? '0' + n : String(n);
|
|
}
|
|
|
|
function fmtDate(d: Date): string {
|
|
return `${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
|
|
}
|
|
|
|
function fmtTime(d: Date): string {
|
|
return `${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
|
}
|
|
|
|
function fmtHm(d: Date): string {
|
|
return `${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
|
|
}
|
|
|
|
/** 距今天的天数差(用于工期剩余天数) */
|
|
function daysFromToday(target: Date): number {
|
|
const today = new Date();
|
|
const a = Date.UTC(today.getFullYear(), today.getMonth(), today.getDate());
|
|
const b = Date.UTC(target.getFullYear(), target.getMonth(), target.getDate());
|
|
return Math.round((b - a) / 86_400_000);
|
|
}
|
|
|
|
function addDays(base: Date, n: number): Date {
|
|
const d = new Date(base);
|
|
d.setDate(d.getDate() + n);
|
|
return d;
|
|
}
|
|
|
|
/** 生成 12 个工位(含扫码枪 + 拧紧枪,责任到人) */
|
|
function buildStations(): Station[] {
|
|
return Array.from({ length: 12 }, (_, i) => {
|
|
const id = i + 1;
|
|
// 演示态:绝大多数工位在线作业,体现产线满负荷运转
|
|
const busy = id <= 10;
|
|
const tool: ToolStatus = busy ? 'busy' : 'online';
|
|
const operator = OPERATORS[i % OPERATORS.length];
|
|
const sn = busy ? `SN26-${String(2400 + id * 7)}` : undefined;
|
|
return {
|
|
id,
|
|
name: `工位${id}`,
|
|
status: busy ? 'running' : 'idle',
|
|
scanGun: { status: tool, processedCount: 120 + id * 13 },
|
|
tighteningGun: { status: tool, currentSn: sn, processedCount: 1080 + id * 96 },
|
|
currentSn: sn,
|
|
currentOperator: operator,
|
|
};
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 生成一个工件的完整追溯时间线。
|
|
* 演示态下全部工序 OK,用于体现「每一件产品、每一道工序、每一个人都有据可查」。
|
|
*/
|
|
function buildTraceItem(index: number, doneMinutesAgo: number): TraceItem {
|
|
const now = new Date();
|
|
const onlineAt = new Date(now.getTime() - (3 + index) * 3_600_000 - 12 * 60_000);
|
|
const doneAt = new Date(now.getTime() - doneMinutesAgo * 60_000);
|
|
|
|
const steps: TraceStep[] = PROCESS_NAMES.map((name, i) => {
|
|
const startedAt = new Date(onlineAt.getTime() + i * 9 * 60_000);
|
|
const endedAt = new Date(startedAt.getTime() + 7 * 60_000);
|
|
return {
|
|
processCode: i + 1,
|
|
processName: name,
|
|
stationNo: i + 1,
|
|
operator: OPERATORS[(i + index) % OPERATORS.length],
|
|
result: 'OK',
|
|
startedAt: fmtTime(startedAt),
|
|
endedAt: fmtTime(endedAt),
|
|
torqueCount: SCREWS_PER_STEP,
|
|
torqueNg: 0,
|
|
avgStrain: 4.95 + ((i * 7 + index * 3) % 10) / 100,
|
|
};
|
|
});
|
|
|
|
return {
|
|
sn: `SN26-${2600 - index * 3}`,
|
|
orderNo: 'WO-20260825-007',
|
|
productName: '智能电能表 DDS-02',
|
|
status: 'DONE',
|
|
onlineAt: fmtTime(onlineAt),
|
|
doneAt: fmtHm(doneAt),
|
|
durationMin: Math.round((doneAt.getTime() - onlineAt.getTime()) / 60_000),
|
|
stepCount: steps.length,
|
|
okCount: steps.length,
|
|
ngCount: 0,
|
|
steps,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 演示数据。
|
|
*
|
|
* 仅在 MES 真实业务数据为空时启用(看板为纯展示系统,大屏出现 0 或空白比演示数据更糟)。
|
|
* 演示数据只存在于前端,不回写任何业务库;真实数据到位后自动切换。
|
|
*/
|
|
export function getDemoData(): DashboardData {
|
|
const now = new Date();
|
|
|
|
// 当前订单:工期 26 天,今天处于中段,剩余天数按真实日期动态计算
|
|
const planStart = addDays(now, -10);
|
|
const planEnd = addDays(now, 16);
|
|
const totalQty = 260;
|
|
const doneQty = 168;
|
|
|
|
// 近 7 日产量趋势:整体平稳上行,体现产能爬坡
|
|
const trends = Array.from({ length: 7 }, (_, i) => {
|
|
const d = addDays(now, i - 6);
|
|
return {
|
|
time: `${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`,
|
|
output: 132 + i * 9 + (i % 3),
|
|
qualifiedRate: 100,
|
|
};
|
|
});
|
|
|
|
const traces = [
|
|
buildTraceItem(0, 6),
|
|
buildTraceItem(1, 21),
|
|
buildTraceItem(2, 38),
|
|
buildTraceItem(3, 55),
|
|
];
|
|
|
|
// 当前订单 12 道工序横道图:工期 -10 ~ +16 天,每序约 2.17 天
|
|
const stepDurationHours = ((planEnd.getTime() - planStart.getTime()) / 12) / 36e5;
|
|
const progressSteps: DashboardData['progress']['steps'] = PROCESS_NAMES.map((name, i) => {
|
|
const seqStart = new Date(planStart.getTime() + i * stepDurationHours * 36e5);
|
|
const seqEnd = new Date(seqStart.getTime() + stepDurationHours * 36e5);
|
|
const done = i < 6;
|
|
const running = i === 6;
|
|
const actualStart = done || running ? seqStart.toISOString() : undefined;
|
|
const actualEnd = done ? seqEnd.toISOString() : running ? now.toISOString() : undefined;
|
|
return {
|
|
code: i + 1,
|
|
name,
|
|
planStart: seqStart.toISOString(),
|
|
planEnd: seqEnd.toISOString(),
|
|
actualStart,
|
|
actualEnd,
|
|
progress: done ? 100 : running ? 65 : 0,
|
|
owner: OPERATORS[i % OPERATORS.length],
|
|
status: done ? 'done' : running ? 'running' : ('pending' as const),
|
|
};
|
|
});
|
|
|
|
return {
|
|
production: {
|
|
outputToday: 168,
|
|
targetToday: 260,
|
|
passCount: 168,
|
|
torqueCount: 1284,
|
|
inLine: 42,
|
|
deviceOnline: 24,
|
|
deviceTotal: 24,
|
|
stationSummary: { running: 10, idle: 2, offline: 0, alarm: 0 },
|
|
},
|
|
warehouse: {
|
|
totalStock: 12860,
|
|
materialTypes: 46,
|
|
inboundToday: 1320,
|
|
outboundToday: 890,
|
|
movements: [
|
|
{ id: 'm1', time: '09:12', type: 'in', material: '电路板 PCBA-01', qty: 200, operator: '李工' },
|
|
{ id: 'm2', time: '09:28', type: 'out', material: '装配螺丝 M6', qty: 500, operator: '王工' },
|
|
{ id: 'm3', time: '10:05', type: 'in', material: '外壳上盖-铝合金', qty: 120, operator: '李工' },
|
|
{ id: 'm4', time: '10:41', type: 'out', material: '密封圈 硅胶', qty: 300, operator: '赵工' },
|
|
{ id: 'm5', time: '11:03', type: 'in', material: '端子排 T-38', qty: 80, operator: '李工' },
|
|
{ id: 'm6', time: '11:20', type: 'out', material: '装配螺栓 M8', qty: 460, operator: '王工' },
|
|
],
|
|
},
|
|
equipment: buildStations(),
|
|
progress: {
|
|
orderNo: 'WO-20260825-007',
|
|
contractNo: 'HT-2026-0825-007',
|
|
productName: '智能电能表 DDS-02',
|
|
owner: '张伟',
|
|
planStart: fmtDate(planStart),
|
|
planEnd: fmtDate(planEnd),
|
|
remainDays: daysFromToday(planEnd),
|
|
totalQty,
|
|
doneQty,
|
|
progress: Math.round((doneQty / totalQty) * 100),
|
|
processDone: 7,
|
|
processTotal: 12,
|
|
currentProcess: '工序 8 · 面板固定',
|
|
status: '生产中',
|
|
traceStepCount: 2016,
|
|
traceable: true,
|
|
steps: progressSteps,
|
|
},
|
|
traces,
|
|
trends: { production: trends },
|
|
isDemo: true,
|
|
};
|
|
}
|