feat: 完成产线与仓储系统多模块迭代升级

本次迭代覆盖MES与WMS核心业务:
1. 新增接驳台托盘传感器读取与AGV对接能力
2. 完善工单排产、备料流程与权限体系拆分
3. 优化看板接口与前端路由、样式
4. 新增操作日志、库存盘点与角色保护逻辑
5. 修复代理地址、BOM保存等已知问题
This commit is contained in:
SunYF
2026-09-04 14:18:53 +08:00
parent c1fc6d32b2
commit b6799c9de4
138 changed files with 20613 additions and 2220 deletions
@@ -1,67 +0,0 @@
import { Card, Table, Tag, Typography } from '@douyinfe/semi-ui';
import type { DashboardData, AlarmItem } from '../types';
const typeLabel: Record<AlarmItem['type'], string> = {
equipment: '设备故障',
material: '物料短缺',
};
export function AlarmBoard({ data }: { data: DashboardData }) {
const rows = data.alarms.map((a) => ({
key: a.id,
level: a.level,
type: a.type,
target: a.target,
message: a.message,
time: a.time,
status: a.status,
}));
const activeCount = data.alarms.filter((a) => a.status === 'active').length;
const columns = [
{
title: '级别',
dataIndex: 'level',
width: 90,
render: (level: AlarmItem['level']) => (
<Tag color={level === 'critical' ? 'red' : 'orange'}>
{level === 'critical' ? '严重' : '警告'}
</Tag>
),
},
{
title: '类型',
dataIndex: 'type',
width: 110,
render: (type: AlarmItem['type']) => typeLabel[type] ?? type,
},
{ title: '对象', dataIndex: 'target', width: 140 },
{ title: '描述', dataIndex: 'message' },
{ title: '时间', dataIndex: 'time', width: 90 },
{
title: '状态',
dataIndex: 'status',
width: 100,
render: (status: AlarmItem['status']) => (
<Tag color={status === 'active' ? 'red' : 'green'}>
{status === 'active' ? '处理中' : '已解决'}
</Tag>
),
},
];
return (
<div>
<Card title={`异常报警(当前告警 ${activeCount} 条)`}>
{rows.length === 0 ? (
<div style={{ textAlign: 'center', padding: '40px 0' }}>
<Typography.Text type="tertiary">当前无异常报警</Typography.Text>
</div>
) : (
<Table columns={columns} dataSource={rows} pagination={false} rowKey="key" />
)}
</Card>
</div>
);
}
+491 -111
View File
@@ -1,128 +1,508 @@
import { Card, Tag, Tooltip } from '@douyinfe/semi-ui';
import type { DashboardData, Station, ToolStatus } from '../types';
const toolColor: Record<ToolStatus, string> = {
online: '#00d68f',
busy: '#36a3f7',
alarm: '#ff5252',
offline: '#8fa3bf',
};
const toolText: Record<ToolStatus, string> = {
online: '在线',
busy: '作业中',
alarm: '报警',
offline: '离线',
};
const stationColor: Record<Station['status'], string> = {
running: '#00d68f',
idle: '#36a3f7',
alarm: '#ff5252',
offline: '#8fa3bf',
};
import { useEffect, useRef } from 'react';
import * as THREE from 'three';
import type { DashboardData, Station } from '../types';
/**
* 平面产线模型:12 个工位,每个工位含「扫码枪 + 拧紧枪」两台设备。
* 本装配线仅这两类设备,无其他设备。
* 产线 3D 数字孪生(程序化生成,零模型依赖)
*
* 布局按真实厂房俯视图(回字环形):
* ┌──────────────────────────────┐
* │ 上方库房(红货架/来料) │
* │ │
* │ ◀── 6 工位 ──▶ │ ← 上边
* │ ▲ ▼ │
* │ │ 左侧 │右侧 │
* │ │ │ │
* │ ◀── 6 工位 ──▶ │ ← 底边
* │ │
* │ 下方库房(黄货架/电池) │
* └──────────────────────────────┘
* 右上 / 右下 = 办公区
* 传送带顺时针循环;物料光点沿环跑;
* 2 台 AGV 分别从上下库房向对应侧工位配送。
*/
export function LineModel({ data }: { data: DashboardData }) {
const stations = data.equipment;
return (
<Card title="产线平面模型(12 工位 · 扫码枪 + 拧紧枪)">
<div
style={{
display: 'flex',
flexWrap: 'wrap',
gap: 14,
justifyContent: stations.length ? 'flex-start' : 'center',
}}
>
{stations.length === 0 && (
<Tag color="grey">暂无工位数据</Tag>
)}
{stations.map((s) => (
<div
key={s.id}
style={{
width: 148,
border: `2px solid ${stationColor[s.status]}`,
borderRadius: 8,
padding: 10,
background: 'rgba(255,255,255,0.03)',
}}
>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 8,
}}
>
<strong>{s.name}</strong>
<Tag color={s.status === 'alarm' ? 'red' : s.status === 'offline' ? 'grey' : 'green'}>
{statusText(s.status)}
</Tag>
</div>
<Tooltip content={`扫码枪 · 累计 ${s.scanGun.processedCount} 件`}>
<DeviceLine label="扫码枪" status={s.scanGun.status} />
</Tooltip>
<Tooltip
content={`拧紧枪 · 累计 ${s.tighteningGun.processedCount} 件${
s.tighteningGun.currentSn ? ` · ${s.tighteningGun.currentSn}` : ''
}`}
>
<DeviceLine label="拧紧枪" status={s.tighteningGun.status} />
</Tooltip>
{s.currentSn && (
<div style={{ marginTop: 8, fontSize: 12, color: '#8fa3bf' }}>
当前工件:{s.currentSn}
</div>
)}
</div>
))}
</div>
const RING_X = 56; // 环半宽(X)
const RING_Z = 36; // 环半深(Z)
<div style={{ marginTop: 20, display: 'flex', gap: 20, flexWrap: 'wrap' }}>
<Legend color="#00d68f" label="在线 / 运行" />
<Legend color="#36a3f7" label="作业中 / 空闲" />
<Legend color="#ff5252" label="报警" />
<Legend color="#8fa3bf" label="离线" />
</div>
</Card>
);
const BELT_W = 3.4; // 传送带宽
const BELT_H = 1.1; // 传送带高
const STATION_OFFSET = 4; // 工位距环外偏移
const STATION_SIZE = [7, 6.4, 7] as const;
// 环形路径总长度
const SEG_LEN_X = RING_X * 2;
const SEG_LEN_Z = RING_Z * 2;
const TOTAL_LEN = 2 * (SEG_LEN_X + SEG_LEN_Z);
// 环形 4 段端点(z 与 y 在 three 中都是水平轴;地面为 XZ,y 是高度)
const P0 = new THREE.Vector3(-RING_X, BELT_H / 2, -RING_Z); // 左下
const P1 = new THREE.Vector3(+RING_X, BELT_H / 2, -RING_Z); // 右下
const P2 = new THREE.Vector3(+RING_X, BELT_H / 2, +RING_Z); // 右上
const P3 = new THREE.Vector3(-RING_X, BELT_H / 2, +RING_Z); // 左上
// 工位总数:底边 6 + 上边 6(顺传送方向)
const BOTTOM_STATIONS = 6;
const TOP_STATIONS = 6;
// 库房区
const DOCK_TOP = new THREE.Vector3(0, 0, +95);
const DOCK_BOTTOM = new THREE.Vector3(0, 0, -95);
const STATUS_COLOR: Record<Station['status'], number> = {
running: 0x00d68f,
idle: 0x36a3f7,
alarm: 0xffd666,
offline: 0x4b5b73,
};
const STATION_NAMES = [
'上料扫码', '外壳组装', '端子排安装', '电路板装配', '线缆连接', '密封圈压装',
'面板固定', '功能初检', '绝缘耐压', '计量校准', '外观终检', '铭牌绑定',
];
interface LiveObj {
topMat: THREE.MeshBasicMaterial;
ringMat: THREE.MeshBasicMaterial;
status: Station['status'];
pulsePhase: number;
}
function DeviceLine({ label, status }: { label: string; status: ToolStatus }) {
interface AgvObj {
mesh: THREE.Mesh;
lamp: THREE.Mesh;
baseZ: number; // 库房 z
stationZ: number; // 工位 z
}
/** 计算 12 工位沿环的位置(底边 6 + 上边 6,顺时针编号) */
function buildStationLayout(): Array<{ pos: THREE.Vector3; name: string }> {
const out: Array<{ pos: THREE.Vector3; name: string }> = [];
// 底边:从左到右(编号 1-6)
for (let i = 0; i < BOTTOM_STATIONS; i++) {
const t = (i + 0.5) / BOTTOM_STATIONS;
out.push({
pos: new THREE.Vector3(
-RING_X + t * SEG_LEN_X,
0,
-RING_Z - STATION_OFFSET,
),
name: STATION_NAMES[i] ?? `工位${i + 1}`,
});
}
// 上边:从右到左(编号 7-12,沿顺时针方向连续)
for (let i = 0; i < TOP_STATIONS; i++) {
const t = (i + 0.5) / TOP_STATIONS;
out.push({
pos: new THREE.Vector3(
+RING_X - t * SEG_LEN_X,
0,
+RING_Z + STATION_OFFSET,
),
name: STATION_NAMES[BOTTOM_STATIONS + i] ?? `工位${BOTTOM_STATIONS + i + 1}`,
});
}
return out;
}
/** 给定总进度 p∈[0,1],返回环形路径上的位置 */
function ringPosition(p: number, y = BELT_H / 2 + 0.6): THREE.Vector3 {
const d = ((p % 1) + 1) % 1 * TOTAL_LEN;
let rest = d;
if (rest < SEG_LEN_X) {
const t = rest / SEG_LEN_X;
return new THREE.Vector3(P0.x + t * (P1.x - P0.x), y, P0.z);
}
rest -= SEG_LEN_X;
if (rest < SEG_LEN_Z) {
const t = rest / SEG_LEN_Z;
return new THREE.Vector3(P1.x, y, P1.z + t * (P2.z - P1.z));
}
rest -= SEG_LEN_Z;
if (rest < SEG_LEN_X) {
const t = rest / SEG_LEN_X;
return new THREE.Vector3(P2.x + t * (P3.x - P2.x), y, P2.z);
}
rest -= SEG_LEN_X;
const t = rest / SEG_LEN_Z;
return new THREE.Vector3(P3.x, y, P3.z + t * (P0.z - P3.z));
}
export function LineModel({ data }: { data: DashboardData }) {
const holderRef = useRef<HTMLDivElement>(null);
const liveRef = useRef<LiveObj[]>([]);
const agvRef = useRef<AgvObj[]>([]);
const statusRef = useRef<Station['status'][]>(
data.equipment.map((e) => e.status),
);
statusRef.current = data.equipment.map((e) => e.status);
useEffect(() => {
const holder = holderRef.current;
if (!holder) return;
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
holder.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x050b18, 220, 520);
const camera = new THREE.PerspectiveCamera(46, 1, 0.1, 1000);
const camClock = new THREE.Clock();
const clock = new THREE.Clock();
// ============ 地面 + 网格 ============
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(420, 320),
new THREE.MeshBasicMaterial({ color: 0x081226, transparent: true, opacity: 0.95 }),
);
floor.rotation.x = -Math.PI / 2;
scene.add(floor);
const grid = new THREE.GridHelper(380, 38, 0x1f3a63, 0x12233d);
(grid.material as THREE.Material).transparent = true;
(grid.material as THREE.Material).opacity = 0.55;
grid.position.y = 0.05;
scene.add(grid);
// ============ 厂房轮廓(线框)============
const shellBox = new THREE.BoxGeometry(280, 50, 240);
const shell = new THREE.LineSegments(
new THREE.EdgesGeometry(shellBox),
new THREE.LineBasicMaterial({ color: 0x2dd4bf, transparent: true, opacity: 0.45 }),
);
shell.position.y = 25;
scene.add(shell);
const roof = new THREE.Mesh(
new THREE.PlaneGeometry(260, 220),
new THREE.MeshBasicMaterial({
color: 0x22d3ee, transparent: true, opacity: 0.04, side: THREE.DoubleSide,
}),
);
roof.rotation.x = -Math.PI / 2;
roof.position.y = 49;
scene.add(roof);
// ============ 库房区(上下两大块 + 右上下办公区)============
const dockMat = new THREE.MeshBasicMaterial({ color: 0x4b1d1d }); // 上方红库房
const dockBottomMat = new THREE.MeshBasicMaterial({ color: 0x3b3a16 }); // 下方黄库房
const dockTop = new THREE.Mesh(new THREE.BoxGeometry(200, 8, 40), dockMat);
dockTop.position.set(0, 4, +95);
scene.add(dockTop);
const dockTopEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(dockTop.geometry),
new THREE.LineBasicMaterial({ color: 0xff7a45, transparent: true, opacity: 0.7 }),
);
dockTop.add(dockTopEdge);
const dockBottom = new THREE.Mesh(new THREE.BoxGeometry(200, 8, 40), dockBottomMat);
dockBottom.position.set(0, 4, -95);
scene.add(dockBottom);
const dockBottomEdge = new THREE.LineSegments(
new THREE.EdgesGeometry(dockBottom.geometry),
new THREE.LineBasicMaterial({ color: 0xfbbf24, transparent: true, opacity: 0.7 }),
);
dockBottom.add(dockBottomEdge);
// 右上下办公区(小盒子代表隔间)
const officeMat = new THREE.MeshBasicMaterial({ color: 0x0e2340 });
[-1, 1].forEach((sgn) => {
for (let k = 0; k < 3; k++) {
const ofc = new THREE.Mesh(new THREE.BoxGeometry(36, 16, 26), officeMat);
ofc.position.set(135, 8, sgn * (32 + k * 6));
scene.add(ofc);
}
});
// ============ 环形传送带(4 段 box)============
const beltMat = new THREE.MeshBasicMaterial({ color: 0x12233d });
const beltEdgeMat = new THREE.LineBasicMaterial({
color: 0x22d3ee, transparent: true, opacity: 0.4,
});
const beltGroup = new THREE.Group();
// 底边 P0→P1
const segBottom = new THREE.Mesh(new THREE.BoxGeometry(SEG_LEN_X, BELT_H, BELT_W), beltMat);
segBottom.position.set(0, BELT_H / 2, -RING_Z);
beltGroup.add(segBottom);
segBottom.add(new THREE.LineSegments(new THREE.EdgesGeometry(segBottom.geometry), beltEdgeMat));
// 顶边 P2→P3
const segTop = new THREE.Mesh(new THREE.BoxGeometry(SEG_LEN_X, BELT_H, BELT_W), beltMat);
segTop.position.set(0, BELT_H / 2, +RING_Z);
beltGroup.add(segTop);
segTop.add(new THREE.LineSegments(new THREE.EdgesGeometry(segTop.geometry), beltEdgeMat));
// 右边 P1→P2
const segRight = new THREE.Mesh(new THREE.BoxGeometry(BELT_W, BELT_H, SEG_LEN_Z), beltMat);
segRight.position.set(+RING_X, BELT_H / 2, 0);
beltGroup.add(segRight);
segRight.add(new THREE.LineSegments(new THREE.EdgesGeometry(segRight.geometry), beltEdgeMat));
// 左边 P3→P0
const segLeft = new THREE.Mesh(new THREE.BoxGeometry(BELT_W, BELT_H, SEG_LEN_Z), beltMat);
segLeft.position.set(-RING_X, BELT_H / 2, 0);
beltGroup.add(segLeft);
segLeft.add(new THREE.LineSegments(new THREE.EdgesGeometry(segLeft.geometry), beltEdgeMat));
scene.add(beltGroup);
// 4 个拐角装饰小灯柱
[P0, P1, P2, P3].forEach((p) => {
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(1.2, 10, 10),
new THREE.MeshBasicMaterial({ color: 0x67e8f9 }),
);
lamp.position.set(p.x, BELT_H + 1.5, p.z);
scene.add(lamp);
});
// ============ 12 工位灯柱 ============
const layout = buildStationLayout();
const live: LiveObj[] = [];
layout.forEach((st, i) => {
const base = new THREE.Mesh(
new THREE.BoxGeometry(...STATION_SIZE),
new THREE.MeshBasicMaterial({ color: 0x1b2b47 }),
);
base.position.set(st.pos.x, STATION_SIZE[1] / 2, st.pos.z);
scene.add(base);
const topMat = new THREE.MeshBasicMaterial({ color: STATUS_COLOR.running });
const top = new THREE.Mesh(
new THREE.BoxGeometry(STATION_SIZE[0] + 0.4, 0.9, STATION_SIZE[2] + 0.4),
topMat,
);
top.position.set(st.pos.x, STATION_SIZE[1] + 0.5, st.pos.z);
scene.add(top);
const ringMat = new THREE.MeshBasicMaterial({
color: STATUS_COLOR.running, transparent: true, opacity: 0.4, side: THREE.DoubleSide,
});
const ring = new THREE.Mesh(new THREE.RingGeometry(4.6, 5.4, 36), ringMat);
ring.rotation.x = -Math.PI / 2;
ring.position.set(st.pos.x, 0.15, st.pos.z);
scene.add(ring);
// 工位名标签(用 sprite canvas)
const labelCanvas = document.createElement('canvas');
labelCanvas.width = 256;
labelCanvas.height = 64;
const ctx = labelCanvas.getContext('2d')!;
ctx.fillStyle = 'rgba(15,26,48,0.85)';
ctx.fillRect(0, 0, 256, 64);
ctx.font = 'bold 32px "PingFang SC", "Microsoft YaHei", sans-serif';
ctx.fillStyle = '#67e8f9';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(st.name, 128, 36);
const tex = new THREE.CanvasTexture(labelCanvas);
tex.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, transparent: true }));
sprite.scale.set(18, 4.5, 1);
sprite.position.set(st.pos.x, STATION_SIZE[1] + 4, st.pos.z);
scene.add(sprite);
live.push({ topMat, ringMat, status: 'idle', pulsePhase: i * 0.4 });
});
liveRef.current = live;
// ============ 物料流光(沿环形路径)============
const DOTS = 26;
const dotGroup = new THREE.Group();
const dotMat = new THREE.MeshBasicMaterial({ color: 0x67e8f9 });
for (let i = 0; i < DOTS; i++) {
const d = new THREE.Mesh(new THREE.SphereGeometry(0.55, 12, 12), dotMat);
d.position.set(0, BELT_H + 1.3, 0);
dotGroup.add(d);
}
scene.add(dotGroup);
// ============ AGV ×2(库房 ↔ 工位)============
const agvConfigs: Array<{ color: number; baseZ: number; stationZ: number; x: number }> = [
{ color: 0xfb923c, baseZ: DOCK_TOP.z, stationZ: +RING_Z + STATION_OFFSET, x: 0 }, // 上库房→上边工位
{ color: 0x60a5fa, baseZ: DOCK_BOTTOM.z, stationZ: -RING_Z - STATION_OFFSET, x: 0 }, // 下库房→下边工位
];
const agvList: AgvObj[] = [];
agvConfigs.forEach((cfg) => {
const body = new THREE.Mesh(
new THREE.BoxGeometry(5.2, 2.6, 3.2),
new THREE.MeshBasicMaterial({ color: cfg.color }),
);
const lamp = new THREE.Mesh(
new THREE.SphereGeometry(0.6, 10, 10),
new THREE.MeshBasicMaterial({ color: 0xffffff }),
);
lamp.position.y = 2;
body.add(lamp);
body.position.set(cfg.x, 1.3, cfg.baseZ);
body.userData = { ...cfg, t: 0, dir: 1 };
scene.add(body);
agvList.push({
mesh: body, lamp, baseZ: cfg.baseZ, stationZ: cfg.stationZ,
});
});
agvRef.current = agvList;
// ============ 灯光 ============
scene.add(new THREE.HemisphereLight(0x9fc8ff, 0x0a1428, 1.05));
const dir = new THREE.DirectionalLight(0xffffff, 1.3);
dir.position.set(80, 160, 60);
scene.add(dir);
// ============ 尺寸自适应 ============
const resize = () => {
const w = holder.clientWidth || 960;
const h = holder.clientHeight || 560;
renderer.setSize(w, h);
camera.aspect = w / h;
camera.updateProjectionMatrix();
};
resize();
window.addEventListener('resize', resize);
// ============ 渲染循环 ============
let raf = 0;
const animate = () => {
raf = requestAnimationFrame(animate);
const t = clock.getElapsedTime();
// 相机环绕(俯视更明显,看清环形)
const theta = t * 0.04;
const r = 230;
camera.position.x = Math.sin(theta) * r;
camera.position.z = Math.cos(theta) * r;
camera.position.y = 145 + Math.sin(t * 0.06) * 8;
camera.lookAt(0, 4, 0);
// 静音未使用变量警告
void camClock;
// 工位状态脉冲
const statuses = statusRef.current;
live.forEach((o, i) => {
const st = statuses[i] ?? 'idle';
if (st !== o.status) {
o.status = st;
const c = STATUS_COLOR[st];
o.topMat.color.setHex(c);
o.ringMat.color.setHex(c);
}
const phase = t * 3 + o.pulsePhase;
const pulse = st === 'running' ? 0.6 + 0.4 * Math.sin(phase) : st === 'offline' ? 0.25 : 0.45;
o.ringMat.opacity = pulse;
o.ringMat.transparent = true;
});
// 物料流光(环形)
const span = TOTAL_LEN - 18;
const speed = 32;
for (let i = 0; i < DOTS; i++) {
const d = dotGroup.children[i] as THREE.Mesh;
const p = ((t * speed) / span + i / DOTS) % 1;
const pos = ringPosition(p);
d.position.set(pos.x, pos.y + Math.sin(t * 5 + i) * 0.3, pos.z);
}
// AGV 库房 ↔ 工位往返(24s 一个来回)
agvList.forEach((agv, i) => {
const ud = agv.mesh.userData as { t: number; dir: number };
const period = 24; // 秒
const phase = (t / period + i * 0.5) % 1;
// 0..0.5 库房→工位,0.5..1 工位→库房
const dir = phase < 0.5 ? 1 : -1;
const tp = dir > 0 ? phase * 2 : (1 - phase) * 2; // 0..1
agv.mesh.position.z = agv.baseZ + (agv.stationZ - agv.baseZ) * tp;
agv.mesh.position.y = 1.3 + Math.sin(t * 4) * 0.2;
(agv.lamp.material as THREE.MeshBasicMaterial).color.setHex(
dir > 0 ? 0xffffff : 0xffaa66,
);
void ud;
});
renderer.render(scene, camera);
};
animate();
return () => {
cancelAnimationFrame(raf);
window.removeEventListener('resize', resize);
scene.traverse((obj) => {
const mesh = obj as THREE.Mesh;
mesh.geometry?.dispose?.();
const m = mesh.material as THREE.Material | THREE.Material[] | undefined;
if (Array.isArray(m)) m.forEach((mm) => mm.dispose());
else m?.dispose();
});
liveRef.current = [];
agvRef.current = [];
renderer.dispose();
if (renderer.domElement.parentElement === holder) {
holder.removeChild(renderer.domElement);
}
};
}, []);
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 4 }}>
<span style={{ display: 'inline-block', width: 10, height: 10, borderRadius: 5, background: toolColor[status] }} />
<span style={{ fontSize: 13 }}>{label}</span>
<span style={{ fontSize: 12, color: '#8fa3bf' }}>{toolText[status]}</span>
<div
style={{
borderRadius: 12,
overflow: 'hidden',
border: '1px solid rgba(34,211,238,0.25)',
background:
'radial-gradient(900px 520px at 50% 0%, #0e1c38 0%, #070e1d 65%)',
position: 'relative',
}}
>
<div
ref={holderRef}
style={{ width: '100%', height: 580, position: 'relative' }}
>
<Legend />
<Footnote />
</div>
</div>
);
}
function statusText(s: Station['status']): string {
switch (s) {
case 'running':
return '运行';
case 'idle':
return '空闲';
case 'alarm':
return '报警';
default:
return '离线';
}
function Legend() {
const items: Array<[string, string]> = [
['#00d68f', '运行中'],
['#36a3f7', '待料'],
['#ffd666', '异常'],
['#4b5b73', '离线'],
['#fb923c', 'AGV 上料'],
['#60a5fa', 'AGV 下料'],
];
return (
<div
style={{
position: 'absolute',
left: 14, top: 12, display: 'flex', gap: 14, fontSize: 12, color: '#9fb4d8',
pointerEvents: 'none', zIndex: 2,
}}
>
{items.map(([color, label]) => (
<span key={label} style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
<span
style={{
width: 9, height: 9, borderRadius: 5, background: color, display: 'inline-block',
}}
/>
{label}
</span>
))}
</div>
);
}
function Legend({ color, label }: { color: string; label: string }) {
function Footnote() {
return (
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 13, color: '#8fa3bf' }}>
<span style={{ display: 'inline-block', width: 10, height: 10, borderRadius: 5, background: color }} />
{label}
</span>
<div
style={{
position: 'absolute', right: 14, bottom: 12, fontSize: 11, color: '#5d7296',
pointerEvents: 'none', zIndex: 2,
}}
>
环形产线自动漫游 · 红=上料库房 / 黄=下料库房 · 右上/右下=办公区
</div>
);
}
+208 -112
View File
@@ -1,157 +1,253 @@
import { Card, Progress, Tag, Typography } from '@douyinfe/semi-ui';
import type { EChartsOption } from 'echarts';
import type { DashboardData } from '../types';
import type { DashboardData, Station } from '../types';
import { EChart } from '../components/EChart';
const gridLabel = {
color: '#8fa3bf',
fontSize: 13,
const C = {
cyan: '#22d3ee',
green: '#34d399',
blue: '#60a5fa',
amber: '#fbbf24',
panel: '#0d1a33',
border: 'rgba(56,189,248,0.22)',
text: '#e2e8f0',
sub: '#94a3b8',
dim: '#64748b',
};
export function ProductionBoard({ data }: { data: DashboardData }) {
const { production, progress, trends } = data;
const st = production.stationSummary;
const prog =
progress.totalQty > 0 ? (progress.completedQty / progress.totalQty) * 100 : 0;
const statusColor: Record<Station['status'], string> = {
running: C.green,
idle: C.blue,
alarm: '#f87171',
offline: '#475569',
};
const ringOption: EChartsOption = {
tooltip: {
formatter: '{b}: {c}({d}%)',
},
series: [
{
type: 'pie',
radius: ['62%', '82%'],
silent: true,
label: { show: true, position: 'center', formatter: '{value}%'.replace('{value}', String(production.qualifiedRate)), fontSize: 30, fontWeight: 'bold', color: '#00d68f' },
data: [
{ value: production.qualityOk, name: '合格', itemStyle: { color: '#00d68f' } },
{ value: production.qualityNg, name: '不合格', itemStyle: { color: '#ff5252' } },
],
},
],
};
const gridLabel = { color: '#8fa3bf', fontSize: 13 };
export function ProductionBoard({ data }: { data: DashboardData }) {
const { production, progress, trends, equipment } = data;
const trendOption: EChartsOption = {
grid: { left: 40, right: 16, top: 28, bottom: 24 },
grid: { left: 48, right: 20, top: 28, bottom: 28 },
tooltip: { trigger: 'axis' },
legend: { textStyle: gridLabel, top: 0, data: ['当日产量', '合格率'] },
xAxis: {
type: 'category',
data: trends.production.map((t) => t.time),
axisLine: { lineStyle: { color: '#335' } },
axisLabel: gridLabel,
},
yAxis: [
{
type: 'value',
name: '产量',
splitLine: { lineStyle: { color: '#1f2a3f' } },
axisLabel: gridLabel,
},
{
type: 'value',
name: '合格率',
min: 80,
max: 100,
splitLine: { show: false },
axisLabel: gridLabel,
},
],
yAxis: {
type: 'value',
name: '产量',
splitLine: { lineStyle: { color: '#1f2a3f' } },
axisLabel: gridLabel,
},
series: [
{
name: '当日产量',
name: '日产量',
type: 'line',
smooth: true,
data: trends.production.map((t) => t.output),
itemStyle: { color: '#36a3f7' },
areaStyle: { color: 'rgba(54,163,247,0.2)' },
},
{
name: '合格率',
type: 'line',
yAxisIndex: 1,
smooth: true,
data: trends.production.map((t) => t.qualifiedRate),
itemStyle: { color: '#00d68f' },
itemStyle: { color: C.cyan },
areaStyle: { color: 'rgba(34,211,238,0.18)' },
},
],
};
return (
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16 }}>
<Card title="产线运行状态" style={{ gridColumn: 'span 2' }}>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14 }}>
<Kpi value={production.outputToday} label="今日产量" sub={`目标 ${production.targetToday}`} color={C.cyan} />
<Kpi value={production.passCount} label="一次通过" sub="件 · 全工序合格" color={C.green} />
<Kpi value={production.inLine} label="在制工件" sub="产线流转中" color={C.blue} />
<Kpi
value={production.deviceOnline}
label="设备在线"
sub={`共 ${production.deviceTotal} 台 · 全部在线`}
color={C.green}
/>
<Panel title="近 7 日产量趋势" style={{ gridColumn: 'span 2' }}>
<EChart option={trendOption} height={230} />
</Panel>
<Panel title="当前订单" style={{ gridColumn: 'span 2' }} accent>
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(4, 1fr)',
gap: 12,
textAlign: 'center',
gridTemplateColumns: 'auto 1fr',
rowGap: 10,
columnGap: 14,
alignItems: 'center',
}}
>
<Cell value={st.running} label="运行中" color="#00d68f" />
<Cell value={st.idle} label="空闲" color="#36a3f7" />
<Cell value={st.alarm} label="报警" color="#ff5252" />
<Cell value={st.offline} label="离线" color="#8fa3bf" />
</div>
</Card>
<Field label="合同号" />
<span style={{ fontSize: 15, fontWeight: 500 }}>{progress.contractNo || progress.orderNo}</span>
<Card title="当日产量">
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
<span style={{ fontSize: 36, fontWeight: 700, color: '#36a3f7' }}>
{production.outputToday}
<Field label="产品" />
<span style={{ fontSize: 14 }}>{progress.productName}</span>
<Field label="负责人" />
<span style={{ fontSize: 14, color: C.cyan }}>{progress.owner || '—'}</span>
<Field label="工期" />
<span style={{ fontSize: 14 }}>
{progress.planStart} ~ {progress.planEnd}
<span style={{ marginLeft: 10, color: progress.remainDays >= 0 ? C.green : C.amber }}>
剩余 {Math.max(progress.remainDays, 0)} 天
</span>
</span>
<span style={{ color: '#8fa3bf' }}>/ {production.targetToday}</span>
</div>
<div style={{ marginTop: 8 }}>
<Typography.Text type="tertiary">日计划达成率</Typography.Text>
<Progress
percent={
production.targetToday
? Math.round((production.outputToday / production.targetToday) * 100)
: 0
}
showInfo
style={{ marginTop: 8 }}
<div style={{ marginTop: 16 }}>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'baseline',
marginBottom: 8,
}}
>
<span style={{ fontSize: 13, color: C.sub }}>完成度</span>
<span style={{ fontSize: 13, color: C.sub }}>
<span style={{ fontSize: 20, fontWeight: 500, color: C.cyan }}>{progress.doneQty}</span>
{' / '}
{progress.totalQty} 台
</span>
</div>
<Bar percent={progress.progress} />
</div>
<div style={{ display: 'flex', gap: 10, marginTop: 16 }}>
<Chip label="工序进度" value={`${progress.processDone} / ${progress.processTotal} 序`} color={C.cyan} />
<Chip label="当前工序" value={progress.currentProcess || '—'} color={C.blue} />
<Chip
label="责任追溯"
value={progress.traceable ? `${progress.traceStepCount} 条 · 全程可追溯` : '待采集'}
color={progress.traceable ? C.green : C.dim}
/>
</div>
</Card>
</Panel>
<Card title="合格率">
<EChart option={ringOption} height={170} />
</Card>
<Card title="工单进度">
<div style={{ marginBottom: 8 }}>
<Typography.Text strong>{progress.orderNo}</Typography.Text>
<Tag size="small" style={{ marginLeft: 8 }} color="green">
{progress.status}
</Tag>
<Panel title="工位状态(12 工位 · 扫码枪 + 拧紧枪)" style={{ gridColumn: 'span 4' }}>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(6, 1fr)', gap: 10 }}>
{equipment.map((s) => (
<div
key={s.id}
style={{
border: `1px solid ${statusColor[s.status]}55`,
borderLeft: `3px solid ${statusColor[s.status]}`,
borderRadius: 6,
padding: '8px 10px',
background: 'rgba(255,255,255,0.02)',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<span style={{ fontSize: 13, fontWeight: 500 }}>{s.name}</span>
<span style={{ fontSize: 11, color: statusColor[s.status] }}>
{s.status === 'running'
? '作业中'
: s.status === 'idle'
? '待料'
: s.status === 'alarm'
? '异常'
: '离线'}
</span>
</div>
<div style={{ fontSize: 11, color: C.dim, marginTop: 4 }}>
{s.currentOperator || '—'}
</div>
{s.currentSn && <div style={{ fontSize: 11, color: C.sub, marginTop: 2 }}>{s.currentSn}</div>}
</div>
))}
</div>
<Typography.Text type="tertiary">{progress.productName}</Typography.Text>
<div style={{ margin: '10px 0' }}>
<Typography.Text>
完成 {progress.completedQty} / {progress.totalQty}
</Typography.Text>
<div style={{ marginTop: 12, fontSize: 12, color: C.dim }}>
运行中 {production.stationSummary.running} · 待料 {production.stationSummary.idle} · 离线{' '}
{production.stationSummary.offline}
</div>
<Progress percent={Math.round(prog)} showInfo stroke="#5cabff" />
<div style={{ marginTop: 12 }}>
<Typography.Text type="secondary">当前工序:{progress.currentProcess}</Typography.Text>
</div>
</Card>
<Card title="产量与合格率趋势" style={{ gridColumn: 'span 4' }}>
<EChart option={trendOption} height={280} />
</Card>
</Panel>
</div>
);
}
function Cell({ value, label, color }: { value: number; label: string; color: string }) {
function Field({ label }: { label: string }) {
return <span style={{ fontSize: 12, color: C.dim }}>{label}</span>;
}
function Kpi({ value, label, sub, color }: { value: number; label: string; sub: string; color: string }) {
return (
<div>
<div style={{ fontSize: 32, fontWeight: 600, color }}>{value}</div>
<div style={{ color: '#8fa3bf', fontSize: 13 }}>{label}</div>
<div
style={{
background: C.panel,
border: `1px solid ${C.border}`,
borderRadius: 8,
padding: '16px 18px',
}}
>
<div style={{ fontSize: 12, color: C.sub }}>{label}</div>
<div style={{ fontSize: 32, fontWeight: 500, color, lineHeight: 1.3 }}>{value}</div>
<div style={{ fontSize: 11, color: C.dim }}>{sub}</div>
</div>
);
}
}
function Panel({
title,
children,
style,
accent,
}: {
title: string;
children: React.ReactNode;
style?: React.CSSProperties;
accent?: boolean;
}) {
return (
<div
style={{
background: C.panel,
border: `1px solid ${accent ? 'rgba(34,211,238,0.42)' : C.border}`,
borderRadius: 8,
padding: '14px 16px',
...style,
}}
>
<div
style={{
fontSize: 13,
fontWeight: 500,
color: accent ? C.cyan : C.text,
marginBottom: 12,
letterSpacing: 0.5,
}}
>
{title}
</div>
{children}
</div>
);
}
function Bar({ percent }: { percent: number }) {
const p = Math.max(0, Math.min(100, percent));
return (
<div style={{ height: 8, background: '#1e293b', borderRadius: 4, overflow: 'hidden' }}>
<div style={{ width: `${p}%`, height: '100%', background: C.cyan, transition: 'width 0.6s ease' }} />
</div>
);
}
function Chip({ label, value, color }: { label: string; value: string; color: string }) {
return (
<div
style={{
flex: 1,
border: `1px solid ${color}44`,
borderRadius: 6,
padding: '8px 10px',
background: 'rgba(255,255,255,0.02)',
}}
>
<div style={{ fontSize: 11, color: C.dim }}>{label}</div>
<div style={{ fontSize: 13, color, marginTop: 3 }}>{value}</div>
</div>
);
}