feat: 完成产线与仓储系统多模块迭代升级
本次迭代覆盖MES与WMS核心业务: 1. 新增接驳台托盘传感器读取与AGV对接能力 2. 完善工单排产、备料流程与权限体系拆分 3. 优化看板接口与前端路由、样式 4. 新增操作日志、库存盘点与角色保护逻辑 5. 修复代理地址、BOM保存等已知问题
This commit is contained in:
+163
-85
@@ -1,53 +1,167 @@
|
||||
import type { DashboardData, Station, ToolStatus } from './types';
|
||||
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[] {
|
||||
const statusPool: ToolStatus[] = ['online', 'busy', 'busy', 'online', 'alarm', 'busy'];
|
||||
return Array.from({ length: 12 }, (_, i) => {
|
||||
const id = i + 1;
|
||||
const scan = statusPool[id % statusPool.length];
|
||||
const tight: ToolStatus =
|
||||
id % 6 === 0 ? 'offline' : id % 5 === 0 ? 'alarm' : 'busy';
|
||||
const css = scan === 'alarm' || tight === 'alarm' ? 'alarm' : 'running';
|
||||
// 演示态:绝大多数工位在线作业,体现产线满负荷运转
|
||||
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: id % 6 === 0 ? 'offline' : css,
|
||||
scanGun: { status: scan, processedCount: 30 + id * 13 },
|
||||
tighteningGun: {
|
||||
status: tight,
|
||||
currentSn: tight === 'busy' ? `SN-${2500 + id * 7}` : undefined,
|
||||
processedCount: 28 + id * 11,
|
||||
},
|
||||
currentSn: `SN-${2400 + id * 5}`,
|
||||
status: busy ? 'running' : 'idle',
|
||||
scanGun: { status: tool, processedCount: 120 + id * 13 },
|
||||
tighteningGun: { status: tool, currentSn: sn, processedCount: 1080 + id * 96 },
|
||||
currentSn: sn,
|
||||
currentOperator: operator,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** 演示数据(无 MES 时使用,页面不空白) */
|
||||
export function getMockData(): DashboardData {
|
||||
const now = Date.now();
|
||||
const hour = new Date().getHours();
|
||||
const trends = Array.from({ length: 12 }, (_, i) => {
|
||||
const t = new Date(now - (11 - i) * 30 * 60_000);
|
||||
const hh = `${String(t.getHours()).padStart(2, '0')}:${String(
|
||||
t.getMinutes(),
|
||||
).padStart(2, '0')}`;
|
||||
/**
|
||||
* 生成一个工件的完整追溯时间线。
|
||||
* 演示态下全部工序 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 {
|
||||
time: hh,
|
||||
output: 18 + i * 4 + (i % 3),
|
||||
qualifiedRate: 94 + (i % 5),
|
||||
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),
|
||||
];
|
||||
|
||||
return {
|
||||
production: {
|
||||
outputToday: 168 + hour,
|
||||
outputToday: 168,
|
||||
targetToday: 260,
|
||||
qualifiedRate: 96.4,
|
||||
qualityOk: 162,
|
||||
qualityNg: 6,
|
||||
stationSummary: { running: 10, idle: 1, offline: 1, alarm: 1 },
|
||||
passCount: 168,
|
||||
torqueCount: 1284,
|
||||
inLine: 42,
|
||||
deviceOnline: 24,
|
||||
deviceTotal: 24,
|
||||
stationSummary: { running: 10, idle: 2, offline: 0, alarm: 0 },
|
||||
},
|
||||
warehouse: {
|
||||
totalStock: 12860,
|
||||
@@ -65,61 +179,25 @@ export function getMockData(): DashboardData {
|
||||
},
|
||||
equipment: buildStations(),
|
||||
progress: {
|
||||
orderNo: 'WO-20260828-007',
|
||||
orderNo: 'WO-20260825-007',
|
||||
contractNo: 'HT-2026-0825-007',
|
||||
productName: '智能电能表 DDS-02',
|
||||
totalQty: 260,
|
||||
doneQty: 168,
|
||||
completedQty: 162,
|
||||
currentProcess: '工序8 / 12',
|
||||
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,
|
||||
},
|
||||
alarms: [
|
||||
{
|
||||
id: 'a1',
|
||||
level: 'critical',
|
||||
type: 'equipment',
|
||||
target: '工位6 拧紧枪',
|
||||
message: '拧紧扭矩超上限(目标 5.0 N·m,实测 5.6 N·m)',
|
||||
time: '10:52',
|
||||
status: 'active',
|
||||
},
|
||||
{
|
||||
id: 'a2',
|
||||
level: 'warning',
|
||||
type: 'material',
|
||||
target: '工位4',
|
||||
message: '结构件 装配螺丝 M6 余量不足(剩余 12 件)',
|
||||
time: '11:08',
|
||||
status: 'active',
|
||||
},
|
||||
{
|
||||
id: 'a3',
|
||||
level: 'critical',
|
||||
type: 'equipment',
|
||||
target: '工位6 扫码枪',
|
||||
message: '连续 5 次扫码未识别',
|
||||
time: '11:12',
|
||||
status: 'active',
|
||||
},
|
||||
{
|
||||
id: 'a4',
|
||||
level: 'warning',
|
||||
type: 'material',
|
||||
target: '库房',
|
||||
message: '端子排 T-38 库存低于安全库存',
|
||||
time: '11:15',
|
||||
status: 'active',
|
||||
},
|
||||
{
|
||||
id: 'a5',
|
||||
level: 'warning',
|
||||
type: 'equipment',
|
||||
target: '工位3 拧紧枪',
|
||||
message: '角度偏差过大,已复检',
|
||||
time: '09:44',
|
||||
status: 'resolved',
|
||||
},
|
||||
],
|
||||
traces,
|
||||
trends: { production: trends },
|
||||
isDemo: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user