feat: 装配线看板修正、统一密钥Hardman_2026、操作日志追溯、日志按天存储
Dashboard 移除 CNC/清洗机等不存在设备,改为纯装配线看板(扫码枪+拧紧枪+人工);JWT/内部token统一为 Hardman_2026 写入各 etc/*.yaml,MES 建表 DSN 改读 yaml;event_log 增加 workOrderNo/operator,BOM/备料/PLC下发/拧紧/扫码报工/半成品/AGV 全链路埋点,日志页支持工单号/操作人筛选;MES/WMS 日志按天存储(dailyWriter),WMS SetWriter 用 logx.NewWriter 适配
This commit is contained in:
@@ -4,19 +4,7 @@ import { color, font, radius } from '../theme/tokens';
|
||||
import { StatusDot } from './ui/StatusDot';
|
||||
import { useStore } from '../store/useStore';
|
||||
|
||||
type Page = 'overview' | 'monitor';
|
||||
|
||||
interface AppHeaderProps {
|
||||
page: Page;
|
||||
onChangePage: (p: Page) => void;
|
||||
}
|
||||
|
||||
const TABS: { key: Page; label: string; en: string }[] = [
|
||||
{ key: 'overview', label: '产线概览', en: 'OVERVIEW' },
|
||||
{ key: 'monitor', label: '设备监控', en: 'MONITOR' },
|
||||
];
|
||||
|
||||
export function AppHeader({ page, onChangePage }: AppHeaderProps) {
|
||||
export function AppHeader() {
|
||||
const [now, setNow] = useState(() => dayjs());
|
||||
const overview = useStore((s) => s.overview);
|
||||
|
||||
@@ -52,7 +40,7 @@ export function AppHeader({ page, onChangePage }: AppHeaderProps) {
|
||||
lineHeight: 1.1,
|
||||
margin: 0,
|
||||
}}>
|
||||
液压马达后盖 CNC 产线
|
||||
液压马达后盖装配线
|
||||
</h1>
|
||||
<div style={{
|
||||
fontSize: 10, letterSpacing: 4,
|
||||
@@ -60,65 +48,11 @@ export function AppHeader({ page, onChangePage }: AppHeaderProps) {
|
||||
fontFamily: font.display, fontWeight: 500,
|
||||
marginTop: 2,
|
||||
}}>
|
||||
HYDRAULIC MOTOR REAR COVER · CNC PRODUCTION COMMAND CENTER
|
||||
HYDRAULIC MOTOR REAR COVER · ASSEMBLY LINE COMMAND CENTER
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Center: Tabs */}
|
||||
<nav style={{
|
||||
position: 'absolute', left: '50%', transform: 'translateX(-50%)',
|
||||
display: 'flex', gap: 4,
|
||||
padding: 4,
|
||||
background: 'rgba(13,22,46,0.6)',
|
||||
border: `1px solid ${color.border.base}`,
|
||||
borderRadius: radius.md,
|
||||
}}>
|
||||
{TABS.map((tab) => {
|
||||
const active = page === tab.key;
|
||||
return (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => onChangePage(tab.key)}
|
||||
style={{
|
||||
position: 'relative',
|
||||
padding: '6px 18px',
|
||||
background: active
|
||||
? `linear-gradient(180deg, ${color.primary[500]}30, ${color.primary[600]}10)`
|
||||
: 'transparent',
|
||||
border: 'none',
|
||||
borderRadius: radius.sm,
|
||||
color: active ? color.text.primary : color.text.tertiary,
|
||||
fontSize: 13, fontWeight: 600,
|
||||
fontFamily: font.body,
|
||||
cursor: 'pointer',
|
||||
transition: 'all 200ms ease',
|
||||
display: 'flex', alignItems: 'center', gap: 8,
|
||||
letterSpacing: 1,
|
||||
}}
|
||||
onMouseEnter={(e) => { if (!active) e.currentTarget.style.color = color.text.secondary; }}
|
||||
onMouseLeave={(e) => { if (!active) e.currentTarget.style.color = color.text.tertiary; }}
|
||||
>
|
||||
{active && (
|
||||
<span style={{
|
||||
width: 4, height: 4, borderRadius: '50%',
|
||||
background: color.primary[400],
|
||||
boxShadow: `0 0 8px ${color.primary[400]}`,
|
||||
}} />
|
||||
)}
|
||||
<span>{tab.label}</span>
|
||||
<span style={{
|
||||
fontFamily: font.display, fontSize: 10, opacity: 0.5,
|
||||
letterSpacing: 1.5,
|
||||
}}>
|
||||
{tab.en}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Right: Status + Time */}
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 18 }}>
|
||||
<div style={{
|
||||
|
||||
@@ -1,203 +0,0 @@
|
||||
import { useMemo } from 'react';
|
||||
import type { EChartsOption } from 'echarts';
|
||||
import { useStore } from '../store/useStore';
|
||||
import { color, font } from '../theme/tokens';
|
||||
import { useEChart } from '../hooks/useEChart';
|
||||
|
||||
// CNC 实际运行状态(来自 dc_device_status + okuma_data),与槽位调度状态不同
|
||||
const CNC_STATUS_LABEL: Record<string, string> = {
|
||||
RUN: '运行',
|
||||
STOP: '停止',
|
||||
ALM: '报警',
|
||||
HOLD: '暂停',
|
||||
MSTR: '手动',
|
||||
MEM: '记忆',
|
||||
AUTO: '自动',
|
||||
待机: '待机',
|
||||
离线: '离线',
|
||||
};
|
||||
|
||||
// 展示顺序:运行最优先,报警最显眼,其余跟随
|
||||
const STATUS_ORDER = ['RUN', 'ALM', '待机', 'HOLD', 'STOP', 'MSTR', 'MEM', '离线'] as const;
|
||||
|
||||
function statusColor(s: string): string {
|
||||
if (s === 'RUN') return color.status.success;
|
||||
if (s === 'ALM') return color.status.danger;
|
||||
if (s === 'HOLD' || s === 'STOP') return color.status.warning;
|
||||
if (s === '离线') return color.status.neutral;
|
||||
if (s === '待机') return color.status.info;
|
||||
return color.status.info;
|
||||
}
|
||||
|
||||
/**
|
||||
* CNC 状态分布环形图
|
||||
*
|
||||
* 数据源:cncLatest(后端 /cnc-latest,以 dc_device_status 中的 CNC 设备为基准)。
|
||||
* 按实际机器运行状态(RUN/STOP/ALM/HOLD 等)聚合;无 okuma 快照时按连接状态
|
||||
* 兜底为"待机/离线",与 MachineMonitor 卡片口径一致。
|
||||
*/
|
||||
export default function CncStatusChart() {
|
||||
const cncLatest = useStore((s) => s.cncLatest);
|
||||
|
||||
const { buckets, total } = useMemo(() => {
|
||||
const counts = new Map<string, number>();
|
||||
for (const cnc of cncLatest) {
|
||||
// 与 MachineMonitor 兜底逻辑保持一致
|
||||
const hasSnapshot = !!cnc.status;
|
||||
const status = hasSnapshot ? cnc.status : (cnc.is_connected ? '待机' : '离线');
|
||||
counts.set(status, (counts.get(status) ?? 0) + 1);
|
||||
}
|
||||
const ordered: { status: string; count: number }[] = [];
|
||||
for (const s of STATUS_ORDER) {
|
||||
if (counts.has(s)) ordered.push({ status: s, count: counts.get(s)! });
|
||||
}
|
||||
// 兜底:未在预定义顺序的状态拼到末尾
|
||||
for (const [status, count] of counts) {
|
||||
if (!(STATUS_ORDER as readonly string[]).includes(status)) {
|
||||
ordered.push({ status, count });
|
||||
}
|
||||
}
|
||||
return { buckets: ordered, total: cncLatest.length };
|
||||
}, [cncLatest]);
|
||||
|
||||
const option = useMemo<EChartsOption>(() => {
|
||||
if (total === 0) {
|
||||
return {
|
||||
backgroundColor: 'transparent',
|
||||
title: {
|
||||
text: '暂无 CNC 数据',
|
||||
left: 'center', top: 'middle',
|
||||
textStyle: { color: color.text.tertiary, fontSize: 12, fontWeight: 400 },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
backgroundColor: 'rgba(8,15,32,0.95)',
|
||||
borderColor: 'rgba(34,211,238,0.4)',
|
||||
borderWidth: 1,
|
||||
textStyle: { color: '#e6f1ff', fontSize: 12, fontFamily: font.body },
|
||||
extraCssText: 'box-shadow:0 8px 24px rgba(0,0,0,0.6); backdrop-filter: blur(8px);',
|
||||
formatter: (p: any) => {
|
||||
const pct = total > 0 ? ((p.value / total) * 100).toFixed(0) : '0';
|
||||
return `
|
||||
<div style="display:flex;align-items:center;gap:8px;font-size:12px;">
|
||||
<span style="width:8px;height:8px;border-radius:50%;background:${p.color};box-shadow:0 0 6px ${p.color};"></span>
|
||||
<span style="color:#e6f1ff;">${p.name}</span>
|
||||
<span style="color:#22d3ee;font-family:${font.mono};margin-left:8px;font-weight:600;">${p.value} 台</span>
|
||||
<span style="color:#8ba1c7;font-family:${font.mono};">${pct}%</span>
|
||||
</div>`;
|
||||
},
|
||||
},
|
||||
// 中心总台数 + 副标题
|
||||
graphic: [
|
||||
{
|
||||
type: 'text',
|
||||
left: 'center',
|
||||
top: '38%',
|
||||
style: {
|
||||
text: String(total),
|
||||
fill: color.text.primary,
|
||||
fontFamily: font.mono,
|
||||
fontSize: 28,
|
||||
fontWeight: 700,
|
||||
textShadowColor: 'rgba(34,211,238,0.5)',
|
||||
textShadowBlur: 12,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
left: 'center',
|
||||
top: '58%',
|
||||
style: {
|
||||
text: 'CNC 台数',
|
||||
fill: color.text.tertiary,
|
||||
fontFamily: font.display,
|
||||
fontSize: 10,
|
||||
},
|
||||
},
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: 'CNC 状态',
|
||||
type: 'pie',
|
||||
radius: ['58%', '78%'],
|
||||
center: ['50%', '50%'],
|
||||
avoidLabelOverlap: false,
|
||||
label: { show: false },
|
||||
labelLine: { show: false },
|
||||
itemStyle: {
|
||||
borderColor: 'rgba(8,15,32,0.95)',
|
||||
borderWidth: 2,
|
||||
shadowBlur: 8,
|
||||
shadowColor: 'rgba(34,211,238,0.25)',
|
||||
},
|
||||
emphasis: {
|
||||
scale: true,
|
||||
scaleSize: 4,
|
||||
itemStyle: { shadowBlur: 16 },
|
||||
},
|
||||
data: buckets.map(({ status, count }) => ({
|
||||
name: CNC_STATUS_LABEL[status] || status,
|
||||
value: count,
|
||||
itemStyle: { color: statusColor(status) },
|
||||
})),
|
||||
},
|
||||
],
|
||||
animationDuration: 700,
|
||||
animationEasing: 'cubicOut',
|
||||
};
|
||||
}, [buckets, total]);
|
||||
|
||||
const ref = useEChart(option);
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
width: '100%', height: '100%',
|
||||
display: 'flex', flexDirection: 'column',
|
||||
}}>
|
||||
<div style={{ flex: 1, minHeight: 0 }}>
|
||||
<div ref={ref} style={{ width: '100%', height: '100%' }} />
|
||||
</div>
|
||||
{/* 图例:状态计数(空态不渲染,避免空行) */}
|
||||
{total > 0 && (
|
||||
<div style={{
|
||||
flexShrink: 0,
|
||||
display: 'flex', flexWrap: 'wrap',
|
||||
justifyContent: 'center', gap: '4px 10px',
|
||||
padding: '4px 4px 2px',
|
||||
}}>
|
||||
{buckets.map(({ status, count }) => {
|
||||
const c = statusColor(status);
|
||||
return (
|
||||
<div key={status} style={{
|
||||
display: 'inline-flex', alignItems: 'center', gap: 5,
|
||||
fontSize: 10,
|
||||
}}>
|
||||
<span style={{
|
||||
width: 6, height: 6, borderRadius: '50%',
|
||||
background: c, boxShadow: `0 0 6px ${c}`,
|
||||
flexShrink: 0,
|
||||
}} />
|
||||
<span style={{
|
||||
color: color.text.secondary,
|
||||
fontFamily: font.body, letterSpacing: 0.5,
|
||||
}}>
|
||||
{CNC_STATUS_LABEL[status] || status}
|
||||
</span>
|
||||
<span className="tnum" style={{
|
||||
color: c, fontFamily: font.mono, fontWeight: 600,
|
||||
}}>
|
||||
{count}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
import { useMemo } from 'react';
|
||||
import * as echarts from 'echarts';
|
||||
import type { EChartsOption } from 'echarts';
|
||||
import { useStore } from '../store/useStore';
|
||||
import { color, font } from '../theme/tokens';
|
||||
import { useEChart } from '../hooks/useEChart';
|
||||
|
||||
// 三种 category 的展示顺序与配色(与 tokens.category 对齐,缺省回退中性色)
|
||||
const CATEGORY_ORDER = ['A6VM107', 'A6VM160', 'A6VM200'];
|
||||
const catColor = (cat: string) =>
|
||||
(color.category as Record<string, string>)[cat] || color.status.neutral;
|
||||
|
||||
// 内窥镜检测趋势:与 SamplingTrendChart 同构,数据源 inspectionTrends
|
||||
export default function InspectionTrendChart() {
|
||||
const trends = useStore((s) => s.inspectionTrends);
|
||||
|
||||
const option = useMemo<EChartsOption | null>(() => {
|
||||
if (!trends.length) return null;
|
||||
|
||||
const dates = Array.from(new Set(trends.map((t) => t.date)));
|
||||
const cats = Array.from(new Set(trends.map((t) => t.category)))
|
||||
.sort((a, b) => CATEGORY_ORDER.indexOf(a) - CATEGORY_ORDER.indexOf(b));
|
||||
|
||||
const cell = new Map<string, { passed: number; failed: number }>();
|
||||
for (const t of trends) {
|
||||
cell.set(`${t.date}|${t.category}`, { passed: t.passed, failed: t.failed });
|
||||
}
|
||||
|
||||
// 每个 category 两个 series:合格(category 色) + 不合格(红色),堆叠到同一 category
|
||||
const series: any[] = [];
|
||||
for (const cat of cats) {
|
||||
const base = catColor(cat);
|
||||
series.push({
|
||||
name: `${cat} 合格`,
|
||||
type: 'bar',
|
||||
stack: cat,
|
||||
barMaxWidth: 22,
|
||||
itemStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: base },
|
||||
{ offset: 1, color: `${base}66` },
|
||||
]),
|
||||
borderRadius: [2, 2, 0, 0],
|
||||
shadowBlur: 6,
|
||||
shadowColor: `${base}55`,
|
||||
},
|
||||
emphasis: { focus: 'series' as const },
|
||||
data: dates.map((d) => cell.get(`${d}|${cat}`)?.passed ?? 0),
|
||||
});
|
||||
series.push({
|
||||
name: `${cat} 不合格`,
|
||||
type: 'bar',
|
||||
stack: cat,
|
||||
barMaxWidth: 22,
|
||||
itemStyle: {
|
||||
color: color.status.danger,
|
||||
borderRadius: [2, 2, 0, 0],
|
||||
},
|
||||
emphasis: { focus: 'series' as const },
|
||||
data: dates.map((d) => cell.get(`${d}|${cat}`)?.failed ?? 0),
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: 'rgba(8,15,32,0.95)',
|
||||
borderColor: 'rgba(34,211,238,0.4)',
|
||||
borderWidth: 1,
|
||||
textStyle: { color: '#e6f1ff', fontSize: 12, fontFamily: font.body },
|
||||
extraCssText: 'box-shadow:0 8px 24px rgba(0,0,0,0.6); backdrop-filter: blur(8px);',
|
||||
axisPointer: {
|
||||
type: 'shadow',
|
||||
shadowStyle: { color: 'rgba(34,211,238,0.06)' },
|
||||
},
|
||||
formatter: (params: any) => {
|
||||
const date = params[0]?.axisValue ?? '';
|
||||
const byCat = new Map<string, { passed: number; failed: number }>();
|
||||
for (const p of params) {
|
||||
const m = /^(\S+)\s(合格|不合格)$/.exec(p.seriesName);
|
||||
if (!m) continue;
|
||||
const [, cat, kind] = m;
|
||||
const cur = byCat.get(cat) ?? { passed: 0, failed: 0 };
|
||||
if (kind === '合格') cur.passed = p.value ?? 0;
|
||||
else cur.failed = p.value ?? 0;
|
||||
byCat.set(cat, cur);
|
||||
}
|
||||
const rows = Array.from(byCat.entries())
|
||||
.map(([cat, v]) => {
|
||||
const total = v.passed + v.failed;
|
||||
const yld = total > 0 ? ((v.passed / total) * 100).toFixed(1) : '--';
|
||||
const c = catColor(cat);
|
||||
return `
|
||||
<div style="display:flex;align-items:center;gap:8px;margin-top:4px;font-size:12px;">
|
||||
<span style="width:8px;height:8px;border-radius:50%;background:${c};box-shadow:0 0 6px ${c};"></span>
|
||||
<span style="color:#e6f1ff;min-width:74px;">${cat}</span>
|
||||
<span style="color:#10d68a;font-family:${font.mono};min-width:40px;text-align:right;">合 ${v.passed}</span>
|
||||
<span style="color:#f43f5e;font-family:${font.mono};min-width:48px;text-align:right;">废 ${v.failed}</span>
|
||||
<span style="color:#22d3ee;font-family:${font.mono};min-width:48px;text-align:right;">${yld}%</span>
|
||||
</div>`;
|
||||
})
|
||||
.join('');
|
||||
const dayTotal = Array.from(byCat.values()).reduce((s, v) => s + v.passed + v.failed, 0);
|
||||
return `
|
||||
<div style="font-size:11px;color:#8ba1c7;letter-spacing:0.5px;margin-bottom:2px;">
|
||||
${date} <span style="color:#67e8f9;font-family:${font.mono};margin-left:8px;">检测合计 ${dayTotal} 件</span>
|
||||
</div>${rows}`;
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
data: series.map((s) => s.name),
|
||||
textStyle: { color: color.text.secondary, fontSize: 10, fontFamily: font.body },
|
||||
right: 8, top: 4,
|
||||
itemWidth: 8, itemHeight: 8, itemGap: 8,
|
||||
icon: 'circle',
|
||||
},
|
||||
grid: { top: 36, right: 12, bottom: 24, left: 36, containLabel: true },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLabel: {
|
||||
color: color.text.tertiary, fontSize: 10, fontFamily: font.mono,
|
||||
},
|
||||
axisLine: { lineStyle: { color: color.border.base } },
|
||||
axisTick: { show: false },
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
minInterval: 1,
|
||||
axisLabel: {
|
||||
color: color.text.tertiary, fontSize: 10, fontFamily: font.mono,
|
||||
},
|
||||
axisLine: { show: false },
|
||||
axisTick: { show: false },
|
||||
splitLine: { lineStyle: { color: color.border.grid, type: 'dashed' } },
|
||||
},
|
||||
series,
|
||||
animationDuration: 700,
|
||||
animationEasing: 'cubicOut',
|
||||
};
|
||||
}, [trends]);
|
||||
|
||||
const ref = useEChart(option);
|
||||
return <div ref={ref} style={{ width: '100%', height: '100%' }} />;
|
||||
}
|
||||
@@ -144,35 +144,19 @@ const IconAlert = () => (
|
||||
<circle cx="12" cy="17" r="0.5" fill="currentColor" />
|
||||
</svg>
|
||||
);
|
||||
const IconSampling = () => (
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" style={iconStyle}>
|
||||
<circle cx="10.5" cy="10.5" r="6.5" />
|
||||
<line x1="15.5" y1="15.5" x2="20" y2="20" />
|
||||
<polyline points="8 10.5 10 12.5 13.5 8.5" />
|
||||
</svg>
|
||||
);
|
||||
const IconInspection = () => (
|
||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" style={iconStyle}>
|
||||
<circle cx="10.5" cy="10.5" r="6.5" />
|
||||
<line x1="15.5" y1="15.5" x2="20" y2="20" />
|
||||
<line x1="7" y1="10.5" x2="14" y2="10.5" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export default function KPICards() {
|
||||
const overview = useStore((s) => s.overview);
|
||||
const samplingOverview = useStore((s) => s.samplingOverview);
|
||||
const inspectionOverview = useStore((s) => s.inspectionOverview);
|
||||
|
||||
if (!overview) {
|
||||
return (
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(7, 1fr)',
|
||||
gridTemplateColumns: 'repeat(5, 1fr)',
|
||||
gap: 12,
|
||||
padding: '0 12px',
|
||||
}}>
|
||||
{[0, 1, 2, 3, 4, 5, 6].map(i => (
|
||||
{[0, 1, 2, 3, 4].map(i => (
|
||||
<div key={i} style={{
|
||||
background: 'rgba(15,26,52,0.4)',
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
@@ -187,7 +171,7 @@ export default function KPICards() {
|
||||
return (
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(7, 1fr)',
|
||||
gridTemplateColumns: 'repeat(5, 1fr)',
|
||||
gap: 12,
|
||||
padding: '0 12px',
|
||||
}}>
|
||||
@@ -207,8 +191,8 @@ export default function KPICards() {
|
||||
icon={<IconCheck />}
|
||||
/>
|
||||
<KpiCard
|
||||
label="设备利用率"
|
||||
enLabel="EQUIPMENT UTIL"
|
||||
label="工位利用率"
|
||||
enLabel="STATION UTIL"
|
||||
value={overview.equipment_util_rate}
|
||||
decimals={1}
|
||||
suffix="%"
|
||||
@@ -224,24 +208,6 @@ export default function KPICards() {
|
||||
tone={color.status.accent}
|
||||
icon={<IconPercent />}
|
||||
/>
|
||||
<KpiCard
|
||||
label="抽检合格率"
|
||||
enLabel="SAMPLING PASS RATE"
|
||||
value={samplingOverview?.pass_rate ?? 0}
|
||||
decimals={1}
|
||||
suffix="%"
|
||||
tone={color.primary[400]}
|
||||
icon={<IconSampling />}
|
||||
/>
|
||||
<KpiCard
|
||||
label="内窥镜合格率"
|
||||
enLabel="INSPECTION PASS RATE"
|
||||
value={inspectionOverview?.pass_rate ?? 0}
|
||||
decimals={1}
|
||||
suffix="%"
|
||||
tone={color.status.success}
|
||||
icon={<IconInspection />}
|
||||
/>
|
||||
<KpiCard
|
||||
label="活跃报警"
|
||||
enLabel="ACTIVE ALARMS"
|
||||
|
||||
@@ -1,644 +0,0 @@
|
||||
import { useEffect, useReducer } from 'react';
|
||||
import { useStore } from '../store/useStore';
|
||||
import type { CncDisplay, CncOeeItem, WasherOeeItem, WasherPoint } from '../types';
|
||||
import { color, font, radius } from '../theme/tokens';
|
||||
import { Panel } from './ui/Panel';
|
||||
import { StatusDot } from './ui/StatusDot';
|
||||
import { Badge } from './ui/Badge';
|
||||
import { SimBadge } from './ui/SimBadge';
|
||||
import { simulator } from '../utils/simulator';
|
||||
import type { SimStatus } from '../utils/simulator';
|
||||
import { mergeCnc, mergeWasher, fmt } from '../utils/machineFields';
|
||||
import type { FieldVal } from '../utils/machineFields';
|
||||
|
||||
// ===== Connection bar item =====
|
||||
function DeviceChip({ name, type, connected }: { name: string; type: string; connected: boolean }) {
|
||||
const c = connected ? color.status.success : color.status.danger;
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 8,
|
||||
padding: '4px 12px',
|
||||
background: `${c}10`,
|
||||
border: `1px solid ${c}33`,
|
||||
borderRadius: radius.sm,
|
||||
}}>
|
||||
<StatusDot color={c} size={6} pulse={connected} />
|
||||
<span style={{ fontSize: 12, color: color.text.primary }}>{name}</span>
|
||||
<span style={{
|
||||
fontSize: 9, color: color.text.tertiary,
|
||||
fontFamily: font.display, letterSpacing: 1,
|
||||
}}>
|
||||
{type}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== OEE Ring =====
|
||||
function OeeRing({ value, label, size = 52, color: ringColor }: {
|
||||
value: number; label: string; size?: number; color?: string;
|
||||
}) {
|
||||
const r = size / 2;
|
||||
const stroke = 4;
|
||||
const inner = r - stroke;
|
||||
const circ = 2 * Math.PI * inner;
|
||||
const v = Math.max(0, Math.min(value, 100));
|
||||
const offset = circ * (1 - v / 100);
|
||||
|
||||
const c = ringColor ?? (v >= 85 ? color.status.success : v >= 60 ? color.status.warning : color.status.danger);
|
||||
|
||||
return (
|
||||
<div style={{ textAlign: 'center', flexShrink: 0 }}>
|
||||
<svg width={size} height={size} style={{ display: 'block', margin: '0 auto', overflow: 'visible' }}>
|
||||
<defs>
|
||||
<linearGradient id={`oee-grad-${label}-${size}`} x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0%" stopColor={c} stopOpacity="1" />
|
||||
<stop offset="100%" stopColor={c} stopOpacity="0.6" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle cx={r} cy={r} r={inner}
|
||||
fill="none" stroke="rgba(56,189,248,0.10)" strokeWidth={stroke} />
|
||||
<circle cx={r} cy={r} r={inner}
|
||||
fill="none"
|
||||
stroke={`url(#oee-grad-${label}-${size})`}
|
||||
strokeWidth={stroke}
|
||||
strokeDasharray={circ}
|
||||
strokeDashoffset={offset}
|
||||
strokeLinecap="round"
|
||||
transform={`rotate(-90 ${r} ${r})`}
|
||||
style={{
|
||||
transition: 'stroke-dashoffset 600ms cubic-bezier(0.4,0,0.2,1)',
|
||||
filter: `drop-shadow(0 0 4px ${c}aa)`,
|
||||
}}
|
||||
/>
|
||||
<text x={r} y={r + 0.5} textAnchor="middle" dominantBaseline="middle"
|
||||
fill={color.text.primary}
|
||||
fontSize={size >= 56 ? 14 : 12}
|
||||
fontWeight={700}
|
||||
fontFamily={font.mono}>
|
||||
{v.toFixed(0)}
|
||||
</text>
|
||||
</svg>
|
||||
<div style={{
|
||||
fontSize: 9, color: color.text.tertiary,
|
||||
fontFamily: font.display, letterSpacing: 1, marginTop: 3,
|
||||
}}>
|
||||
{label}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RuntimeRow({ label, value, c }: { label: string; value: string; c: string }) {
|
||||
return (
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<span style={{
|
||||
color: color.text.muted, fontFamily: font.display,
|
||||
fontSize: 9, letterSpacing: 1, fontWeight: 600,
|
||||
}}>
|
||||
{label}
|
||||
</span>
|
||||
<span className="tnum" style={{
|
||||
color: c, fontFamily: font.mono, fontSize: 11, fontWeight: 600,
|
||||
}}>
|
||||
{value}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 通用小格子:label + 数值 + 可选 SIM 角标 =====
|
||||
function Metric({ label, val, fmt: fmtFn, color: c, unit }: {
|
||||
label: string;
|
||||
val: FieldVal<number | string | null>;
|
||||
fmt?: (v: number | string | null) => string;
|
||||
color?: string;
|
||||
unit?: string;
|
||||
}) {
|
||||
const text = val.value == null ? '--'
|
||||
: fmtFn ? fmtFn(val.value)
|
||||
: String(val.value);
|
||||
return (
|
||||
<div style={{
|
||||
background: 'rgba(8,15,32,0.6)',
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
borderRadius: radius.sm,
|
||||
padding: '5px 8px',
|
||||
display: 'flex', flexDirection: 'column', gap: 2,
|
||||
minWidth: 0,
|
||||
}}>
|
||||
<span style={{
|
||||
fontSize: 9, color: color.text.tertiary,
|
||||
fontFamily: font.display, letterSpacing: 0.8, fontWeight: 600,
|
||||
display: 'flex', alignItems: 'center',
|
||||
}}>
|
||||
{label}{val.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span className="tnum" style={{
|
||||
fontSize: 12, fontWeight: 600,
|
||||
color: c ?? color.primary[300],
|
||||
fontFamily: font.mono,
|
||||
textShadow: `0 0 6px ${(c ?? color.primary[300]).slice(0, 7)}55`,
|
||||
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
||||
}}>
|
||||
{text}{unit && text !== '--' ? <span style={{ fontSize: 9, color: color.text.tertiary, marginLeft: 2 }}>{unit}</span> : null}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 轴单格(比 Metric 更紧凑,用于轴行内联) =====
|
||||
function AxisCell({ label, val, fmt: fmtFn, color: c, unit }: {
|
||||
label: string;
|
||||
val: FieldVal<number | null>;
|
||||
fmt?: (v: number | null) => string;
|
||||
color?: string;
|
||||
unit?: string;
|
||||
}) {
|
||||
const text = val.value == null ? '--' : fmtFn ? fmtFn(val.value) : String(val.value);
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 1, minWidth: 0, lineHeight: 1.2 }}>
|
||||
<span style={{
|
||||
fontSize: 8, color: color.text.tertiary,
|
||||
fontFamily: font.display, letterSpacing: 0.5, fontWeight: 600,
|
||||
display: 'flex', alignItems: 'center',
|
||||
}}>
|
||||
{label}{val.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span className="tnum" style={{
|
||||
fontSize: 10, fontWeight: 600,
|
||||
color: c ?? color.text.secondary,
|
||||
fontFamily: font.mono,
|
||||
overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
||||
}}>
|
||||
{text}{unit && text !== '--' ? <span style={{ fontSize: 7, color: color.text.tertiary, marginLeft: 1 }}>{unit}</span> : null}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== 区块标题 =====
|
||||
function SectionLabel({ children, accent }: { children: string; accent?: string }) {
|
||||
return (
|
||||
<div style={{
|
||||
fontSize: 10, color: color.text.tertiary,
|
||||
fontFamily: font.display, letterSpacing: 2, fontWeight: 600,
|
||||
display: 'flex', alignItems: 'center', gap: 8, marginTop: 2,
|
||||
}}>
|
||||
<span style={{ width: 4, height: 4, borderRadius: '50%', background: accent ?? color.primary[400] }} />
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== Status Badge for CNC =====
|
||||
function statusTone(status: string): 'success' | 'danger' | 'warning' | 'info' | 'neutral' {
|
||||
if (status.includes('ALM') || status === 'FAULT') return 'danger';
|
||||
if (status === 'RUN') return 'success';
|
||||
if (status === 'HOLD' || status === 'STOP' || status === '待机') return 'warning';
|
||||
if (status === '离线' || status === 'OFFLINE') return 'neutral';
|
||||
if (status === 'AUTO' || status === 'MSTR' || status === 'MEM') return 'info';
|
||||
return 'neutral';
|
||||
}
|
||||
|
||||
// ===== CNC Card =====
|
||||
function CncCard({ cnc, oee }: { cnc: CncDisplay; oee?: CncOeeItem }) {
|
||||
const axes = cnc.axes ?? [];
|
||||
const hasSnapshot = !!cnc.status || axes.length > 0 || !!cnc.program;
|
||||
|
||||
// 喂真实状态给模拟器(每次渲染都同步)
|
||||
const simStatus: SimStatus = !hasSnapshot && !cnc.is_connected
|
||||
? 'OFFLINE'
|
||||
: (cnc.status || 'IDLE') as SimStatus;
|
||||
simulator.setState(cnc.machine, simStatus, cnc.mode || 'AUTO', cnc.program || '', !!cnc.is_connected);
|
||||
|
||||
// 取合并后的完整字段集(轴名用真实轴名)
|
||||
const axisNames = axes.length > 0 ? axes.map((a) => a.name || '') : ['X', 'Y', 'Z'];
|
||||
const sim = simulator.getState(cnc.machine, axisNames);
|
||||
const f = mergeCnc(cnc, sim);
|
||||
|
||||
const displayStatus = hasSnapshot
|
||||
? cnc.status
|
||||
: (cnc.is_connected ? '待机' : '离线');
|
||||
|
||||
const isAlarm = (cnc.status || '').includes('ALM');
|
||||
const isRunning = cnc.status === 'RUN';
|
||||
const isOffline = !hasSnapshot && !cnc.is_connected;
|
||||
const accentColor = isAlarm
|
||||
? color.status.danger
|
||||
: isRunning
|
||||
? color.status.success
|
||||
: isOffline
|
||||
? color.status.neutral
|
||||
: color.status.warning;
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position: 'relative',
|
||||
height: '100%',
|
||||
background: `linear-gradient(135deg, rgba(15,26,52,0.85) 0%, rgba(8,15,32,0.65) 100%)`,
|
||||
border: `1px solid ${accentColor}33`,
|
||||
borderRadius: radius.lg,
|
||||
padding: 12,
|
||||
display: 'flex', flexDirection: 'column', gap: 8,
|
||||
overflow: 'auto',
|
||||
boxShadow: isAlarm
|
||||
? `0 0 20px ${color.status.danger}40, inset 0 1px 0 ${color.status.danger}30`
|
||||
: `0 4px 16px rgba(0,0,0,0.3), inset 0 1px 0 ${accentColor}20`,
|
||||
}}>
|
||||
<div style={{
|
||||
position: 'absolute', top: 0, left: 0, right: 0, height: 2,
|
||||
background: `linear-gradient(90deg, transparent, ${accentColor}, transparent)`,
|
||||
animation: isRunning ? 'glow-breath 2s ease-in-out infinite' : undefined,
|
||||
}} />
|
||||
|
||||
{/* Header */}
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<StatusDot color={accentColor} size={8} pulse={isRunning || isAlarm} />
|
||||
<span style={{
|
||||
fontSize: 15, fontWeight: 700,
|
||||
color: color.text.primary,
|
||||
fontFamily: font.display, letterSpacing: 1.5,
|
||||
}}>
|
||||
{cnc.machine}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
||||
<Badge tone={statusTone(displayStatus)}>{displayStatus || '未知'}</Badge>
|
||||
<Badge tone={f.mode.value === 'AUTO' ? 'info' : 'neutral'}>
|
||||
{f.mode.value}{f.mode.source === 'sim' && <SimBadge />}
|
||||
</Badge>
|
||||
<Badge tone={f.eStop.value ? 'danger' : 'neutral'}>
|
||||
急停{f.eStop.value ? 'ON' : 'OFF'}{f.eStop.source === 'sim' && <SimBadge />}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* OEE rings + runtime */}
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 12,
|
||||
padding: '6px 10px',
|
||||
background: 'rgba(8,15,32,0.5)',
|
||||
borderRadius: radius.md,
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
}}>
|
||||
{oee ? (
|
||||
<>
|
||||
<OeeRing value={oee.oee} label="OEE" size={52} color={color.primary[400]} />
|
||||
<div style={{ width: 1, height: 38, background: color.border.base }} />
|
||||
<OeeRing value={oee.availability} label="可用" />
|
||||
<OeeRing value={oee.performance} label="性能" />
|
||||
<OeeRing value={oee.quality} label="质量" />
|
||||
<div style={{ width: 1, height: 38, background: color.border.base }} />
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, fontSize: 11, flex: 1 }}>
|
||||
<RuntimeRow label="NC RUN" value={oee.nc_run_time} c={color.status.info} />
|
||||
<RuntimeRow label="CUTTING" value={oee.cutting_time} c={color.status.success} />
|
||||
<RuntimeRow label="COUNT" value={`${oee.counter_val}/${oee.counter_set}`} c={color.status.accent} />
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div style={{ color: color.text.tertiary, fontSize: 11, padding: '6px 0' }}>
|
||||
等待 OEE 数据...
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 报警条:仅报警时有内容,单行紧凑 */}
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap',
|
||||
padding: '4px 8px', borderRadius: radius.sm,
|
||||
background: isAlarm ? `${color.status.danger}14` : 'rgba(8,15,32,0.4)',
|
||||
border: `1px solid ${isAlarm ? color.status.danger + '44' : color.border.subtle}`,
|
||||
fontSize: 10, fontFamily: font.mono,
|
||||
}}>
|
||||
<span style={{ color: color.text.muted, fontFamily: font.display, fontWeight: 600, letterSpacing: 1 }}>报警</span>
|
||||
<span style={{ color: color.status.danger }}>
|
||||
{f.alarmNo.value || '--'}{f.alarmNo.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span style={{ color: color.status.danger }}>
|
||||
{f.alarmType.value || '--'}{f.alarmType.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span style={{ color: color.text.secondary, flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{f.alarmText.value || '无报警'}{f.alarmText.source === 'sim' && !f.alarmText.value ? <SimBadge /> : null}
|
||||
</span>
|
||||
<span style={{ color: color.text.tertiary }}>
|
||||
{fmt.time(f.alarmStart.value as string)} → {fmt.time(f.alarmEnd.value as string)}{f.alarmStart.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 进给轴:每轴一行,坐标4系+速度3项 横排紧凑 */}
|
||||
<SectionLabel accent={color.primary[400]}>进给轴 · AXES</SectionLabel>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||
{f.axes.map((ax, i) => (
|
||||
<div key={i} style={{
|
||||
background: 'rgba(8,15,32,0.6)',
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
borderRadius: radius.sm,
|
||||
padding: '3px 6px',
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '24px repeat(4, 1fr) repeat(3, 1fr)',
|
||||
gap: 4, alignItems: 'center',
|
||||
}}>
|
||||
<span style={{
|
||||
fontSize: 11, fontWeight: 700, color: color.primary[300],
|
||||
fontFamily: font.display, letterSpacing: 1, textAlign: 'center',
|
||||
}}>{ax.name}</span>
|
||||
<AxisCell label="绝" val={ax.abs} fmt={(v) => (v as number).toFixed(3)} />
|
||||
<AxisCell label="相" val={ax.rel} fmt={(v) => (v as number).toFixed(3)} />
|
||||
<AxisCell label="机" val={ax.mac} fmt={(v) => (v as number).toFixed(3)} />
|
||||
<AxisCell label="余" val={ax.remain} fmt={(v) => (v as number).toFixed(3)} />
|
||||
<AxisCell label="设定" val={ax.feedSet} fmt={(v) => (v as number).toFixed(0)} unit="m/m" color={color.status.info} />
|
||||
<AxisCell label="实际" val={ax.feedAct} fmt={(v) => (v as number).toFixed(0)} unit="m/m" color={color.status.success} />
|
||||
<AxisCell label="载" val={ax.feedLoad} fmt={(v) => (v as number).toFixed(0)} unit="%" color={color.status.warning} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 工件轴 + 进给 合并一行 8 格 */}
|
||||
<SectionLabel accent={color.status.accent}>主轴 / 进给 · SPINDLE / FEED</SectionLabel>
|
||||
<div style={{
|
||||
display: 'grid', gridTemplateColumns: 'repeat(8, 1fr)', gap: 4,
|
||||
}}>
|
||||
<Metric label="主轴设定" val={f.workSet} fmt={(v) => (v as number).toFixed(0)} unit="rpm" color={color.status.info} />
|
||||
<Metric label="主轴实际" val={f.workAct} fmt={(v) => (v as number).toFixed(0)} unit="rpm" color={color.status.success} />
|
||||
<Metric label="主轴倍率" val={f.workOvr} fmt={(v) => `${(v as number).toFixed(0)}`} unit="%" color={color.status.accent} />
|
||||
<Metric label="主轴负载" val={f.workLoad} fmt={(v) => (v as number).toFixed(0)} unit="%" color={color.status.warning} />
|
||||
<Metric label="进给设定" val={f.feedSet} fmt={(v) => (v as number).toFixed(0)} unit="m/m" color={color.status.info} />
|
||||
<Metric label="进给实际" val={f.feedAct} fmt={(v) => (v as number).toFixed(0)} unit="m/m" color={color.status.success} />
|
||||
<Metric label="进给倍率" val={f.feedOvr} fmt={(v) => `${(v as number).toFixed(0)}`} unit="%" color={color.status.accent} />
|
||||
<Metric label="进给负载" val={f.feedLoad} fmt={(v) => (v as number).toFixed(0)} unit="%" color={color.status.warning} />
|
||||
</div>
|
||||
|
||||
{/* 程序区:名称/行号/行程序 + 时间类 + 能耗,一个紧凑块 */}
|
||||
<SectionLabel accent={color.status.success}>程序 · PROGRAM</SectionLabel>
|
||||
<div style={{
|
||||
background: 'rgba(8,15,32,0.6)',
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
borderRadius: radius.sm,
|
||||
padding: '5px 8px',
|
||||
display: 'flex', flexDirection: 'column', gap: 3,
|
||||
}}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 10, fontFamily: font.mono }}>
|
||||
<span style={{ color: color.text.muted, fontFamily: font.display, letterSpacing: 1, fontWeight: 600 }}>PGM</span>
|
||||
<span style={{ color: color.text.secondary, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{f.program.value || '--'}{f.program.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span style={{ color: color.text.muted, fontFamily: font.display, letterSpacing: 1, fontWeight: 600, marginLeft: 'auto' }}>N</span>
|
||||
<span className="tnum" style={{ color: color.primary[300], fontWeight: 600 }}>
|
||||
{f.lineNo.value}{f.lineNo.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span style={{ color: color.text.muted, fontFamily: font.display, letterSpacing: 1, fontWeight: 600, marginLeft: 8 }}>循环</span>
|
||||
<span className="tnum" style={{ color: color.status.info }}>
|
||||
{fmt.duration(f.cycleTotal.value as number)}{f.cycleTotal.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span style={{ color: color.text.muted }}>剩</span>
|
||||
<span className="tnum" style={{ color: color.status.warning }}>
|
||||
{fmt.duration(f.cycleRemain.value as number)}{f.cycleRemain.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
<span style={{ color: color.text.muted, fontFamily: font.display, letterSpacing: 1, fontWeight: 600, marginLeft: 8 }}>能耗</span>
|
||||
<span className="tnum" style={{ color: color.status.warning }}>
|
||||
{(f.energy.value as number).toFixed(3)}kWh{f.energy.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 9, fontFamily: font.mono, color: color.text.tertiary }}>
|
||||
<span style={{ fontFamily: font.display, letterSpacing: 1, fontWeight: 600, color: color.text.muted }}>加工</span>
|
||||
<span>{fmt.time(f.machStart.value as string)} → {fmt.time(f.machEnd.value as string)}{f.machStart.source === 'sim' && <SimBadge />}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== Washer Card =====
|
||||
function WasherCard({ points, oee }: { points: WasherPoint[]; oee?: WasherOeeItem }) {
|
||||
const connected = oee?.is_connected ?? false;
|
||||
const accent = connected ? color.status.info : color.status.neutral;
|
||||
|
||||
// 喂真实状态给模拟器:清洗机状态点 data_name="状态"
|
||||
const statusPoint = points.find((p) => p.data_name === '状态');
|
||||
const rawStatus = statusPoint?.value || '';
|
||||
const simStatus: SimStatus = connected ? (rawStatus || 'IDLE') as SimStatus : 'OFFLINE';
|
||||
simulator.setState('washer-hp', simStatus, 'AUTO', '', connected);
|
||||
|
||||
const sim = simulator.getState('washer-hp', ['X', 'Y', 'Z']);
|
||||
const f = mergeWasher(points, sim);
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
position: 'relative', height: '100%',
|
||||
background: `linear-gradient(135deg, rgba(15,26,52,0.85) 0%, rgba(8,15,32,0.65) 100%)`,
|
||||
border: `1px solid ${accent}33`,
|
||||
borderRadius: radius.lg,
|
||||
padding: 12,
|
||||
display: 'flex', flexDirection: 'column', gap: 8,
|
||||
overflow: 'auto',
|
||||
boxShadow: `0 4px 16px rgba(0,0,0,0.3), inset 0 1px 0 ${accent}20`,
|
||||
}}>
|
||||
<div style={{
|
||||
position: 'absolute', top: 0, left: 0, right: 0, height: 2,
|
||||
background: `linear-gradient(90deg, transparent, ${accent}, transparent)`,
|
||||
}} />
|
||||
|
||||
{/* Header */}
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<StatusDot color={accent} size={8} pulse={connected} />
|
||||
<span style={{
|
||||
fontSize: 15, fontWeight: 700,
|
||||
color: color.text.primary,
|
||||
fontFamily: font.display, letterSpacing: 1.5,
|
||||
}}>
|
||||
高压清洗机
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', justifyContent: 'flex-end' }}>
|
||||
<Badge tone={connected ? 'success' : 'neutral'}>{connected ? '在线' : '离线'}</Badge>
|
||||
<Badge tone={f.mode.value === 'AUTO' ? 'info' : 'neutral'}>
|
||||
{f.mode.value}{f.mode.source === 'sim' && <SimBadge />}
|
||||
</Badge>
|
||||
<Badge tone={f.eStop.value ? 'danger' : 'neutral'}>
|
||||
急停{f.eStop.value ? 'ON' : 'OFF'}{f.eStop.source === 'sim' && <SimBadge />}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* OEE compact */}
|
||||
{oee ? (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 10,
|
||||
padding: '6px 10px',
|
||||
background: 'rgba(8,15,32,0.5)',
|
||||
borderRadius: radius.md,
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
}}>
|
||||
<OeeRing value={oee.oee} label="OEE" size={48} color={color.primary[400]} />
|
||||
<div style={{ width: 1, height: 34, background: color.border.base }} />
|
||||
<OeeRing value={oee.availability} label="可用" size={40} />
|
||||
<OeeRing value={oee.performance} label="性能" size={40} />
|
||||
<OeeRing value={oee.quality} label="质量" size={40} />
|
||||
<div style={{ width: 1, height: 34, background: color.border.base }} />
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4, fontSize: 11, flex: 1, minWidth: 0 }}>
|
||||
<RuntimeRow label="OUTPUT" value={`${oee.prod_count}/${oee.prod_target}`} c={color.status.accent} />
|
||||
<RuntimeRow label="RUN HRS" value={`${oee.runtime.toFixed(1)}h`} c={color.status.info} />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ color: color.text.tertiary, fontSize: 11, padding: '6px 0' }}>
|
||||
等待 OEE 数据...
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 报警区 */}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: 4 }}>
|
||||
<Metric label="报警类型" val={f.alarmType} color={color.status.danger} />
|
||||
<Metric label="报警编号" val={f.alarmNo} color={color.status.danger} />
|
||||
<Metric label="报警文本" val={f.alarmText} color={color.status.danger} />
|
||||
<Metric label="报警开始" val={f.alarmStart} fmt={(v) => fmt.time(v as string)} color={color.status.danger} />
|
||||
<Metric label="报警结束" val={f.alarmEnd} fmt={(v) => fmt.time(v as string)} color={color.status.danger} />
|
||||
</div>
|
||||
|
||||
{/* 三种坐标:机械 / 绝对 / 相对,各 X/Y/Z */}
|
||||
<SectionLabel accent={color.primary[400]}>坐标 · COORDINATE</SectionLabel>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||
{([
|
||||
{ label: '机械', getVal: (i: number) => f.axes[i].mac, c: color.primary[400] },
|
||||
{ label: '绝对', getVal: (i: number) => f.axes[i].abs, c: color.status.success },
|
||||
{ label: '相对', getVal: (i: number) => f.axes[i].rel, c: color.status.accent },
|
||||
{ label: '剩余', getVal: (i: number) => f.axes[i].remain, c: color.status.warning },
|
||||
] as const).map(({ label, getVal, c }) => (
|
||||
<div key={label} style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: '42px repeat(3, 1fr)',
|
||||
gap: 4, alignItems: 'center',
|
||||
}}>
|
||||
<span style={{
|
||||
fontSize: 10, fontWeight: 700, color: c,
|
||||
fontFamily: font.display, letterSpacing: 1,
|
||||
display: 'flex', alignItems: 'center',
|
||||
}}>
|
||||
{label}
|
||||
</span>
|
||||
{['X', 'Y', 'Z'].map((ax, i) => {
|
||||
const v = getVal(i);
|
||||
return (
|
||||
<div key={ax} style={{
|
||||
background: 'rgba(8,15,32,0.6)',
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
borderRadius: radius.sm,
|
||||
padding: '3px 6px',
|
||||
display: 'flex', justifyContent: 'space-between', alignItems: 'center',
|
||||
}}>
|
||||
<span style={{ fontSize: 9, color: color.text.tertiary, fontFamily: font.display, fontWeight: 600 }}>{ax}</span>
|
||||
<span className="tnum" style={{
|
||||
fontSize: 11, fontWeight: 600, color: c,
|
||||
fontFamily: font.mono, textShadow: `0 0 6px ${c}55`,
|
||||
display: 'flex', alignItems: 'center',
|
||||
}}>
|
||||
{typeof v.value === 'number' ? v.value.toFixed(3) : '--'}{v.source === 'sim' && <SimBadge />}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 工件轴/主轴 速度倍率负载 */}
|
||||
<SectionLabel accent={color.status.accent}>主轴 · SPINDLE</SectionLabel>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 4 }}>
|
||||
<Metric label="设定转速" val={f.workSet} fmt={(v) => (v as number).toFixed(0)} unit="rpm" color={color.status.info} />
|
||||
<Metric label="实际转速" val={f.workAct} fmt={(v) => (v as number).toFixed(0)} unit="rpm" color={color.status.success} />
|
||||
<Metric label="倍率" val={f.workOvr} fmt={(v) => `${(v as number).toFixed(0)}`} unit="%" color={color.status.accent} />
|
||||
<Metric label="负载" val={f.workLoad} fmt={(v) => (v as number).toFixed(1)} unit="%" color={color.status.warning} />
|
||||
</div>
|
||||
|
||||
{/* 进给 速度倍率负载 */}
|
||||
<SectionLabel accent={color.status.info}>进给 · FEED</SectionLabel>
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 4 }}>
|
||||
<Metric label="设定速度" val={f.feedSet} fmt={(v) => (v as number).toFixed(0)} unit="mm/min" color={color.status.info} />
|
||||
<Metric label="实际速度" val={f.feedAct} fmt={(v) => (v as number).toFixed(0)} unit="mm/min" color={color.status.success} />
|
||||
<Metric label="倍率" val={f.feedOvr} fmt={(v) => `${(v as number).toFixed(0)}`} unit="%" color={color.status.accent} />
|
||||
<Metric label="负载" val={f.feedLoad} fmt={(v) => (v as number).toFixed(1)} unit="%" color={color.status.warning} />
|
||||
</div>
|
||||
|
||||
{/* 程序信息 */}
|
||||
<SectionLabel accent={color.status.success}>程序 · PROGRAM</SectionLabel>
|
||||
<div style={{
|
||||
background: 'rgba(8,15,32,0.6)',
|
||||
border: `1px solid ${color.border.subtle}`,
|
||||
borderRadius: radius.sm,
|
||||
padding: '6px 8px',
|
||||
display: 'flex', flexDirection: 'column', gap: 4,
|
||||
}}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, fontSize: 10 }}>
|
||||
<span style={{ color: color.text.muted, fontFamily: font.display, letterSpacing: 1, fontWeight: 600 }}>程序号</span>
|
||||
<span style={{ color: color.text.secondary, fontFamily: font.mono }}>{f.program.value || '--'}{f.program.source === 'sim' && <SimBadge />}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ===== Main =====
|
||||
export default function MachineMonitor() {
|
||||
const devStatus = useStore((s) => s.devStatus);
|
||||
const cncLatest = useStore((s) => s.cncLatest);
|
||||
const washerLatest = useStore((s) => s.washerLatest);
|
||||
const cncOee = useStore((s) => s.cncOee);
|
||||
const washerOee = useStore((s) => s.washerOee);
|
||||
const monitorLoading = useStore((s) => s.monitorLoading);
|
||||
const fetchMonitor = useStore((s) => s.fetchMonitor);
|
||||
const refreshMonitor = useStore((s) => s.refreshMonitor);
|
||||
|
||||
// 强制重渲染驱动器(配合 1s tick)
|
||||
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
||||
|
||||
useEffect(() => {
|
||||
fetchMonitor();
|
||||
const t = setInterval(refreshMonitor, 5000);
|
||||
return () => clearInterval(t);
|
||||
}, [fetchMonitor, refreshMonitor]);
|
||||
|
||||
// 模拟引擎 1s tick,驱动仿真动画(坐标缓动/能耗递增/剩余时间倒数/行号递增)
|
||||
useEffect(() => {
|
||||
const unsub = simulator.subscribe(forceUpdate);
|
||||
const t = setInterval(() => simulator.tick(), 1000);
|
||||
return () => { unsub(); clearInterval(t); };
|
||||
}, []);
|
||||
|
||||
const oeeByMachine = new Map(cncOee.map((o) => [o.machine, o]));
|
||||
const washerOeeItem = washerOee[0];
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex', flexDirection: 'column', gap: 10, height: '100%',
|
||||
overflow: 'hidden',
|
||||
}}>
|
||||
{/* 4 设备卡片: 3 CNC + 1 清洗机, 2×2 网格统一展示 */}
|
||||
<div style={{
|
||||
flex: 1, display: 'grid',
|
||||
gridTemplateColumns: '1fr 1fr',
|
||||
gridAutoRows: '1fr',
|
||||
gap: 10, minHeight: 0,
|
||||
}}>
|
||||
{cncLatest.length === 0 && !monitorLoading ? (
|
||||
<div style={{
|
||||
gridColumn: '1 / -1',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
color: color.text.tertiary, fontSize: 13,
|
||||
border: `1px dashed ${color.border.base}`,
|
||||
borderRadius: radius.lg,
|
||||
}}>
|
||||
暂无 CNC 采集数据
|
||||
</div>
|
||||
) : (
|
||||
cncLatest.map((cnc) => (
|
||||
<CncCard key={cnc.machine} cnc={cnc} oee={oeeByMachine.get(cnc.machine)} />
|
||||
))
|
||||
)}
|
||||
<WasherCard points={washerLatest} oee={washerOeeItem} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
import { useMemo } from 'react';
|
||||
import * as echarts from 'echarts';
|
||||
import type { EChartsOption } from 'echarts';
|
||||
import { useStore } from '../store/useStore';
|
||||
import { color, font } from '../theme/tokens';
|
||||
import { useEChart } from '../hooks/useEChart';
|
||||
|
||||
// 三种 category 的展示顺序与配色(与 tokens.category 对齐,缺省回退中性色)
|
||||
const CATEGORY_ORDER = ['A6VM107', 'A6VM160', 'A6VM200'];
|
||||
const catColor = (cat: string) =>
|
||||
(color.category as Record<string, string>)[cat] || color.status.neutral;
|
||||
|
||||
export default function SamplingTrendChart() {
|
||||
const trends = useStore((s) => s.samplingTrends);
|
||||
|
||||
const option = useMemo<EChartsOption | null>(() => {
|
||||
if (!trends.length) return null;
|
||||
|
||||
// 聚合:trends 为 30 行(10 日 × 3 category),按日期/category 重组
|
||||
const dates = Array.from(new Set(trends.map((t) => t.date)));
|
||||
const cats = Array.from(new Set(trends.map((t) => t.category)))
|
||||
.sort((a, b) => CATEGORY_ORDER.indexOf(a) - CATEGORY_ORDER.indexOf(b));
|
||||
|
||||
// 按 date -> category 建索引,便于取值
|
||||
const cell = new Map<string, { passed: number; failed: number }>();
|
||||
for (const t of trends) {
|
||||
cell.set(`${t.date}|${t.category}`, { passed: t.passed, failed: t.failed });
|
||||
}
|
||||
|
||||
// 每个 category 两个 series:合格(category 色) + 不合格(红色),堆叠到同一 category
|
||||
const series: any[] = [];
|
||||
for (const cat of cats) {
|
||||
const base = catColor(cat);
|
||||
series.push({
|
||||
name: `${cat} 合格`,
|
||||
type: 'bar',
|
||||
stack: cat,
|
||||
barMaxWidth: 22,
|
||||
itemStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: base },
|
||||
{ offset: 1, color: `${base}66` },
|
||||
]),
|
||||
borderRadius: [2, 2, 0, 0],
|
||||
shadowBlur: 6,
|
||||
shadowColor: `${base}55`,
|
||||
},
|
||||
emphasis: { focus: 'series' as const },
|
||||
data: dates.map((d) => cell.get(`${d}|${cat}`)?.passed ?? 0),
|
||||
});
|
||||
series.push({
|
||||
name: `${cat} 不合格`,
|
||||
type: 'bar',
|
||||
stack: cat,
|
||||
barMaxWidth: 22,
|
||||
itemStyle: {
|
||||
color: color.status.danger,
|
||||
borderRadius: [2, 2, 0, 0],
|
||||
},
|
||||
emphasis: { focus: 'series' as const },
|
||||
data: dates.map((d) => cell.get(`${d}|${cat}`)?.failed ?? 0),
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
backgroundColor: 'transparent',
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: 'rgba(8,15,32,0.95)',
|
||||
borderColor: 'rgba(34,211,238,0.4)',
|
||||
borderWidth: 1,
|
||||
textStyle: { color: '#e6f1ff', fontSize: 12, fontFamily: font.body },
|
||||
extraCssText: 'box-shadow:0 8px 24px rgba(0,0,0,0.6); backdrop-filter: blur(8px);',
|
||||
axisPointer: {
|
||||
type: 'shadow',
|
||||
shadowStyle: { color: 'rgba(34,211,238,0.06)' },
|
||||
},
|
||||
formatter: (params: any) => {
|
||||
const date = params[0]?.axisValue ?? '';
|
||||
// 按 category 归并(同一 category 的 合格/不合格 两条)
|
||||
const byCat = new Map<string, { passed: number; failed: number }>();
|
||||
for (const p of params) {
|
||||
const m = /^(\S+)\s(合格|不合格)$/.exec(p.seriesName);
|
||||
if (!m) continue;
|
||||
const [, cat, kind] = m;
|
||||
const cur = byCat.get(cat) ?? { passed: 0, failed: 0 };
|
||||
if (kind === '合格') cur.passed = p.value ?? 0;
|
||||
else cur.failed = p.value ?? 0;
|
||||
byCat.set(cat, cur);
|
||||
}
|
||||
const rows = Array.from(byCat.entries())
|
||||
.map(([cat, v]) => {
|
||||
const total = v.passed + v.failed;
|
||||
const yld = total > 0 ? ((v.passed / total) * 100).toFixed(1) : '--';
|
||||
const c = catColor(cat);
|
||||
return `
|
||||
<div style="display:flex;align-items:center;gap:8px;margin-top:4px;font-size:12px;">
|
||||
<span style="width:8px;height:8px;border-radius:50%;background:${c};box-shadow:0 0 6px ${c};"></span>
|
||||
<span style="color:#e6f1ff;min-width:74px;">${cat}</span>
|
||||
<span style="color:#10d68a;font-family:${font.mono};min-width:40px;text-align:right;">合 ${v.passed}</span>
|
||||
<span style="color:#f43f5e;font-family:${font.mono};min-width:48px;text-align:right;">废 ${v.failed}</span>
|
||||
<span style="color:#22d3ee;font-family:${font.mono};min-width:48px;text-align:right;">${yld}%</span>
|
||||
</div>`;
|
||||
})
|
||||
.join('');
|
||||
const dayTotal = Array.from(byCat.values()).reduce((s, v) => s + v.passed + v.failed, 0);
|
||||
return `
|
||||
<div style="font-size:11px;color:#8ba1c7;letter-spacing:0.5px;margin-bottom:2px;">
|
||||
${date} <span style="color:#67e8f9;font-family:${font.mono};margin-left:8px;">抽检合计 ${dayTotal} 件</span>
|
||||
</div>${rows}`;
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
data: series.map((s) => s.name),
|
||||
textStyle: { color: color.text.secondary, fontSize: 10, fontFamily: font.body },
|
||||
right: 8, top: 4,
|
||||
itemWidth: 8, itemHeight: 8, itemGap: 8,
|
||||
icon: 'circle',
|
||||
},
|
||||
grid: { top: 36, right: 12, bottom: 24, left: 36, containLabel: true },
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: dates,
|
||||
axisLabel: {
|
||||
color: color.text.tertiary, fontSize: 10, fontFamily: font.mono,
|
||||
},
|
||||
axisLine: { lineStyle: { color: color.border.base } },
|
||||
axisTick: { show: false },
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
minInterval: 1,
|
||||
axisLabel: {
|
||||
color: color.text.tertiary, fontSize: 10, fontFamily: font.mono,
|
||||
},
|
||||
axisLine: { show: false },
|
||||
axisTick: { show: false },
|
||||
splitLine: { lineStyle: { color: color.border.grid, type: 'dashed' } },
|
||||
},
|
||||
series,
|
||||
animationDuration: 700,
|
||||
animationEasing: 'cubicOut',
|
||||
};
|
||||
}, [trends]);
|
||||
|
||||
const ref = useEChart(option);
|
||||
return <div ref={ref} style={{ width: '100%', height: '100%' }} />;
|
||||
}
|
||||
Reference in New Issue
Block a user