feat: 新增收集式校验错误弹窗及工位报警语音播报
新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import { useState } from 'react';
|
||||
import { Layout, Tag, Spin } from '@douyinfe/semi-ui';
|
||||
import { useDashboardData } from './hooks/useDashboardData';
|
||||
import { useSpeechAlarm } from './hooks/useSpeechAlarm';
|
||||
import { ProductionBoard } from './pages/ProductionBoard';
|
||||
import { WarehouseBoard } from './pages/WarehouseBoard';
|
||||
import { LineModel } from './pages/LineModel';
|
||||
import { ErrorRetry } from './components/ErrorRetry';
|
||||
import { MaterialQuery } from './components/MaterialQuery';
|
||||
|
||||
export function App() {
|
||||
const { data: dashboard, mode, error, retry } = useDashboardData();
|
||||
const loading = !dashboard && !error;
|
||||
const [now, setNow] = useState(() => new Date());
|
||||
|
||||
// D2 语音播报:监听报警事件(无播音设备静默降级)
|
||||
useSpeechAlarm(dashboard?.alarms ?? []);
|
||||
|
||||
// 时钟
|
||||
setTimeout(() => setNow(new Date()), 1000);
|
||||
|
||||
@@ -22,6 +27,7 @@ export function App() {
|
||||
{mode === 'polling' && <Tag color="blue">轮询刷新</Tag>}
|
||||
{mode === 'demo' && <Tag color="amber">演示数据</Tag>}
|
||||
{mode === 'init' && <Tag color="grey">连接中</Tag>}
|
||||
<MaterialQuery />
|
||||
<span className="clock">{now.toLocaleTimeString('zh-CN')}</span>
|
||||
<span className="date">{now.toLocaleDateString('zh-CN', { weekday: 'long' })}</span>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
import { useState } from 'react';
|
||||
import { Button, Modal, Input, Table, Tag, Typography, Space } from '@douyinfe/semi-ui';
|
||||
import { config } from '../config';
|
||||
|
||||
interface MaterialInfo {
|
||||
code: string;
|
||||
name: string;
|
||||
spec: string;
|
||||
type: string;
|
||||
unit: string;
|
||||
manageMode: number;
|
||||
snMode: number;
|
||||
}
|
||||
|
||||
interface InvRow {
|
||||
zone: string;
|
||||
shelf: string;
|
||||
layer: string;
|
||||
position: string;
|
||||
quality: string;
|
||||
qty: number;
|
||||
batch: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* C7 物料追溯查询入口:复用 WMS 物料档案 + 库存查询接口(经 MES 代理 /api/internal/dashboard/material-query)。
|
||||
* 大屏以展示为主,此入口作为「查询」悬浮窗(不污染主展示区)。
|
||||
*/
|
||||
export function MaterialQuery() {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [code, setCode] = useState('');
|
||||
const [batch, setBatch] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [found, setFound] = useState<boolean | null>(null);
|
||||
const [material, setMaterial] = useState<MaterialInfo | null>(null);
|
||||
const [inventory, setInventory] = useState<InvRow[]>([]);
|
||||
|
||||
async function doQuery() {
|
||||
const c = code.trim();
|
||||
if (!c) {
|
||||
setError('请输入物料编码');
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
setError('');
|
||||
setFound(null);
|
||||
setMaterial(null);
|
||||
setInventory([]);
|
||||
try {
|
||||
const base = config.mesBaseUrl || '';
|
||||
const url =
|
||||
`${base}/api/internal/dashboard/material-query?code=${encodeURIComponent(c)}` +
|
||||
(batch.trim() ? `&batch=${encodeURIComponent(batch.trim())}` : '');
|
||||
const res = await fetch(url, { headers: { 'X-API-TOKEN': config.internalToken } });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const j = (await res.json()) as { data?: { available?: boolean; found?: boolean; material?: MaterialInfo; inventory?: InvRow[] } };
|
||||
const d = j.data;
|
||||
if (!d || d.available === false) {
|
||||
setError('MES/WMS 服务不可用,暂无法查询');
|
||||
setFound(false);
|
||||
return;
|
||||
}
|
||||
setFound(!!d.found);
|
||||
setMaterial(d.material || null);
|
||||
setInventory(d.inventory || []);
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : '查询失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
const invColumns = [
|
||||
{ title: '库位', dataIndex: 'zone', render: (v: string, r: InvRow) => `${v || '-'} / ${r.shelf || ''} / ${r.layer || ''} / ${r.position || ''}` },
|
||||
{ title: '批次', dataIndex: 'batch' },
|
||||
{
|
||||
title: '质量状态',
|
||||
dataIndex: 'quality',
|
||||
render: (q: string) => {
|
||||
const color = q === '合格' ? 'green' : q === '不合格' ? 'red' : 'grey';
|
||||
return <Tag color={color}>{q || '未检'}</Tag>;
|
||||
},
|
||||
},
|
||||
{ title: '数量', dataIndex: 'qty' },
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button theme="borderless" onClick={() => setVisible(true)}>
|
||||
物料追溯查询
|
||||
</Button>
|
||||
<Modal
|
||||
title="物料追溯查询"
|
||||
visible={visible}
|
||||
onCancel={() => setVisible(false)}
|
||||
footer={
|
||||
<Button type="primary" onClick={doQuery} loading={loading}>
|
||||
查询
|
||||
</Button>
|
||||
}
|
||||
width={640}
|
||||
>
|
||||
<Space style={{ marginBottom: 12 }}>
|
||||
<Input
|
||||
placeholder="物料编码(必填)"
|
||||
value={code}
|
||||
onChange={(v) => setCode(v)}
|
||||
onEnterPress={doQuery}
|
||||
style={{ width: 260 }}
|
||||
/>
|
||||
<Input
|
||||
placeholder="批次号(可选)"
|
||||
value={batch}
|
||||
onChange={(v) => setBatch(v)}
|
||||
onEnterPress={doQuery}
|
||||
style={{ width: 200 }}
|
||||
/>
|
||||
</Space>
|
||||
|
||||
{error && (
|
||||
<Typography.Text type="danger" style={{ display: 'block', marginBottom: 8 }}>
|
||||
{error}
|
||||
</Typography.Text>
|
||||
)}
|
||||
|
||||
{found === false && (
|
||||
<Typography.Text type="tertiary">未查询到该物料档案。</Typography.Text>
|
||||
)}
|
||||
|
||||
{material && (
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Typography.Title heading={6}>物料档案</Typography.Title>
|
||||
<Typography.Text>
|
||||
{material.name || material.code}({material.code}) · 规格 {material.spec || '-'} · 单位{' '}
|
||||
{material.unit || '-'}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{inventory.length > 0 && (
|
||||
<div>
|
||||
<Typography.Title heading={6}>在库库存</Typography.Title>
|
||||
<Table
|
||||
columns={invColumns}
|
||||
dataSource={inventory}
|
||||
pagination={false}
|
||||
size="small"
|
||||
rowKey={(r) => (r ? `${r.zone}-${r.shelf}-${r.layer}-${r.position}-${r.batch}` : '')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -15,8 +15,11 @@ export const config = {
|
||||
mesBaseUrl: import.meta.env.VITE_MES_BASE_URL || DEFAULT_MES_BASE_URL,
|
||||
/** 内部服务间鉴权 Token(请求头 X-API-TOKEN) */
|
||||
internalToken: 'Hardman_2026',
|
||||
/** SSE 失效时降级为 HTTP 轮询的间隔(毫秒) */
|
||||
pollIntervalMs: 10_000,
|
||||
/**
|
||||
* SSE 失效时降级为 HTTP 轮询的间隔(毫秒)。
|
||||
* 纯轮询 5s 是兜底上限;SSE 实时通道可用时由事件驱动刷新(收到 dashboard.updated 即拉快照),不依赖轮询周期。
|
||||
*/
|
||||
pollIntervalMs: 5_000,
|
||||
/**
|
||||
* 强制演示模式:为 true 时完全不连 MES,直接用演示数据。
|
||||
* 用于离线开发 / 现场无 MES 的场景。
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import type { AlarmItem } from '../types';
|
||||
|
||||
/**
|
||||
* D2 语音播报:监听报警项,新出现的报警用浏览器 SpeechSynthesis 播报(中文)。
|
||||
* 无播音设备 / 浏览器不支持 speechSynthesis:静默降级(不报错、不影响展示)。
|
||||
* 与「报喜不报忧」一致:报警只语音、不渲染到屏幕。
|
||||
*/
|
||||
export function useSpeechAlarm(alarms: AlarmItem[]) {
|
||||
const prevIds = useRef<Set<string>>(new Set());
|
||||
const supported =
|
||||
typeof window !== 'undefined' && typeof window.speechSynthesis !== 'undefined';
|
||||
|
||||
useEffect(() => {
|
||||
if (!supported) return; // 静默降级
|
||||
const current = new Set(alarms.map((a) => a.id));
|
||||
for (const a of alarms) {
|
||||
if (prevIds.current.has(a.id)) continue; // 仅播报新出现的报警
|
||||
try {
|
||||
const utter = new SpeechSynthesisUtterance(`报警提示:${a.target},${a.message}`);
|
||||
utter.lang = 'zh-CN';
|
||||
utter.rate = 1;
|
||||
utter.volume = 1;
|
||||
window.speechSynthesis.speak(utter);
|
||||
} catch {
|
||||
// 静默降级:无播音设备 / 权限被拒
|
||||
}
|
||||
}
|
||||
prevIds.current = current;
|
||||
}, [alarms, supported]);
|
||||
}
|
||||
@@ -183,6 +183,7 @@ export function getDemoData(): DashboardData {
|
||||
inLine: 42,
|
||||
deviceOnline: 24,
|
||||
deviceTotal: 24,
|
||||
cycleTime: 4.5,
|
||||
stationSummary: { running: 10, idle: 2, offline: 0, alarm: 0 },
|
||||
},
|
||||
warehouse: {
|
||||
@@ -190,13 +191,17 @@ export function getDemoData(): DashboardData {
|
||||
materialTypes: 46,
|
||||
inboundToday: 1320,
|
||||
outboundToday: 890,
|
||||
locationUsed: 86,
|
||||
locationTotal: 120,
|
||||
pendingInbound: 3,
|
||||
pendingOutbound: 2,
|
||||
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: '王工' },
|
||||
{ id: 'm1', time: '09:12', type: 'in', material: '电路板 PCBA-01', qty: 200, operator: '李工', batch: 'PCBA-01-20260922' },
|
||||
{ id: 'm2', time: '09:28', type: 'out', material: '装配螺丝 M6', qty: 500, operator: '王工', batch: 'M6-20260920' },
|
||||
{ id: 'm3', time: '10:05', type: 'in', material: '外壳上盖-铝合金', qty: 120, operator: '李工', batch: 'SJ-20260921' },
|
||||
{ id: 'm4', time: '10:41', type: 'out', material: '密封圈 硅胶', qty: 300, operator: '赵工', batch: 'MFQ-20260918' },
|
||||
{ id: 'm5', time: '11:03', type: 'in', material: '端子排 T-38', qty: 80, operator: '李工', batch: 'DZP-20260922' },
|
||||
{ id: 'm6', time: '11:20', type: 'out', material: '装配螺栓 M8', qty: 460, operator: '王工', batch: 'M8-20260919' },
|
||||
],
|
||||
},
|
||||
equipment: buildStations(),
|
||||
@@ -221,6 +226,8 @@ export function getDemoData(): DashboardData {
|
||||
},
|
||||
traces,
|
||||
trends: { production: trends },
|
||||
// 报警项仅用于语音播报、屏幕不渲染;演示数据不造报警(看板报喜不报忧)
|
||||
alarms: [],
|
||||
isDemo: true,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,15 +56,23 @@ export function ProductionBoard({ data }: { data: DashboardData }) {
|
||||
|
||||
return (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14, gridAutoRows: 'min-content' }}>
|
||||
<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}
|
||||
/>
|
||||
<div style={{ gridColumn: 'span 4', display: 'grid', gridTemplateColumns: 'repeat(5, 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}
|
||||
/>
|
||||
<Kpi
|
||||
value={production.cycleTime > 0 ? production.cycleTime.toFixed(1) : '—'}
|
||||
label="生产节拍"
|
||||
sub="相邻完工间隔均值(分)"
|
||||
color={C.amber}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Panel title="近 7 日产量趋势" style={{ gridColumn: 'span 2' }}>
|
||||
<EChart option={trendOption} height={200} />
|
||||
@@ -177,7 +185,7 @@ 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 }) {
|
||||
function Kpi({ value, label, sub, color }: { value: number | string; label: string; sub: string; color: string }) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
|
||||
@@ -8,6 +8,7 @@ interface MovementRow {
|
||||
material: string;
|
||||
qty: string;
|
||||
operator: string;
|
||||
batch: string;
|
||||
}
|
||||
|
||||
export function WarehouseBoard({ data }: { data: DashboardData }) {
|
||||
@@ -19,8 +20,12 @@ export function WarehouseBoard({ data }: { data: DashboardData }) {
|
||||
material: m.material,
|
||||
qty: `${m.qty}`,
|
||||
operator: m.operator,
|
||||
batch: m.batch || '—',
|
||||
}));
|
||||
|
||||
const locationPct =
|
||||
w.locationTotal > 0 ? `${Math.round((w.locationUsed / w.locationTotal) * 100)}%` : '—';
|
||||
|
||||
const columns = [
|
||||
{ title: '时间', dataIndex: 'time' },
|
||||
{
|
||||
@@ -32,21 +37,37 @@ export function WarehouseBoard({ data }: { data: DashboardData }) {
|
||||
},
|
||||
{ title: '物料名称', dataIndex: 'material' },
|
||||
{ title: '数量', dataIndex: 'qty' },
|
||||
{ title: '批次', dataIndex: 'batch', width: 140 },
|
||||
{ title: '操作人', dataIndex: 'operator' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16 }}>
|
||||
<Card title="库存总量" style={{ gridColumn: 'span 2' }}>
|
||||
<BigNumber value={w.totalStock} unit="件" color="#36a3f7" />
|
||||
</Card>
|
||||
<Card title="物料种类">
|
||||
<BigNumber value={w.materialTypes} unit="种" color="#00d68f" />
|
||||
</Card>
|
||||
<Card title="当日出入库">
|
||||
<div style={{ display: 'flex', gap: 24 }}>
|
||||
<TextStat color="#00d68f" value={w.inboundToday} label="入库" />
|
||||
<TextStat color="#36a3f7" value={w.outboundToday} label="出库" />
|
||||
<div style={{ gridColumn: 'span 4', display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 14 }}>
|
||||
<Card title="库存总量">
|
||||
<BigNumber value={w.totalStock} unit="件" color="#36a3f7" />
|
||||
</Card>
|
||||
<Card title="物料种类">
|
||||
<BigNumber value={w.materialTypes} unit="种" color="#00d68f" />
|
||||
</Card>
|
||||
<Card title="当日出入库">
|
||||
<div style={{ display: 'flex', gap: 24 }}>
|
||||
<TextStat color="#00d68f" value={w.inboundToday} label="入库" />
|
||||
<TextStat color="#36a3f7" value={w.outboundToday} label="出库" />
|
||||
</div>
|
||||
</Card>
|
||||
<Card title="库位利用率">
|
||||
<BigNumber value={locationPct} unit="" color="#fbbf24" />
|
||||
<div style={{ color: '#8fa3bf', fontSize: 12, marginTop: 4 }}>
|
||||
已用 {w.locationUsed} / 共 {w.locationTotal}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Card title="待处理出入库任务" style={{ gridColumn: 'span 4' }}>
|
||||
<div style={{ display: 'flex', gap: 32 }}>
|
||||
<TextStat color="#fbbf24" value={w.pendingInbound} label="入库待检(检未闭环)" />
|
||||
<TextStat color="#36a3f7" value={w.pendingOutbound} label="出库待送(已出库)" />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
@@ -77,7 +98,7 @@ function BigNumber({
|
||||
unit,
|
||||
color,
|
||||
}: {
|
||||
value: number;
|
||||
value: number | string;
|
||||
unit: string;
|
||||
color: string;
|
||||
}) {
|
||||
|
||||
@@ -248,6 +248,7 @@ function normalize(raw: Partial<DashboardData>): DashboardData {
|
||||
inLine: p.inLine ?? 0,
|
||||
deviceOnline: p.deviceOnline ?? 0,
|
||||
deviceTotal: p.deviceTotal ?? 0,
|
||||
cycleTime: p.cycleTime ?? 0,
|
||||
stationSummary: {
|
||||
running: p.stationSummary?.running ?? 0,
|
||||
idle: p.stationSummary?.idle ?? 0,
|
||||
@@ -260,6 +261,10 @@ function normalize(raw: Partial<DashboardData>): DashboardData {
|
||||
materialTypes: w.materialTypes ?? 0,
|
||||
inboundToday: w.inboundToday ?? 0,
|
||||
outboundToday: w.outboundToday ?? 0,
|
||||
locationUsed: w.locationUsed ?? 0,
|
||||
locationTotal: w.locationTotal ?? 0,
|
||||
pendingInbound: w.pendingInbound ?? 0,
|
||||
pendingOutbound: w.pendingOutbound ?? 0,
|
||||
movements: w.movements ?? [],
|
||||
},
|
||||
equipment: raw.equipment ?? [],
|
||||
@@ -284,6 +289,7 @@ function normalize(raw: Partial<DashboardData>): DashboardData {
|
||||
},
|
||||
traces: raw.traces ?? [],
|
||||
trends: raw.trends ?? { production: [] },
|
||||
alarms: raw.alarms ?? [],
|
||||
isDemo: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ export interface ProductionOverview {
|
||||
/** 设备在线数 / 总数 */
|
||||
deviceOnline: number;
|
||||
deviceTotal: number;
|
||||
/** 实际生产节拍(分钟):相邻完工间隔均值 */
|
||||
cycleTime: number;
|
||||
stationSummary: {
|
||||
running: number;
|
||||
idle: number;
|
||||
@@ -66,6 +68,8 @@ export interface StockMovement {
|
||||
material: string;
|
||||
qty: number;
|
||||
operator: string;
|
||||
/** 批次号 */
|
||||
batch: string;
|
||||
}
|
||||
|
||||
export interface WarehouseOverview {
|
||||
@@ -73,9 +77,26 @@ export interface WarehouseOverview {
|
||||
materialTypes: number;
|
||||
inboundToday: number;
|
||||
outboundToday: number;
|
||||
/** 已用库位 / 总库位(库位利用率) */
|
||||
locationUsed: number;
|
||||
locationTotal: number;
|
||||
/** 待处理出入库任务:入库检未闭环 / 出库已出库待送达 */
|
||||
pendingInbound: number;
|
||||
pendingOutbound: number;
|
||||
movements: StockMovement[];
|
||||
}
|
||||
|
||||
/** 报警项(仅用于语音播报,不在屏幕渲染) */
|
||||
export interface AlarmItem {
|
||||
id: string;
|
||||
level: string;
|
||||
type: string;
|
||||
target: string;
|
||||
message: string;
|
||||
time: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前订单(屏1 核心卡片)
|
||||
* 展示:合同信息、负责人、工期、完成度、可追溯。
|
||||
@@ -186,6 +207,8 @@ export interface DashboardData {
|
||||
/** 追溯轮播数据(最近完工工件) */
|
||||
traces: TraceItem[];
|
||||
trends: TrendData;
|
||||
/** 报警项(仅用于语音播报,屏幕不渲染) */
|
||||
alarms: AlarmItem[];
|
||||
/** 是否演示数据:真实业务数据为空时自动降级,角落低调标注 */
|
||||
isDemo: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user