oee
This commit is contained in:
@@ -0,0 +1,380 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useTheme } from '../../context/ThemeContext';
|
||||
|
||||
/**
|
||||
* 业务本体图谱:节点、边都由调用方传入(履约本体 8 对象 / 品质本体 17 张表各一套),
|
||||
* 这里只负责画。力导向布局移植自智能体开发平台的本体管理页(纯手写 SVG,不引 d3):
|
||||
* 环形初始化 → 斥力 9000/d² → 弹簧 (d−rest)×0.008 → 向心 0.004 → 阻尼 0.88,跑满 120 帧收敛。
|
||||
* 斥力/弹簧原长/向心力都按容器尺寸与节点数给(不是写死常数),因此 8 与 17 节点两种规模都铺得开。
|
||||
*
|
||||
* 画布有三种模式,构成「总览 → 裂变 → 下钻」的现场演示动线:
|
||||
* graph 总览:17 张表 + 关系边(力导向)
|
||||
* explode 裂变:双击某张表后,它缩成中心锚,本表实例作为药签沿椭圆环炸开,其余表淡出
|
||||
* instance 下钻:再点一个实例,环上摊开该实例的字段(列名 = 值)
|
||||
* 两种 zoom 布局的坐标都是同步算出来的,CSS 只做透明/缩放插值,
|
||||
* 所以即使动画被浏览器挂起(无头截图场景),终态几何依然正确、可被 getBoundingClientRect 读出来。
|
||||
* 配色全走本应用主题 token,深浅两套主题都保证边线与文字有足够对比度。
|
||||
*/
|
||||
|
||||
export interface GNode { id: string; label: string; count: number; color: string }
|
||||
export interface GEdge { id: string; source: string; target: string; label: string }
|
||||
|
||||
export type GraphMode = 'graph' | 'explode' | 'instance';
|
||||
|
||||
/** 裂变/下钻环上的药签:explode 是实例,instance 是字段 */
|
||||
export interface SatNode { id: string; label: string; value?: string; badge?: string }
|
||||
|
||||
interface SimNode extends GNode { x: number; y: number; vx: number; vy: number; deg: number }
|
||||
|
||||
interface Props {
|
||||
nodes: GNode[];
|
||||
edges: GEdge[];
|
||||
selectedNodeId: string | null;
|
||||
selectedEdgeId: string | null;
|
||||
onNodeClick?: (id: string) => void;
|
||||
onEdgeClick?: (id: string) => void;
|
||||
/** 双击节点:进入裂变(把该表实例炸开成一圈) */
|
||||
onNodeDoubleClick?: (id: string) => void;
|
||||
/** 三种画布模式,缺省为总览 */
|
||||
mode?: GraphMode;
|
||||
/** explode / instance 的中心锚(表或实例) */
|
||||
center?: { label: string; sub?: string; badge?: string; color: string; count?: number } | null;
|
||||
/** explode / instance 环上的药签 */
|
||||
satellites?: SatNode[];
|
||||
/** 环上药签被点(explode 时=下钻该实例) */
|
||||
onSatelliteClick?: (id: string) => void;
|
||||
/** 点画布空白:返回上一级 */
|
||||
onBackgroundClick?: () => void;
|
||||
}
|
||||
|
||||
/** 椭圆环按弧长等分取点,避免直接按角度分导致长轴两端药签挤在一起 */
|
||||
function ellipsePoints(n: number, rx: number, ry: number, cx: number, cy: number): [number, number][] {
|
||||
if (n <= 0) return [];
|
||||
if (n === 1) return [[cx, cy - ry]];
|
||||
const N = 720;
|
||||
const acc: number[] = [0];
|
||||
let px = cx, py = cy - ry, total = 0;
|
||||
for (let i = 1; i <= N; i++) {
|
||||
const a = (i / N) * 2 * Math.PI - Math.PI / 2;
|
||||
const x = cx + rx * Math.cos(a), y = cy + ry * Math.sin(a);
|
||||
total += Math.hypot(x - px, y - py); acc.push(total); px = x; py = y;
|
||||
}
|
||||
/* 半轴 a,b 的椭圆周长:拉马努金近似,用来反推药签可用宽度 */
|
||||
const at = (target: number): [number, number] => {
|
||||
let lo = 0, hi = N;
|
||||
while (lo < hi) { const mid = (lo + hi) >> 1; if (acc[mid] < target) lo = mid + 1; else hi = mid; }
|
||||
const a = (lo / N) * 2 * Math.PI - Math.PI / 2;
|
||||
return [cx + rx * Math.cos(a), cy + ry * Math.sin(a)];
|
||||
};
|
||||
return Array.from({ length: n }, (_, k) => at((k / n) * total));
|
||||
}
|
||||
|
||||
const ellipseCircumference = (a: number, b: number) =>
|
||||
Math.PI * (3 * (a + b) - Math.sqrt((3 * a + b) * (a + 3 * b)));
|
||||
|
||||
/** 节点内只放清洗后的短名,全称留给节点下方那行 */
|
||||
const shortName = (s: string) => s.replace(/([^)]*)/g, '').trim();
|
||||
|
||||
export default function OntologyGraph({
|
||||
nodes: rawNodes, edges, selectedNodeId, selectedEdgeId, onNodeClick, onEdgeClick, onNodeDoubleClick,
|
||||
mode = 'graph', center = null, satellites = [], onSatelliteClick, onBackgroundClick,
|
||||
}: Props) {
|
||||
const { tokens } = useTheme();
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
const [nodes, setNodes] = useState<SimNode[]>([]);
|
||||
const [dims, setDims] = useState({ w: 720, h: 420 });
|
||||
const [hovered, setHovered] = useState<string | null>(null);
|
||||
/* 药签入场:不用 CSS animation(fill-mode:both 会把 0% 关键帧钉死,
|
||||
动画被挂起时终态就永远停在 opacity:0 / scale(0.2),无头截图里药签整个消失)。
|
||||
改成 JS 定时器翻状态 + 内层 <g> 的 transition:计时器照跑,
|
||||
而 transition 没有 fill-mode,静止态恒等于目标值(scale 1 / opacity 1),
|
||||
即使过渡帧被浏览器跳过,终态也是「全部可见」。 */
|
||||
const [satShown, setSatShown] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const box = svgRef.current?.parentElement;
|
||||
if (!box) return;
|
||||
const measure = () => {
|
||||
const r = box.getBoundingClientRect();
|
||||
if (r.width > 0 && r.height > 0) setDims({ w: r.width, h: r.height });
|
||||
};
|
||||
/* ResizeObserver 的回调靠 rAF 投递:页面切到后台时会整段挂起,舞台刚进场那几帧
|
||||
flex 比例也还没定。这里同步测一次 + 补两次延时测 + 盯 window resize,
|
||||
保证布局坐标系最终等于真实容器,不会因为 RO 没投递而按默认尺寸画。 */
|
||||
measure();
|
||||
const ro = new ResizeObserver(([e]) => setDims({ w: e.contentRect.width, h: e.contentRect.height }));
|
||||
ro.observe(box);
|
||||
const t1 = setTimeout(measure, 120);
|
||||
const t2 = setTimeout(measure, 420);
|
||||
window.addEventListener('resize', measure);
|
||||
return () => {
|
||||
ro.disconnect();
|
||||
clearTimeout(t1); clearTimeout(t2);
|
||||
window.removeEventListener('resize', measure);
|
||||
};
|
||||
}, []);
|
||||
|
||||
/* ── 布局仿真:数据或尺寸变化即重跑(数据只有 8 节点,成本可忽略) ── */
|
||||
useEffect(() => {
|
||||
if (rawNodes.length === 0) return;
|
||||
const cnt = rawNodes.length;
|
||||
/* 本体有两套规模:履约 8 对象、品质 17 张表。斥力/弹簧原长/向心力都按节点数缩放,
|
||||
否则 17 节点会挤成一团毛球、8 节点又散得太开。以 8 节点为基准(保持原参数不变)。 */
|
||||
const spread = cnt / 8;
|
||||
const cx = dims.w / 2, cy = dims.h / 2;
|
||||
const deg: Record<string, number> = {};
|
||||
rawNodes.forEach(n => { deg[n.id] = 0; });
|
||||
edges.forEach(e => { deg[e.source] = (deg[e.source] || 0) + 1; deg[e.target] = (deg[e.target] || 0) + 1; });
|
||||
/* 舞台通常是横宽竖窄的:初始化用椭圆环而不是正圆,避免节点全挤在中间一条 */
|
||||
const rx = Math.max(150, dims.w * 0.34), ry = Math.max(96, dims.h * 0.34);
|
||||
setNodes(rawNodes.map((n, i) => {
|
||||
const a = (2 * Math.PI * i) / cnt - Math.PI / 2;
|
||||
return { ...n, deg: deg[n.id] || 0, x: cx + rx * Math.cos(a), y: cy + ry * Math.sin(a), vx: 0, vy: 0 };
|
||||
}));
|
||||
|
||||
// 斥力与弹簧原长按容器尺寸与节点数给:常数写死会让宽舞台只用到中间一小块或挤成一团
|
||||
const repel = 9000 * spread;
|
||||
const rest = Math.max(100, Math.min(190, Math.min(dims.w, dims.h) * 0.5));
|
||||
let frame = 0;
|
||||
const timer = setInterval(() => {
|
||||
if (frame++ > 120) { clearInterval(timer); return; }
|
||||
setNodes(prev => {
|
||||
const next = prev.map(n => ({ ...n }));
|
||||
for (let i = 0; i < next.length; i++) for (let j = i + 1; j < next.length; j++) {
|
||||
const dx = next[j].x - next[i].x, dy = next[j].y - next[i].y;
|
||||
const d = Math.max(Math.hypot(dx, dy), 1);
|
||||
const f = repel / (d * d);
|
||||
next[i].vx -= (dx / d) * f; next[i].vy -= (dy / d) * f;
|
||||
next[j].vx += (dx / d) * f; next[j].vy += (dy / d) * f;
|
||||
}
|
||||
const byId = new Map(next.map(n => [n.id, n]));
|
||||
for (const e of edges) {
|
||||
const s = byId.get(e.source), t = byId.get(e.target);
|
||||
if (!s || !t) continue;
|
||||
const dx = t.x - s.x, dy = t.y - s.y;
|
||||
const d = Math.max(Math.hypot(dx, dy), 1);
|
||||
const f = (d - rest) * 0.008;
|
||||
s.vx += (dx / d) * f; s.vy += (dy / d) * f;
|
||||
t.vx -= (dx / d) * f; t.vy -= (dy / d) * f;
|
||||
}
|
||||
for (const n of next) {
|
||||
n.vx += (cx - n.x) * (0.004 / spread); n.vy += (cy - n.y) * (0.004 / spread);
|
||||
n.vx *= 0.88; n.vy *= 0.88; n.x += n.vx; n.y += n.vy;
|
||||
n.x = Math.max(74, Math.min(dims.w - 74, n.x));
|
||||
n.y = Math.max(52, Math.min(dims.h - 62, n.y));
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}, 16);
|
||||
return () => clearInterval(timer);
|
||||
}, [rawNodes, edges, dims]);
|
||||
|
||||
/* 每次换层(模式/中心/药签数变了)先归零再下一帧翻起,让错峰过渡重放一次 */
|
||||
useEffect(() => {
|
||||
setSatShown(false);
|
||||
const t = setTimeout(() => setSatShown(true), 24);
|
||||
return () => clearTimeout(t);
|
||||
}, [mode, center?.label, satellites.length]);
|
||||
|
||||
const maxDeg = useMemo(() => Math.max(...nodes.map(n => n.deg), 1), [nodes]);
|
||||
const byId = useMemo(() => new Map(nodes.map(n => [n.id, n] as const)), [nodes]);
|
||||
/** 度数决定半径:枢纽对象明显大于叶子对象 */
|
||||
const rOf = (deg: number) => 24 + (deg / maxDeg) * 12;
|
||||
/* 17 张表时边标签与节点下方的重复标签会糊成一团:密图只保留圈内名 + 数量,
|
||||
边的中文名改成悬停/选中才浮出,节点下方的「短名 · N 实例」也只在稀疏图(≤10 节点)保留。 */
|
||||
const dense = nodes.length > 10;
|
||||
|
||||
const active = hovered ?? selectedNodeId;
|
||||
const isNeighbor = (id: string) =>
|
||||
!!active && edges.some(e => (e.source === active && e.target === id) || (e.target === active && e.source === id));
|
||||
|
||||
/* 三种模式共用的 SVG 资源 */
|
||||
const svgDefs = (
|
||||
<defs>
|
||||
<marker id="ont-arrow" markerWidth="9" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
||||
<polygon points="0 0, 9 3.5, 0 7" fill={tokens.textMuted} />
|
||||
</marker>
|
||||
<marker id="ont-arrow-hl" markerWidth="9" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
||||
<polygon points="0 0, 9 3.5, 0 7" fill={tokens.accent} />
|
||||
</marker>
|
||||
<pattern id="ont-dots" width="26" height="26" patternUnits="userSpaceOnUse">
|
||||
<circle cx="13" cy="13" r="0.9" fill={tokens.svgStroke} opacity="0.5" />
|
||||
</pattern>
|
||||
<filter id="ont-soft" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feDropShadow dx="0" dy="1.5" stdDeviation="3.5" floodColor={tokens.accentGlow} floodOpacity="0.25" />
|
||||
</filter>
|
||||
<filter id="ont-strong" x="-50%" y="-50%" width="200%" height="200%">
|
||||
<feDropShadow dx="0" dy="0" stdDeviation="7" floodColor={tokens.accentGlow} floodOpacity="0.55" />
|
||||
</filter>
|
||||
</defs>
|
||||
);
|
||||
|
||||
/* ── explode / instance:以 center 为锚、药签沿椭圆环炸开(坐标同步算,动画只做插值) ── */
|
||||
if (mode !== 'graph' && center) {
|
||||
const cc = center.color;
|
||||
const cx = dims.w / 2, cy = dims.h / 2;
|
||||
const cr = mode === 'instance' ? 50 : 46;
|
||||
const rx = Math.max(170, dims.w / 2 - 74);
|
||||
const ry = Math.max(88, dims.h / 2 - 46);
|
||||
const capacity = ellipseCircumference(rx, ry);
|
||||
/* 药签宽度按环容量自适应:节点多就收窄,保证 11 条实例也能均匀铺开而不叠字。
|
||||
再夹一道容器约束:椭圆左右各留 74px(rx 的 inset),药签半宽必须小于它,
|
||||
否则 12 张分析卡这种大规模会把最左/最右药签切出画布。 */
|
||||
const pw = Math.max(84, Math.min(158, capacity / Math.max(satellites.length, 1) - 14, 132));
|
||||
const ph = 27;
|
||||
const pts = ellipsePoints(satellites.length, rx, ry, cx, cy);
|
||||
return (
|
||||
<svg ref={svgRef} width="100%" height="100%" viewBox={`0 0 ${dims.w} ${dims.h}`}
|
||||
preserveAspectRatio="xMidYMid meet" style={{ display: 'block', userSelect: 'none' }}>
|
||||
{svgDefs}
|
||||
<rect width="100%" height="100%" fill="url(#ont-dots)" onClick={onBackgroundClick} />
|
||||
|
||||
{/* 中心锚到每个药签的辐条:explode=属于,instance=字段 */}
|
||||
{pts.map(([x, y], i) => {
|
||||
const dx = x - cx, dy = y - cy;
|
||||
const d = Math.hypot(dx, dy) || 1;
|
||||
return (
|
||||
<line key={`sp-${satellites[i].id}`}
|
||||
x1={cx + (dx / d) * (cr + 4)} y1={cy + (dy / d) * (cr + 4)}
|
||||
x2={x - (dx / d) * (pw / 2)} y2={y - (dy / d) * (ph / 2)}
|
||||
stroke={cc} strokeWidth={1} opacity={0.28} />
|
||||
);
|
||||
})}
|
||||
|
||||
{/* 中心锚:外圈呼吸环 + 品牌色圆 */}
|
||||
<g transform={`translate(${cx}, ${cy})`}>
|
||||
<circle r={cr + 12} fill="none" stroke={cc} strokeWidth={1.2} strokeDasharray="4 4" opacity={0.5} />
|
||||
<circle r={cr + 5} fill="none" stroke={cc} strokeWidth={1.4} opacity={0.32} filter="url(#ont-strong)" />
|
||||
<circle r={cr} fill={tokens.panelBgAlt} stroke={cc} strokeWidth={2.4} filter="url(#ont-soft)" />
|
||||
<text textAnchor="middle" dy={mode === 'instance' ? -6 : -2} fontSize={mode === 'instance' ? 12 : 13}
|
||||
fontWeight={800} fill={tokens.text}>{center.label}</text>
|
||||
{mode === 'instance'
|
||||
? <text textAnchor="middle" dy={10} fontSize={10} fill={tokens.textSub}>{center.sub ?? ''}</text>
|
||||
: <text textAnchor="middle" dy={15} fontSize={11} fontWeight={700} fill={cc}>{center.count ?? 0} 条实例</text>}
|
||||
{center.badge && (
|
||||
<g transform={`translate(0, ${cr + 24})`}>
|
||||
<rect x={-Math.max(22, center.badge.length * 6.4)} y={-9} width={Math.max(44, center.badge.length * 12.8)}
|
||||
height={18} rx={9} fill={tokens.panelBgAlt} stroke={cc} strokeWidth={0.8} />
|
||||
<text textAnchor="middle" dy={3.5} fontSize={10} fontWeight={700} fill={cc}>{center.badge}</text>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
|
||||
{/* 环上药签:炸开时有 0.2→1 的缩放与错峰延时 */}
|
||||
{satellites.map((st, i) => {
|
||||
const [x, y] = pts[i];
|
||||
const text = st.value ? `${st.label} ${st.value}` : st.label;
|
||||
const max = Math.floor((pw - 16) / 6.4);
|
||||
const shown = text.length > max ? `${text.slice(0, Math.max(1, max - 1))}…` : text;
|
||||
return (
|
||||
<g key={st.id} className="ont-sat" transform={`translate(${x}, ${y})`} style={{ cursor: 'pointer' }}
|
||||
onClick={() => onSatelliteClick?.(st.id)}>
|
||||
{/* 位置在外层 <g>(transform 属性,与动画无关);缩放在内层 <g>(transition,终态恒为 1) */}
|
||||
<g style={{
|
||||
transformBox: 'fill-box', transformOrigin: 'center',
|
||||
transform: satShown ? 'scale(1)' : 'scale(0.2)',
|
||||
opacity: satShown ? 1 : 0,
|
||||
transition: `transform 0.45s cubic-bezier(0.2,0.8,0.25,1) ${i * 42}ms, opacity 0.32s linear ${i * 42}ms`,
|
||||
}}>
|
||||
<title>{text}</title>
|
||||
<rect x={-pw / 2} y={-ph / 2} width={pw} height={ph} rx={13}
|
||||
fill={tokens.panelBgAlt} stroke={cc} strokeWidth={0.9} opacity={0.96} />
|
||||
<text textAnchor="middle" dy={3.5} fontSize={10.5} fontWeight={600} fill={tokens.text}>{shown}</text>
|
||||
{st.badge && (
|
||||
<g transform={`translate(${pw / 2 - 4}, ${-ph / 2 + 2})`}>
|
||||
<circle r={9} fill={tokens.cardBg} stroke={cc} strokeWidth={0.8} />
|
||||
<text textAnchor="middle" dy={3} fontSize={8.5} fontWeight={700} fill={cc}>
|
||||
{st.badge.slice(0, 2)}
|
||||
</text>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<svg ref={svgRef} width="100%" height="100%" viewBox={`0 0 ${dims.w} ${dims.h}`}
|
||||
preserveAspectRatio="xMidYMid meet" style={{ display: 'block', userSelect: 'none' }}>
|
||||
{svgDefs}
|
||||
|
||||
<rect width="100%" height="100%" fill="url(#ont-dots)" onClick={onBackgroundClick} />
|
||||
|
||||
{/* ── 关系边:透明粗线负责命中,细线负责显示 ── */}
|
||||
{edges.map(e => {
|
||||
const s = byId.get(e.source), t = byId.get(e.target);
|
||||
if (!s || !t) return null;
|
||||
const sel = e.id === selectedEdgeId;
|
||||
const hl = sel || active === e.source || active === e.target;
|
||||
const dx = t.x - s.x, dy = t.y - s.y;
|
||||
const d = Math.hypot(dx, dy) || 1;
|
||||
const sx = s.x + (dx / d) * (rOf(s.deg) + 5), sy = s.y + (dy / d) * (rOf(s.deg) + 5);
|
||||
const tx = t.x - (dx / d) * (rOf(t.deg) + 6), ty = t.y - (dy / d) * (rOf(t.deg) + 6);
|
||||
const mx = (sx + tx) / 2, my = (sy + ty) / 2;
|
||||
const label = `${e.label}${sel ? ' ⟶' : ''}`;
|
||||
const w = label.length * 10 + 10;
|
||||
const showLabel = !dense || sel || hl;
|
||||
return (
|
||||
<g key={e.id} style={{ cursor: 'pointer' }} onClick={() => onEdgeClick?.(e.id)}>
|
||||
<line x1={sx} y1={sy} x2={tx} y2={ty} stroke="transparent" strokeWidth={14} />
|
||||
<line x1={sx} y1={sy} x2={tx} y2={ty}
|
||||
stroke={sel ? tokens.accent : hl ? tokens.info : tokens.textMuted}
|
||||
strokeWidth={sel ? 2.4 : hl ? 1.6 : 1}
|
||||
opacity={sel || hl ? 1 : 0.45}
|
||||
markerEnd={hl || sel ? 'url(#ont-arrow-hl)' : 'url(#ont-arrow)'} />
|
||||
{showLabel && (
|
||||
<>
|
||||
<rect x={mx - w / 2} y={my - 8} width={w} height={16} rx={5}
|
||||
fill={sel ? tokens.accentBg : tokens.panelBgAlt}
|
||||
stroke={sel ? tokens.accent : hl ? tokens.info : tokens.border}
|
||||
strokeWidth={sel ? 1.4 : 0.7} />
|
||||
<text x={mx} y={my + 3.5} textAnchor="middle" fontSize={10} fontWeight={sel ? 700 : 500}
|
||||
fill={sel ? tokens.accent : hl ? tokens.info : tokens.textSub}>{label}</text>
|
||||
</>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* ── 对象节点 ── */}
|
||||
{nodes.map(n => {
|
||||
const r = rOf(n.deg);
|
||||
const sel = n.id === selectedNodeId;
|
||||
const hl = hovered === n.id;
|
||||
const dim = !!active && !sel && !hl && !isNeighbor(n.id);
|
||||
const ring = sel ? tokens.accent : hl ? tokens.info : n.color;
|
||||
return (
|
||||
<g key={n.id} transform={`translate(${n.x}, ${n.y})`} opacity={dim ? 0.28 : 1}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onMouseEnter={() => setHovered(n.id)} onMouseLeave={() => setHovered(null)}
|
||||
onClick={() => onNodeClick?.(n.id)} onDoubleClick={() => onNodeDoubleClick?.(n.id)}>
|
||||
{sel && (
|
||||
<circle r={r + 9} fill="none" stroke={tokens.accent} strokeWidth={1.4}
|
||||
strokeDasharray="4 3" opacity={0.75} />
|
||||
)}
|
||||
<circle r={r + 4} fill="none" stroke={ring} strokeWidth={sel ? 2 : 1}
|
||||
opacity={sel ? 0.85 : hl ? 0.5 : 0.16}
|
||||
filter={sel || hl ? 'url(#ont-strong)' : undefined} />
|
||||
<circle r={r} fill={tokens.panelBgAlt} stroke={ring}
|
||||
strokeWidth={sel ? 2.4 : hl ? 1.8 : 1.1} filter="url(#ont-soft)" />
|
||||
{/* 对象自身的品牌色压在底部,区分「销售订单 / 工单 / 采购单」 */}
|
||||
<path d={`M ${-r * 0.45} ${r - 2.5} A ${r} ${r} 0 0 0 ${r * 0.45} ${r - 2.5}`}
|
||||
fill="none" stroke={n.color} strokeWidth={2.4} strokeLinecap="round" opacity={dim ? 0.3 : 0.9} />
|
||||
<text textAnchor="middle" dy={-3} fontSize={r > 30 ? 12 : 11} fontWeight={700}
|
||||
fill={sel || hl ? ring : tokens.text}>{shortName(n.label)}</text>
|
||||
<text textAnchor="middle" dy={12} fontSize={10.5} fontWeight={700}
|
||||
fill={sel || hl ? ring : n.color}>{n.count}</text>
|
||||
{!dense && (
|
||||
<text textAnchor="middle" dy={r + 17} fontSize={10} fill={tokens.textMuted}>
|
||||
{shortName(n.label)} · {n.count} 实例
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,887 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { AlertTriangle, Boxes, ChevronRight, CircleSlash2, FlaskConical, Lock, Network, Search, ShieldAlert, X, Zap } from 'lucide-react';
|
||||
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
|
||||
import {
|
||||
actions, instanceFields, objectById, objects, relations, rules,
|
||||
ONTOLOGY_AS_OF, ONTOLOGY_SCOPE_NOTE,
|
||||
type OntAction, type OntInstance, type OntObject, type OntRelation, type OntRule, type Severity, type Tone,
|
||||
} from '../../data/ontologyOee';
|
||||
import OntologyGraph, { type SatNode } from './OntologyGraph';
|
||||
import StageHint from '../common/StageHint';
|
||||
|
||||
/**
|
||||
* OEE 业务本体总览:建议书 3.6 的 9 类对象(设备 / 产线拓扑 / 批次 / 事件 / 状态段 /
|
||||
* 损失 / 绩效 / 口径 / 改善)+共同分析本体 4 类(分析问题 / 因子定义 / 改善对策 / 成本参数),
|
||||
* 抽象成「对象—关系—规则—动作」四层——
|
||||
* 对象=业务实体、属性=实体字段、实例=L3 服务层现算出的真实行、关系=实体间真实连接键、
|
||||
* 规则=口径与 DQ 里写明的阈值、动作=规则命中后真正的处置。
|
||||
* 结构在上方图谱里看,清单在下方四栏里选,点任意条目在右侧下钻到属性与真实实例。
|
||||
*
|
||||
* 图谱是一条「总览 → 裂变 → 下钻」的演示动线(现场讲解用):
|
||||
* 单击对象 聚焦联动:高亮该对象与链路,下方四栏同步高亮/滚动到相关条目(关系按 from/to、规则动作按 tables)
|
||||
* 双击对象 裂变:该对象缩成中心锚,本对象实例作为药签沿椭圆环炸开
|
||||
* 单击药签 下钻:环上摊开该实例的字段(列名 = 值)
|
||||
* 返回:点面包屑任一级、点画布空白、或 ESC(非全屏时逐级退,全屏时 ESC 退出整个舞台)。
|
||||
*
|
||||
* ★ 所有数字(实例数、关系基数、规则命中数)都在 src/data/ontologyOee.ts 里从 L3 服务层现算,
|
||||
* 页面不写死任何统计值,也不自己再跑一遍链路(断言②「四处读数一致」)。
|
||||
* 跑不出结果的规则一律 blocked+gap 标灰:线体合成待 W2、改善任务待 W3-B、实时直采未接入,
|
||||
* **不造实例充数**。文案与本体数据层同源,全部是中文业务术语,因此不走 i18n 词典。
|
||||
*/
|
||||
|
||||
type Sel =
|
||||
| { kind: 'object'; id: string }
|
||||
| { kind: 'relation'; id: string }
|
||||
| { kind: 'rule'; id: string }
|
||||
| { kind: 'action'; id: string };
|
||||
|
||||
/** 图谱画布层级:总览 → 某表裂变 → 某实例下钻 */
|
||||
type View =
|
||||
| { mode: 'graph' }
|
||||
| { mode: 'explode'; table: string }
|
||||
| { mode: 'instance'; table: string; inst: string };
|
||||
|
||||
const toneColor = (tk: ThemeTokens, t: Tone) =>
|
||||
t === 'success' ? { c: tk.success, bg: tk.successBg }
|
||||
: t === 'warning' ? { c: tk.warning, bg: tk.warningBg }
|
||||
: t === 'danger' ? { c: tk.danger, bg: tk.dangerBg }
|
||||
: { c: tk.info, bg: tk.infoBg };
|
||||
|
||||
const sevTone = (s: Severity): Tone => (s === 'error' ? 'danger' : s === 'warning' ? 'warning' : 'info');
|
||||
|
||||
const ACTION_TYPE: Record<OntAction['type'], { label: string; tone: Tone }> = {
|
||||
query: { label: '查询', tone: 'info' },
|
||||
alert: { label: '告警', tone: 'warning' },
|
||||
report: { label: '报表', tone: 'success' },
|
||||
workflow: { label: '流程', tone: 'danger' },
|
||||
};
|
||||
|
||||
/* 卡片底:选中时压 accent 边框,未选中只靠边框与留白分组,不加彩色左边条 */
|
||||
const cardBase = (tk: ThemeTokens, on: boolean): React.CSSProperties => ({
|
||||
width: '100%', textAlign: 'left', cursor: 'pointer', marginBottom: 7,
|
||||
padding: '8px 10px', borderRadius: 9,
|
||||
background: on ? tk.accentBg : tk.panelBgAlt,
|
||||
border: `1px solid ${on ? tk.accent : tk.border}`,
|
||||
transition: 'background .15s ease, border-color .15s ease',
|
||||
});
|
||||
|
||||
/* 面包屑按钮:当前层加粗压色,其余弱化 */
|
||||
const crumbBtn = (tk: ThemeTokens, active: boolean): React.CSSProperties => ({
|
||||
background: 'none', border: 'none', cursor: 'pointer', padding: '1px 4px', borderRadius: 6,
|
||||
fontSize: 11.5, fontWeight: active ? 800 : 600,
|
||||
color: active ? tk.accent : tk.textSub,
|
||||
});
|
||||
|
||||
const Pill = ({ tone, children }: { tone: Tone; children: React.ReactNode }) => {
|
||||
const { tokens } = useTheme();
|
||||
const c = toneColor(tokens, tone);
|
||||
return (
|
||||
<span style={{
|
||||
fontSize: 10, fontWeight: 700, padding: '1px 6px', borderRadius: 999, whiteSpace: 'nowrap',
|
||||
color: c.c, background: c.bg, border: `1px solid ${c.c}44`,
|
||||
}}>{children}</span>
|
||||
);
|
||||
};
|
||||
|
||||
export type OntScope = 'all' | 'feature';
|
||||
|
||||
interface Props {
|
||||
onExit: () => void;
|
||||
/** 视图范围:all=全部 13 类对象(OEE 业务本体 + 共同分析本体);feature=只纳入特征建模相关对象 */
|
||||
scope?: OntScope;
|
||||
/** 从外部跳来时:指定要聚焦的对象/实例 */
|
||||
focus?: { objKey: string; instanceId?: string } | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 各范围纳入的对象 id。
|
||||
* ★ 这里填的是**对象 id**(equipment/event/…),不是物理表名——
|
||||
* ontologyOee 的 rules[].tables / actions[].tables 也按对象 id 填,
|
||||
* 两边键空间必须一致,否则聚焦联动与范围过滤会静默失效(空数组恒真)。
|
||||
* feature 范围取「设备 / 事件 / 状态段 / 损失」四类:特征建模的输入正是这四类。
|
||||
*/
|
||||
const SCOPE_TABLES: Record<OntScope, string[] | null> = {
|
||||
all: null,
|
||||
feature: ['equipment', 'event', 'stateSegment', 'loss'],
|
||||
};
|
||||
|
||||
export default function OntologyView({ onExit, scope = 'all', focus }: Props) {
|
||||
const { tokens } = useTheme();
|
||||
/* 初值取对象清单首项,不写死 id:换本体种子时不会指向一个不存在的对象 */
|
||||
const [sel, setSel] = useState<Sel>({ kind: 'object', id: objects[0].id });
|
||||
const [query, setQuery] = useState('');
|
||||
const [view, setView] = useState<View>({ mode: 'graph' });
|
||||
|
||||
/* ── 范围过滤:feature 只保留特征建模相关表,四栏与图谱都随之收敛 ── */
|
||||
const scopeTables = SCOPE_TABLES[scope];
|
||||
const scObjects = useMemo(
|
||||
() => (scopeTables ? objects.filter(o => scopeTables.includes(o.id)) : objects), [scopeTables],
|
||||
);
|
||||
const scRelations = useMemo(
|
||||
() => (scopeTables ? relations.filter(r => scopeTables.includes(r.from) && scopeTables.includes(r.to)) : relations),
|
||||
[scopeTables],
|
||||
);
|
||||
const scRules = useMemo(
|
||||
() => (scopeTables ? rules.filter(r => r.tables.some(t => scopeTables.includes(t))) : rules), [scopeTables],
|
||||
);
|
||||
const scActions = useMemo(
|
||||
() => (scopeTables ? actions.filter(a => a.tables.some(t => scopeTables.includes(t))) : actions), [scopeTables],
|
||||
);
|
||||
|
||||
/* ── 外部跳入:知识库点特征码 → 聚焦对应对象/实例 ─────────────────────── */
|
||||
useEffect(() => {
|
||||
if (!focus) return;
|
||||
const exists = scObjects.some(o => o.id === focus.objKey);
|
||||
if (!exists) return;
|
||||
setSel({ kind: 'object', id: focus.objKey });
|
||||
setQuery('');
|
||||
if (focus.instanceId) {
|
||||
setView({ mode: 'instance', table: focus.objKey, inst: focus.instanceId });
|
||||
} else {
|
||||
setView({ mode: 'graph' });
|
||||
}
|
||||
}, [focus, scObjects]);
|
||||
|
||||
const nodes = useMemo(
|
||||
() => scObjects.map(o => ({ id: o.id, label: o.short, count: o.instances().length, color: o.color })),
|
||||
[scObjects],
|
||||
);
|
||||
const edges = useMemo(
|
||||
() => scRelations.map(r => ({ id: r.id, source: r.from, target: r.to, label: r.name })),
|
||||
[scRelations],
|
||||
);
|
||||
const hitTotal = useMemo(() => scRules.reduce((a, r) => a + (r.blocked ? 0 : r.hits().n), 0), [scRules]);
|
||||
|
||||
/* ── 层级动线:进/出各一级,全部由 view 单一状态驱动 ───────────────── */
|
||||
const enterExplode = (table: string) => { setSel({ kind: 'object', id: table }); setView({ mode: 'explode', table }); };
|
||||
const enterInstance = (table: string, inst: string) => { setView({ mode: 'instance', table, inst }); };
|
||||
const back = () => setView(v => (v.mode === 'instance' ? { mode: 'explode', table: v.table } : { mode: 'graph' }));
|
||||
|
||||
/* 非全屏时 ESC 逐级返回;capture + stopImmediatePropagation 抢在舞台级 ESC 之前 */
|
||||
useEffect(() => {
|
||||
if (view.mode === 'graph') return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key !== 'Escape') return;
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
back();
|
||||
};
|
||||
window.addEventListener('keydown', onKey, true);
|
||||
return () => window.removeEventListener('keydown', onKey, true);
|
||||
}, [view.mode]);
|
||||
|
||||
const viewTable = view.mode === 'graph' ? null : view.table;
|
||||
const centerObj = viewTable ? objectById(viewTable) : undefined;
|
||||
/** explode 的环=该表实例;instance 的环=该实例的字段(列名 = 值) */
|
||||
const satellites: SatNode[] = useMemo(() => {
|
||||
if (view.mode === 'explode' && centerObj) {
|
||||
return centerObj.instances().map(it => ({ id: it.id, label: it.title, value: it.value, badge: it.badge }));
|
||||
}
|
||||
if (view.mode === 'instance') {
|
||||
return instanceFields(view.table, view.inst).map(f => ({ id: f.name, label: f.name, value: f.value }));
|
||||
}
|
||||
return [];
|
||||
}, [view, centerObj]);
|
||||
|
||||
const focusInst = useMemo(() => {
|
||||
if (view.mode !== 'instance') return null;
|
||||
const obj = objectById(view.table);
|
||||
const inst = obj?.instances().find(i => i.id === view.inst);
|
||||
return obj && inst ? { obj, inst, fields: instanceFields(view.table, view.inst) } : null;
|
||||
}, [view]);
|
||||
|
||||
const q = query.trim().toLowerCase();
|
||||
const match = (...fields: (string | undefined)[]) =>
|
||||
!q || fields.some(f => (f ?? '').toLowerCase().includes(q));
|
||||
|
||||
const visObjects = useMemo(() => scObjects.filter(o => match(o.name, o.en, o.desc, o.source)), [q, scObjects]);
|
||||
const visRelations = useMemo(() => scRelations.filter(r => match(r.name, r.key, r.desc)), [q, scRelations]);
|
||||
const visRules = useMemo(() => scRules.filter(r => match(r.name, r.expr, r.desc, r.on)), [q, scRules]);
|
||||
const visActions = useMemo(() => scActions.filter(a => match(a.name, a.en, a.desc, a.trigger, a.object)), [q, scActions]);
|
||||
|
||||
/* ── 聚焦联动:某类对象被选中/裂变时,四栏里与之相关的条目一并点亮 ──────── */
|
||||
const linkedTo = (tables: string[]) => !!viewTable && tables.includes(viewTable);
|
||||
const relLinked = (r: OntRelation) => !!viewTable && (r.from === viewTable || r.to === viewTable);
|
||||
const isFocusTable = (id: string) => viewTable === id;
|
||||
|
||||
/* 选中的表卡片滚进可视区,否则联动高亮点在折叠线以下等于没点 */
|
||||
const objRefs = useRef<Record<string, HTMLButtonElement | null>>({});
|
||||
useEffect(() => {
|
||||
if (!viewTable) return;
|
||||
objRefs.current[viewTable]?.scrollIntoView({ block: 'nearest', behavior: 'smooth' });
|
||||
}, [viewTable]);
|
||||
|
||||
const detail = useMemo(() => {
|
||||
if (sel.kind === 'object') return objectById(sel.id) as OntObject | undefined;
|
||||
if (sel.kind === 'relation') return scRelations.find(r => r.id === sel.id);
|
||||
if (sel.kind === 'rule') return scRules.find(r => r.id === sel.id);
|
||||
return scActions.find(a => a.id === sel.id);
|
||||
}, [sel, scRelations, scRules, scActions]);
|
||||
|
||||
/** 当前选中对象的实例列表(只在选中对象时计算,避免每帧重建 63/70 行) */
|
||||
const instances = useMemo<OntInstance[]>(
|
||||
() => (sel.kind === 'object' ? (detail as OntObject | undefined)?.instances() ?? [] : []),
|
||||
[sel, detail],
|
||||
);
|
||||
|
||||
const selectedEdgeId = sel.kind === 'relation' ? sel.id : null;
|
||||
const selectedNodeId = sel.kind === 'object' ? sel.id
|
||||
: sel.kind === 'relation' ? (detail as OntRelation | undefined)?.from ?? null
|
||||
: null;
|
||||
|
||||
const colHead = (icon: React.ReactNode, label: string, n: number, total: number) => (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 6, flex: '0 0 auto',
|
||||
padding: '0 2px 7px', marginBottom: 8, borderBottom: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<span style={{ display: 'flex', color: tokens.accent }}>{icon}</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 800, color: tokens.text, letterSpacing: '0.02em' }}>{label}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 11, color: q ? tokens.warning : tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>
|
||||
{n}/{total}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
const colScroll: React.CSSProperties = { flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', paddingRight: 4 };
|
||||
const colBox: React.CSSProperties = {
|
||||
flex: '1 1 0', minWidth: 0, display: 'flex', flexDirection: 'column',
|
||||
padding: '0 10px 8px', borderRadius: 12, background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ flex: 1, minHeight: 0, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
{/* ── 标题栏:窄窗口时换行而不是把退出按钮挤出可视区(容器 overflow:hidden 会裁掉溢出) ── */}
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 10, flex: '0 0 auto', flexWrap: 'wrap',
|
||||
padding: '2px 2px 0',
|
||||
}}>
|
||||
{scope === 'feature'
|
||||
? <FlaskConical size={19} style={{ color: tokens.accent, flexShrink: 0 }} />
|
||||
: <Boxes size={19} style={{ color: tokens.accent, flexShrink: 0 }} />}
|
||||
<span style={{ fontSize: 15.5, fontWeight: 800, color: tokens.text, letterSpacing: '0.03em' }}>
|
||||
{scope === 'feature' ? '工艺建模' : '业务本体'}
|
||||
</span>
|
||||
<span style={{ fontSize: 11.5, color: tokens.textMuted, flexShrink: 0 }} title={ONTOLOGY_SCOPE_NOTE}>
|
||||
快照日 {ONTOLOGY_AS_OF} · {scope === 'feature' ? '特征对象' : '对象即业务实体'} {scObjects.length} 类对象
|
||||
</span>
|
||||
<span style={{ flex: '1 1 24px' }} />
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
{[
|
||||
{ l: scope === 'feature' ? '特征对象' : '对象', v: scObjects.length }, { l: '关系', v: scRelations.length },
|
||||
{ l: '规则', v: scRules.length }, { l: '动作', v: scActions.length },
|
||||
{ l: '当前命中', v: hitTotal, hot: true },
|
||||
].map(s => (
|
||||
<span key={s.l} style={{
|
||||
fontSize: 11, fontWeight: 700, padding: '2px 9px', borderRadius: 999, whiteSpace: 'nowrap',
|
||||
color: s.hot ? tokens.warning : tokens.textSub,
|
||||
background: s.hot ? tokens.warningBg : tokens.accentBg,
|
||||
border: `1px solid ${s.hot ? `${tokens.warning}55` : tokens.border}`,
|
||||
fontVariantNumeric: 'tabular-nums',
|
||||
}}>{s.l} {s.v}</span>
|
||||
))}
|
||||
</div>
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 6, flex: '1 1 190px', minWidth: 150, maxWidth: 260,
|
||||
padding: '3px 9px', borderRadius: 999, background: tokens.panelBgAlt, border: `1px solid ${tokens.borderAccent}`,
|
||||
}}>
|
||||
<Search size={12} style={{ color: tokens.textMuted, flexShrink: 0 }} />
|
||||
<input
|
||||
value={query}
|
||||
onChange={e => setQuery(e.target.value)}
|
||||
placeholder="搜索对象 / 关系 / 规则 / 动作"
|
||||
style={{
|
||||
flex: 1, minWidth: 0, background: 'transparent', border: 'none', outline: 'none',
|
||||
color: tokens.text, fontSize: 12,
|
||||
}}
|
||||
/>
|
||||
{query && (
|
||||
<button onClick={() => setQuery('')} title="清空搜索" style={{ background: 'none', border: 'none', cursor: 'pointer', color: tokens.textMuted, display: 'flex' }}>
|
||||
<X size={12} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={onExit}
|
||||
title={scope === 'feature' ? '退出工艺建模 (ESC)' : '退出业务本体 (ESC)'}
|
||||
style={{
|
||||
flexShrink: 0, display: 'flex', alignItems: 'center', gap: 5, cursor: 'pointer',
|
||||
padding: '4px 11px', borderRadius: 8, fontSize: 11.5, fontWeight: 700,
|
||||
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
|
||||
}}
|
||||
>
|
||||
<X size={13} /> 退出 ESC
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* ── SCHEMA 徽标行:一眼看清每类对象有多少实例 ── */}
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', flex: '0 0 auto' }}>
|
||||
{scObjects.map(o => {
|
||||
const on = sel.kind === 'object' && sel.id === o.id;
|
||||
const n = o.instances().length;
|
||||
return (
|
||||
<button
|
||||
key={o.id}
|
||||
onClick={() => setSel({ kind: 'object', id: o.id })}
|
||||
title={o.desc}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 6, cursor: 'pointer', whiteSpace: 'nowrap',
|
||||
padding: '3px 10px', borderRadius: 999, fontSize: 11.5, fontWeight: on ? 800 : 600,
|
||||
color: on ? tokens.text : tokens.textSub,
|
||||
background: on ? tokens.accentBg : tokens.kpiCardBg,
|
||||
border: `1px solid ${on ? o.color : tokens.border}`,
|
||||
}}
|
||||
>
|
||||
<span style={{ width: 7, height: 7, borderRadius: 99, background: o.color, boxShadow: `0 0 7px ${o.color}88` }} />
|
||||
{o.name}
|
||||
<span style={{ color: o.color, fontVariantNumeric: 'tabular-nums' }}>{n}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* ── 上:图谱 + 详情面板 ── */}
|
||||
<div style={{ flex: '1.7 1 0', minHeight: 300, display: 'flex', gap: 10 }}>
|
||||
<div style={{
|
||||
flex: '1 1 0', minWidth: 0, display: 'flex', flexDirection: 'column',
|
||||
borderRadius: 12, overflow: 'hidden', background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'center', gap: 8, flex: '0 0 auto', flexWrap: 'wrap',
|
||||
padding: '7px 12px', borderBottom: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<Network size={13} style={{ color: tokens.accent }} />
|
||||
{view.mode === 'graph' ? (
|
||||
<>
|
||||
<span style={{ fontSize: 12.5, fontWeight: 800, color: tokens.text }}>{scope === 'feature' ? '特征图谱' : '本体图谱'}</span>
|
||||
<span style={{ fontSize: 11, color: tokens.textMuted }}>节点={scope === 'feature' ? '特征对象' : '对象'}(圈内数字为实例数)· 连线=关系</span>
|
||||
</>
|
||||
) : (
|
||||
<span style={{ display: 'flex', alignItems: 'center', gap: 3, fontSize: 11.5, minWidth: 0, flexWrap: 'wrap' }}>
|
||||
<button onClick={() => setView({ mode: 'graph' })} className="ghost-btn"
|
||||
style={crumbBtn(tokens, false)}>全部表</button>
|
||||
<ChevronRight size={11} style={{ color: tokens.textMuted, flexShrink: 0 }} />
|
||||
<button onClick={() => setView({ mode: 'explode', table: view.mode === 'instance' ? view.table : viewTable! })}
|
||||
className="ghost-btn" style={crumbBtn(tokens, view.mode === 'explode')}>
|
||||
{centerObj?.name ?? viewTable}
|
||||
</button>
|
||||
{view.mode === 'instance' && (
|
||||
<>
|
||||
<ChevronRight size={11} style={{ color: tokens.textMuted, flexShrink: 0 }} />
|
||||
<button className="ghost-btn" style={crumbBtn(tokens, true)}>{view.inst}</button>
|
||||
</>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
<span style={{ flex: 1 }} />
|
||||
{/* 现场讲解用的动词提示:观众不用听说也知道下一步点哪 */}
|
||||
<span style={{ fontSize: 10.5, color: tokens.accent, fontWeight: 600 }}>
|
||||
{view.mode === 'graph' ? '单击聚焦 · 双击展开实例' : view.mode === 'explode' ? '点实例标签看字段 · 空白/ESC 返回' : '空白/ESC 返回上一层'}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ flex: 1, minHeight: 0, position: 'relative' }}>
|
||||
<StageHint
|
||||
stageKey={scope === 'feature' ? 'feature' : 'ontology'}
|
||||
steps={[
|
||||
'单击对象 → 聚焦联动下方四栏',
|
||||
'双击对象 → 裂变成一圈实例标签',
|
||||
'点实例标签 → 下钻查看该实例字段',
|
||||
'点空白 / ESC → 逐级返回',
|
||||
]}
|
||||
/>
|
||||
<OntologyGraph
|
||||
nodes={nodes} edges={edges}
|
||||
selectedNodeId={selectedNodeId} selectedEdgeId={selectedEdgeId}
|
||||
onNodeClick={id => setSel({ kind: 'object', id })}
|
||||
onEdgeClick={id => setSel({ kind: 'relation', id })}
|
||||
onNodeDoubleClick={enterExplode}
|
||||
mode={view.mode}
|
||||
center={view.mode === 'graph' || !centerObj ? null : {
|
||||
label: view.mode === 'explode' ? centerObj.short : view.inst,
|
||||
sub: view.mode === 'instance' ? focusInst?.inst.sub : undefined,
|
||||
badge: view.mode === 'explode' ? undefined : focusInst?.inst.badge,
|
||||
color: centerObj.color,
|
||||
count: view.mode === 'explode' ? satellites.length : undefined,
|
||||
}}
|
||||
satellites={satellites}
|
||||
onSatelliteClick={id => { if (view.mode === 'explode') enterInstance(view.table, id); }}
|
||||
onBackgroundClick={back}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 详情面板:放宽占比与上限,属性标签与实例行不再被挤成两三行 */}
|
||||
<div style={{
|
||||
flex: '0 0 clamp(360px, 34%, 640px)', minWidth: 0, display: 'flex', flexDirection: 'column',
|
||||
borderRadius: 12, overflow: 'hidden', background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<DetailPanel
|
||||
sel={sel} detail={detail} instances={instances} focusInst={focusInst}
|
||||
onPickObject={id => setSel({ kind: 'object', id })}
|
||||
onBack={back}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── 下:对象 / 关系 / 规则 / 动作 四栏清单 ── */}
|
||||
<div style={{ flex: '1 1 0', minHeight: 168, display: 'flex', gap: 10 }}>
|
||||
<div style={colBox}>
|
||||
{colHead(scope === 'feature' ? <FlaskConical size={13} /> : <Boxes size={13} />,
|
||||
scope === 'feature' ? '特征对象 Feature' : '对象 Object', visObjects.length, scObjects.length)}
|
||||
<div style={colScroll}>
|
||||
{visObjects.map(o => {
|
||||
const on = sel.kind === 'object' && sel.id === o.id;
|
||||
const focus = isFocusTable(o.id);
|
||||
return (
|
||||
<button
|
||||
key={o.id}
|
||||
ref={el => { objRefs.current[o.id] = el; }}
|
||||
onClick={() => (view.mode === 'graph' ? setSel({ kind: 'object', id: o.id }) : enterExplode(o.id))}
|
||||
style={{
|
||||
...cardBase(tokens, on),
|
||||
/* 聚焦标识用 inset 阴影画左侧色条:cardBase 用的是 border 简写,
|
||||
再叠 borderLeft 长写会触发 React「简写+长写混用」告警,改用 boxShadow 更稳 */
|
||||
boxShadow: focus ? `inset 3px 0 0 ${o.color}, inset 0 0 0 1px ${o.color}55` : undefined,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ width: 6, height: 6, borderRadius: 99, background: o.color, flexShrink: 0 }} />
|
||||
<span style={{ fontSize: 12.5, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{o.name}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 11, fontWeight: 800, color: o.color, fontVariantNumeric: 'tabular-nums' }}>{o.instances().length}</span>
|
||||
</div>
|
||||
<div style={{ marginTop: 3, fontSize: 10.5, color: tokens.textMuted, fontFamily: 'ui-monospace, SFMono-Regular, monospace' }}>
|
||||
{o.en} · {o.attrs.length} 属性
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{visObjects.length === 0 && <Empty tk={tokens} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={colBox}>
|
||||
{colHead(<Network size={13} />, '关系 Relation', visRelations.length, scRelations.length)}
|
||||
<div style={colScroll}>
|
||||
{visRelations.map(r => {
|
||||
const on = sel.kind === 'relation' && sel.id === r.id;
|
||||
const focus = relLinked(r);
|
||||
return (
|
||||
<button key={r.id} onClick={() => setSel({ kind: 'relation', id: r.id })}
|
||||
style={{ ...cardBase(tokens, on), boxShadow: focus ? `inset 3px 0 0 ${tokens.info}` : undefined }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
||||
<span style={{ fontSize: 12, fontWeight: 700, color: tokens.text }}>{r.name}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<Pill tone="info">{r.cardinality}</Pill>
|
||||
</div>
|
||||
<div style={{ marginTop: 3, display: 'flex', alignItems: 'center', gap: 4, fontSize: 10.5, color: tokens.textSub, overflow: 'hidden', whiteSpace: 'nowrap' }}>
|
||||
<span style={{ color: objectById(r.from)?.color, fontWeight: 700 }}>{objectById(r.from)?.name}</span>
|
||||
<span style={{ color: tokens.textMuted }}>→</span>
|
||||
<span style={{ color: objectById(r.to)?.color, fontWeight: 700 }}>{objectById(r.to)?.name}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>{r.count()}</span>
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{visRelations.length === 0 && <Empty tk={tokens} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={colBox}>
|
||||
{colHead(<ShieldAlert size={13} />, '规则 Rule', visRules.length, scRules.length)}
|
||||
<div style={colScroll}>
|
||||
{visRules.map(r => {
|
||||
const on = sel.kind === 'rule' && sel.id === r.id;
|
||||
const h = r.hits();
|
||||
const focus = linkedTo(r.tables);
|
||||
return (
|
||||
<button
|
||||
key={r.id} onClick={() => setSel({ kind: 'rule', id: r.id })}
|
||||
style={{
|
||||
...cardBase(tokens, on), opacity: r.blocked ? 0.62 : 1,
|
||||
boxShadow: focus ? `inset 3px 0 0 ${toneColor(tokens, sevTone(r.severity)).c}` : undefined,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
||||
{r.blocked
|
||||
? <CircleSlash2 size={11} style={{ color: tokens.textMuted, flexShrink: 0 }} />
|
||||
: <AlertTriangle size={11} style={{ color: toneColor(tokens, sevTone(r.severity)).c, flexShrink: 0 }} />}
|
||||
<span style={{ fontSize: 12.5, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{r.name}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
{r.blocked
|
||||
? <Pill tone="warning">数据缺口</Pill>
|
||||
: <span style={{ fontSize: 11.5, fontWeight: 800, color: h.n ? toneColor(tokens, sevTone(r.severity)).c : tokens.success, fontVariantNumeric: 'tabular-nums' }}>{h.n}</span>}
|
||||
</div>
|
||||
<div style={{ marginTop: 3, fontSize: 10.5, color: tokens.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{r.on}{!r.blocked && ` · ${h.unit}`}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{visRules.length === 0 && <Empty tk={tokens} />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={colBox}>
|
||||
{colHead(<Zap size={13} />, '动作 Action', visActions.length, scActions.length)}
|
||||
<div style={colScroll}>
|
||||
{visActions.map(a => {
|
||||
const on = sel.kind === 'action' && sel.id === a.id;
|
||||
const n = a.targets?.().length ?? 0;
|
||||
const focus = linkedTo(a.tables);
|
||||
return (
|
||||
<button key={a.id} onClick={() => setSel({ kind: 'action', id: a.id })}
|
||||
style={{ ...cardBase(tokens, on), boxShadow: focus ? `inset 3px 0 0 ${tokens.accent}` : undefined }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
||||
<span style={{ fontSize: 12.5, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{a.name}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<Pill tone={ACTION_TYPE[a.type].tone}>{ACTION_TYPE[a.type].label}</Pill>
|
||||
{!a.targets && <Pill tone="warning">不可执行</Pill>}
|
||||
</div>
|
||||
<div style={{ marginTop: 3, display: 'flex', alignItems: 'center', gap: 5, fontSize: 10.5, color: tokens.textMuted, overflow: 'hidden', whiteSpace: 'nowrap' }}>
|
||||
<span style={{ fontFamily: 'ui-monospace, SFMono-Regular, monospace' }}>{a.en}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span>{a.object}</span>
|
||||
{a.targets && <span style={{ color: n ? tokens.accent : tokens.textMuted, fontWeight: 700 }}>· {n}</span>}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
{visActions.length === 0 && <Empty tk={tokens} />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── 页脚:范围与缺口常驻披露(不藏 tooltip)──
|
||||
主数据全量 vs 事实层只取锚点三日,三处未落地一律 blocked+gap 标灰、不造实例充数。
|
||||
文案从 ontologyOee 的 ONTOLOGY_SCOPE_NOTE 取,数字现算,页面不另写一份。 */}
|
||||
<div style={{
|
||||
flex: '0 0 auto', padding: '6px 10px', borderRadius: 10,
|
||||
fontSize: 10.5, lineHeight: 1.55, color: tokens.textMuted,
|
||||
background: tokens.panelBgAlt, border: `1px solid ${tokens.borderSub}`,
|
||||
}}>
|
||||
{ONTOLOGY_SCOPE_NOTE}
|
||||
<span style={{ marginLeft: 6 }}>
|
||||
数据源:<span style={{ fontFamily: 'ui-monospace, SFMono-Regular, monospace' }}>src/data/ontologyOee.ts</span>
|
||||
(数值唯一来源为 L3 lib/oeeService)· 校验:
|
||||
<span style={{ fontFamily: 'ui-monospace, SFMono-Regular, monospace' }}>scripts/verify-oee-ontology.ts</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const Empty = ({ tk }: { tk: ThemeTokens }) => (
|
||||
<div style={{ padding: '22px 0', textAlign: 'center', fontSize: 12, color: tk.textMuted }}>无匹配条目</div>
|
||||
);
|
||||
|
||||
/* ── 右侧详情面板 ─────────────────────────────────────────────────────── */
|
||||
|
||||
function DetailPanel({
|
||||
sel, detail, instances, focusInst, onPickObject, onBack,
|
||||
}: {
|
||||
sel: Sel;
|
||||
detail: OntObject | OntRelation | OntRule | OntAction | undefined;
|
||||
instances: OntInstance[];
|
||||
/** 图谱下钻到某条实例时的上下文:优先展示该实例的字段 */
|
||||
focusInst: { obj: OntObject; inst: OntInstance; fields: { name: string; value: string }[] } | null;
|
||||
onPickObject: (id: string) => void;
|
||||
onBack: () => void;
|
||||
}) {
|
||||
const { tokens } = useTheme();
|
||||
|
||||
/* 原「知识引用」区块已移除:它依赖品质知识库(data/knowledge + kbLinks + ROLE_COLOR),
|
||||
与 OEE 本体无关,且会把整套 QAP 数据拖进包。OEE 的知识库页在 W3-C 另建。 */
|
||||
|
||||
const label: React.CSSProperties = { fontSize: 10.5, fontWeight: 700, color: tokens.textMuted, letterSpacing: '0.06em' };
|
||||
const kv: React.CSSProperties = { display: 'flex', flexDirection: 'column', gap: 3, marginBottom: 9 };
|
||||
|
||||
const head = (title: string, en: string | undefined, tone: Tone | null, tag: string) => (
|
||||
<div style={{ padding: '10px 12px 9px', borderBottom: `1px solid ${tokens.border}`, flex: '0 0 auto' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
|
||||
<span style={{ fontSize: 10.5, fontWeight: 800, color: tokens.accent, padding: '1px 7px', borderRadius: 999, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}` }}>{tag}</span>
|
||||
<span style={{ fontSize: 14.5, fontWeight: 800, color: tokens.text, letterSpacing: '0.02em', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{title}</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
{tone && <Pill tone={tone}>{tone === 'danger' ? '硬约束' : tone === 'warning' ? '预警' : '提示'}</Pill>}
|
||||
</div>
|
||||
{en && <div style={{ marginTop: 4, fontSize: 10.5, color: tokens.textMuted, fontFamily: 'ui-monospace, SFMono-Regular, monospace' }}>{en}</div>}
|
||||
</div>
|
||||
);
|
||||
|
||||
const body: React.CSSProperties = { flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', padding: '10px 12px' };
|
||||
|
||||
/* ── 实例:图谱下钻到某条真实单据,右栏摊开它的字段(列名 = 值) ── */
|
||||
if (focusInst) {
|
||||
const { obj, inst, fields } = focusInst;
|
||||
return (
|
||||
<>
|
||||
{head(inst.title, `${obj.name} · ${obj.en}`, null, '实例')}
|
||||
<div style={body}>
|
||||
<button
|
||||
onClick={onBack} className="ghost-btn"
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 5, marginBottom: 9, cursor: 'pointer',
|
||||
padding: '3px 9px', borderRadius: 8, fontSize: 11.5, fontWeight: 700,
|
||||
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
|
||||
}}
|
||||
>← 返回 {obj.short}</button>
|
||||
{inst.sub && (
|
||||
<div style={{ ...kv, marginBottom: 8 }}>
|
||||
<span style={label}>概要</span>
|
||||
<span style={{ fontSize: 12, color: tokens.textSub }}>{inst.sub}</span>
|
||||
</div>
|
||||
)}
|
||||
{inst.meta && (
|
||||
<div style={{ ...kv, marginBottom: 8 }}>
|
||||
<span style={label}>上下文</span>
|
||||
<span style={{ fontSize: 11.5, color: tokens.textMuted, lineHeight: 1.6 }}>{inst.meta}</span>
|
||||
</div>
|
||||
)}
|
||||
<div style={kv}>
|
||||
<span style={label}>字段 {fields.length} 项(列名 = 值)</span>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
{fields.map(f => (
|
||||
<div key={f.name} style={{
|
||||
display: 'flex', alignItems: 'baseline', gap: 8,
|
||||
padding: '4px 8px', borderRadius: 7, background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<span style={{
|
||||
fontSize: 10.5, fontWeight: 700, color: tokens.textMuted, flexShrink: 0,
|
||||
fontFamily: 'ui-monospace, SFMono-Regular, monospace', minWidth: 96,
|
||||
}}>{f.name}</span>
|
||||
<span style={{ fontSize: 11.5, color: f.value === '—' ? tokens.textMuted : tokens.text, lineHeight: 1.5 }}>{f.value}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (!detail) {
|
||||
return (
|
||||
<div style={{ flex: 1, display: 'grid', placeItems: 'center', color: tokens.textMuted, fontSize: 12.5 }}>
|
||||
在图谱或下方清单里选择一个条目
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── 对象:属性定义 + 实例下钻 ── */
|
||||
if (sel.kind === 'object') {
|
||||
const o = detail as OntObject;
|
||||
return (
|
||||
<>
|
||||
{head(o.name, `${o.en} · ${instances.length} 实例`, null, '对象')}
|
||||
<div style={body}>
|
||||
<div style={kv}>
|
||||
<span style={label}>业务含义</span>
|
||||
<span style={{ fontSize: 12, lineHeight: 1.6, color: tokens.textSub }}>{o.desc}</span>
|
||||
</div>
|
||||
<div style={kv}>
|
||||
<span style={label}>数据来源</span>
|
||||
<span style={{ fontSize: 11.5, color: tokens.textMuted }}>{o.source}</span>
|
||||
</div>
|
||||
<div style={{ ...kv, marginBottom: 4 }}>
|
||||
<span style={label}>属性 {o.attrs.length} 项</span>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 4 }}>
|
||||
{o.attrs.map(a => (
|
||||
<span
|
||||
key={a.en}
|
||||
title={`${a.name}:${a.type}${a.required ? ' · 必填' : ' · 可空'}${a.note ? ` — ${a.note}` : ''}`}
|
||||
style={{
|
||||
fontSize: 10.5, padding: '2px 7px', borderRadius: 6, cursor: 'default',
|
||||
fontFamily: 'ui-monospace, SFMono-Regular, monospace',
|
||||
color: a.required ? tokens.textSub : tokens.textMuted,
|
||||
background: a.required ? tokens.kpiCardBg : 'transparent',
|
||||
border: `1px dashed ${a.required ? tokens.borderAccent : tokens.border}`,
|
||||
}}
|
||||
>
|
||||
{a.en}{a.required ? '' : '?'}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<span style={{ fontSize: 10.5, color: tokens.textMuted }}>虚线=该列在本批数据里可空;悬停看中文列名与口径说明</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, margin: '10px 0 7px', paddingTop: 8, borderTop: `1px solid ${tokens.border}` }}>
|
||||
<span style={label}>实例下钻</span>
|
||||
<span style={{ fontSize: 11, color: tokens.textMuted }}>{instances.length} 条</span>
|
||||
</div>
|
||||
{instances.map((it, i) => (
|
||||
<InstanceRow key={`${it.id}-${i}`} it={it} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── 关系:两端 + 基数 + 连接键 ── */
|
||||
if (sel.kind === 'relation') {
|
||||
const r = detail as OntRelation;
|
||||
const from = objectById(r.from), to = objectById(r.to);
|
||||
return (
|
||||
<>
|
||||
{head(`关系 · ${r.name}`, r.id, null, '关系')}
|
||||
<div style={body}>
|
||||
<div style={{ display: 'flex', alignItems: 'stretch', gap: 8, marginBottom: 10 }}>
|
||||
{[from, to].map((o, i) => (
|
||||
<div key={i} style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||
<button
|
||||
onClick={() => o && onPickObject(o.id)}
|
||||
title="查看该对象"
|
||||
style={{
|
||||
textAlign: 'left', cursor: 'pointer', padding: '7px 9px', borderRadius: 9,
|
||||
background: tokens.panelBgAlt, border: `1px solid ${o?.color ?? tokens.border}66`,
|
||||
}}
|
||||
>
|
||||
<span style={{ fontSize: 10, color: tokens.textMuted }}>{i ? '目标' : '起点'}</span>
|
||||
<div style={{ fontSize: 13, fontWeight: 700, color: o?.color }}>{o?.name ?? r[i ? 'to' : 'from']}</div>
|
||||
<div style={{ fontSize: 10.5, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{o ? `${o.instances().length} 实例` : ''}</div>
|
||||
</button>
|
||||
{i === 0 && (
|
||||
<span style={{ textAlign: 'center', fontSize: 10.5, color: tokens.accent, fontWeight: 800, marginTop: -4 }}>{r.cardinality}</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div style={kv}>
|
||||
<span style={label}>连接键</span>
|
||||
<span style={{ fontSize: 11.5, fontFamily: 'ui-monospace, SFMono-Regular, monospace', color: tokens.textSub }}>{r.key}</span>
|
||||
</div>
|
||||
<div style={kv}>
|
||||
<span style={label}>当前实例数</span>
|
||||
<span style={{ fontSize: 20, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>{r.count()}</span>
|
||||
</div>
|
||||
<div style={kv}>
|
||||
<span style={label}>口径说明</span>
|
||||
<span style={{ fontSize: 12, lineHeight: 1.6, color: tokens.textSub }}>{r.desc}</span>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── 规则:表达式 + 实时命中 + 命中订单 ── */
|
||||
const isRule = sel.kind === 'rule';
|
||||
const rule = detail as OntRule;
|
||||
const action = detail as OntAction;
|
||||
const targets = isRule ? rule.hits() : { n: action.targets?.().length ?? 0, unit: '个目标对象', targets: action.targets?.() ?? [] };
|
||||
const list = isRule ? targets.targets : action.targets?.() ?? [];
|
||||
|
||||
return (
|
||||
<>
|
||||
{head(
|
||||
isRule ? rule.name : action.name,
|
||||
isRule ? `${rule.on} · ${rule.id}` : `${action.en} · ${action.object}`,
|
||||
isRule ? sevTone(rule.severity) : null,
|
||||
isRule ? '规则' : '动作',
|
||||
)}
|
||||
<div style={body}>
|
||||
{isRule ? (
|
||||
<>
|
||||
<div style={{
|
||||
...kv, padding: '7px 9px', borderRadius: 8, background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<span style={label}>判定表达式</span>
|
||||
<span style={{ fontSize: 11.5, lineHeight: 1.6, fontFamily: 'ui-monospace, SFMono-Regular, monospace', color: tokens.text }}>
|
||||
{rule.expr}
|
||||
</span>
|
||||
</div>
|
||||
<div style={kv}>
|
||||
<span style={label}>约束强度</span>
|
||||
<span style={{ fontSize: 12, color: tokens.textSub }}>
|
||||
{rule.severity === 'error' ? '硬约束:违反即质量风险外溢,必须处置' : rule.severity === 'warning' ? '预警:需要责任角色确认后处置' : '提示:结构性风险画像'}
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div style={kv}>
|
||||
<span style={label}>触发条件</span>
|
||||
<span style={{ fontSize: 12, color: tokens.textSub }}>{action.trigger}</span>
|
||||
</div>
|
||||
<div style={kv}>
|
||||
<span style={label}>作用对象 / 类型</span>
|
||||
<span style={{ fontSize: 12, color: tokens.textSub }}>{action.object} · {ACTION_TYPE[action.type].label}</span>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div style={kv}>
|
||||
<span style={label}>说明</span>
|
||||
<span style={{ fontSize: 12, lineHeight: 1.6, color: tokens.textSub }}>{isRule ? rule.desc : action.desc}</span>
|
||||
</div>
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'baseline', gap: 8, margin: '10px 0 8px', paddingTop: 9,
|
||||
borderTop: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<span style={{ fontSize: 22, fontWeight: 800, fontVariantNumeric: 'tabular-nums', color: isRule && rule.blocked ? tokens.textMuted : targets.n ? toneColor(tokens, isRule ? sevTone(rule.severity) : 'info').c : tokens.success }}>
|
||||
{isRule && rule.blocked ? '—' : targets.n}
|
||||
</span>
|
||||
<span style={{ fontSize: 11.5, color: tokens.textSub }}>
|
||||
{isRule && rule.blocked ? '数据缺口,规则无法执行' : targets.unit}
|
||||
</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
{isRule && !rule.blocked && targets.n === 0 && <Pill tone="success">本批无违反</Pill>}
|
||||
</div>
|
||||
{isRule && rule.blocked && (
|
||||
<div style={{
|
||||
display: 'flex', alignItems: 'flex-start', gap: 6, padding: '8px 10px', borderRadius: 9,
|
||||
background: tokens.warningBg, border: `1px solid ${tokens.warning}44`,
|
||||
}}>
|
||||
<Lock size={13} style={{ color: tokens.warning, marginTop: 1, flexShrink: 0 }} />
|
||||
<span style={{ fontSize: 11.5, lineHeight: 1.6, color: tokens.textSub }}>{rule.gap}</span>
|
||||
</div>
|
||||
)}
|
||||
{list.length > 0 && (
|
||||
<>
|
||||
<div style={{ ...label, margin: '11px 0 6px' }}>命中清单 {list.length} 项</div>
|
||||
{list.map((code, i) => (
|
||||
<div
|
||||
key={`${code}-${i}`}
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 8, marginBottom: 5, padding: '6px 9px',
|
||||
borderRadius: 8, background: tokens.panelBgAlt, border: `1px solid ${tokens.border}`,
|
||||
}}
|
||||
>
|
||||
<span style={{ width: 5, height: 16, borderRadius: 3, background: toneColor(tokens, isRule ? sevTone(rule.severity) : 'info').c, flexShrink: 0, opacity: 0.7 }} />
|
||||
<span style={{ fontSize: 11.5, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{code}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** 实例行:一行数据表记录,左=主键与口径,右=该行最该看的那个值 */
|
||||
function InstanceRow({ it }: { it: OntInstance }) {
|
||||
const { tokens } = useTheme();
|
||||
const tone = toneColor(tokens, it.tone ?? 'info');
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 8, marginBottom: 5, padding: '6px 9px', borderRadius: 8,
|
||||
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`,
|
||||
}}
|
||||
>
|
||||
<span style={{ width: 5, height: 22, borderRadius: 3, background: tone.c, flexShrink: 0, opacity: 0.75 }} />
|
||||
<div style={{ minWidth: 0, flex: 1 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
|
||||
<span style={{ fontSize: 12, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{it.title}</span>
|
||||
{it.badge && <Pill tone={it.tone ?? 'info'}>{it.badge}</Pill>}
|
||||
</div>
|
||||
<div style={{ fontSize: 10.5, color: tokens.textMuted, marginTop: 2, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{it.sub}</div>
|
||||
</div>
|
||||
<div style={{ textAlign: 'right', flexShrink: 0, maxWidth: '46%' }}>
|
||||
{it.value && (
|
||||
<div style={{ fontSize: 12, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{it.value}</div>
|
||||
)}
|
||||
<div style={{ fontSize: 10.5, color: tokens.textMuted, marginTop: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{it.meta}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user