新增模块
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
||||
import { useTheme } from '../../context/ThemeContext';
|
||||
import { type Tone } from '../../data/ontology';
|
||||
|
||||
/**
|
||||
* 业务本体图谱:8 个对象节点 + 10 条关系边。
|
||||
* 力导向布局移植自智能体开发平台的本体管理页(纯手写 SVG,不引 d3):
|
||||
* 环形初始化 → 斥力 6000/d² → 弹簧 (d−160)×0.008 → 向心 0.004 → 阻尼 0.88,跑满 120 帧收敛。
|
||||
* 配色改用本应用主题 token,深浅两套主题都保证边线与文字有足够对比度。
|
||||
*/
|
||||
|
||||
export interface GNode { id: string; label: string; count: number; color: string }
|
||||
export interface GEdge { id: string; source: string; target: string; label: string }
|
||||
|
||||
interface SimNode extends GNode { x: number; y: number; vx: number; vy: number; deg: number }
|
||||
|
||||
export interface ChainOverlay {
|
||||
nodeIds: Set<string>;
|
||||
edgeIds: Set<string>;
|
||||
tones: Record<string, Tone>;
|
||||
metrics: Record<string, Record<string, string>>;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
nodes: GNode[];
|
||||
edges: GEdge[];
|
||||
selectedNodeId: string | null;
|
||||
selectedEdgeId: string | null;
|
||||
onNodeClick?: (id: string) => void;
|
||||
onEdgeClick?: (id: string) => void;
|
||||
chain?: ChainOverlay | null;
|
||||
}
|
||||
|
||||
/** 节点内只放清洗后的短名,全称留给节点下方那行 */
|
||||
const shortName = (s: string) => s.replace(/([^)]*)/g, '').trim();
|
||||
|
||||
export default function OntologyGraph({ nodes: rawNodes, edges, selectedNodeId, selectedEdgeId, onNodeClick, onEdgeClick, chain }: 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);
|
||||
const [tooltipPos, setTooltipPos] = useState({ x: 0, y: 0 });
|
||||
const idPrefix = useId().replace(/:/g, '');
|
||||
|
||||
const inChainNode = (n: SimNode) => !!chain?.nodeIds.has(n.id);
|
||||
const inChainEdge = (e: GEdge) => !!chain?.edgeIds.has(e.id);
|
||||
const chainTone = (n: SimNode) => chain?.tones[n.id] ?? 'info';
|
||||
const toneColor = (t: Tone) => {
|
||||
switch (t) {
|
||||
case 'success': return tokens.success;
|
||||
case 'warning': return tokens.warning;
|
||||
case 'danger': return tokens.danger;
|
||||
case 'info': return tokens.info;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSvgMouseMove = (e: React.MouseEvent<SVGSVGElement>) => {
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
const scaleX = dims.w / rect.width;
|
||||
const scaleY = dims.h / rect.height;
|
||||
setTooltipPos({
|
||||
x: (e.clientX - rect.left) * scaleX,
|
||||
y: (e.clientY - rect.top) * scaleY,
|
||||
});
|
||||
};
|
||||
|
||||
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 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; });
|
||||
/* 舞台通常是横宽竖窄的:初始化用椭圆环而不是正圆,避免 8 个节点全挤在中间一条 */
|
||||
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) / rawNodes.length - 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;
|
||||
const rest = Math.max(160, Math.min(260, Math.min(dims.w, dims.h) * 0.55));
|
||||
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; n.vy += (cy - n.y) * 0.004;
|
||||
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]);
|
||||
|
||||
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;
|
||||
|
||||
const active = hovered ?? selectedNodeId;
|
||||
const isNeighbor = (id: string) =>
|
||||
!!active && edges.some(e => (e.source === active && e.target === id) || (e.target === active && e.source === id));
|
||||
|
||||
return (
|
||||
<svg ref={svgRef} width="100%" height="100%" viewBox={`0 0 ${dims.w} ${dims.h}`}
|
||||
preserveAspectRatio="xMidYMid meet" style={{ display: 'block', userSelect: 'none' }}
|
||||
onMouseMove={handleSvgMouseMove}>
|
||||
<defs>
|
||||
<marker id={`${idPrefix}-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={`${idPrefix}-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={`${idPrefix}-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={`${idPrefix}-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={`${idPrefix}-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>
|
||||
|
||||
<rect width="100%" height="100%" fill={`url(#${idPrefix}-ont-dots)`} />
|
||||
|
||||
{/* ── 关系边:透明粗线负责命中,细线负责显示 ── */}
|
||||
{edges.map(e => {
|
||||
const s = byId.get(e.source), t = byId.get(e.target);
|
||||
if (!s || !t) return null;
|
||||
const inChain = inChainEdge(e);
|
||||
const sel = e.id === selectedEdgeId;
|
||||
const hl = !chain && (sel || active === e.source || active === e.target);
|
||||
const stroke = sel ? tokens.accent : (chain && inChain) ? tokens.accent : hl ? tokens.info : tokens.textMuted;
|
||||
const strokeWidth = sel ? 2.4 : (chain && inChain) ? 2 : hl ? 1.6 : 1;
|
||||
const opacity = chain ? (sel || inChain ? 1 : 0.12) : (sel || hl ? 1 : 0.45);
|
||||
const markerEnd = (sel || hl || (chain && inChain)) ? `url(#${idPrefix}-ont-arrow-hl)` : `url(#${idPrefix}-ont-arrow)`;
|
||||
const textFill = sel ? tokens.accent : (chain && inChain) ? tokens.accent : hl ? tokens.info : tokens.textSub;
|
||||
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;
|
||||
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={stroke}
|
||||
strokeWidth={strokeWidth}
|
||||
opacity={opacity}
|
||||
markerEnd={markerEnd} />
|
||||
<rect x={mx - w / 2} y={my - 8} width={w} height={16} rx={5}
|
||||
fill={sel ? tokens.accentBg : tokens.panelBgAlt}
|
||||
stroke={stroke}
|
||||
strokeWidth={sel ? 1.4 : 0.7} />
|
||||
<text x={mx} y={my + 3.5} textAnchor="middle" fontSize={10} fontWeight={sel ? 700 : 500}
|
||||
fill={textFill}>{label}</text>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* ── 对象节点 ── */}
|
||||
{nodes.map(n => {
|
||||
const r = rOf(n.deg);
|
||||
const sel = n.id === selectedNodeId;
|
||||
const hl = hovered === n.id;
|
||||
const inChain = inChainNode(n);
|
||||
const dim = chain ? !inChain && !sel : (!!active && !sel && !hl && !isNeighbor(n.id));
|
||||
const ring = sel ? tokens.accent : hl ? tokens.info : (chain && inChain) ? toneColor(chainTone(n)) : 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)}>
|
||||
{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 : (chain && inChain) ? 2.2 : 1}
|
||||
opacity={chain && inChain ? 1 : (sel ? 0.85 : hl ? 0.5 : 0.16)}
|
||||
filter={sel || hl ? `url(#${idPrefix}-ont-strong)` : undefined} />
|
||||
<circle r={r} fill={tokens.panelBgAlt} stroke={ring}
|
||||
strokeWidth={sel ? 2.4 : hl ? 1.8 : (chain && inChain) ? 2.2 : 1.1} filter={`url(#${idPrefix}-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>
|
||||
<text textAnchor="middle" dy={r + 17} fontSize={10} fill={tokens.textMuted}>
|
||||
{shortName(n.label)} · {n.count} 实例
|
||||
</text>
|
||||
</g>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* ── 链节点 hover tooltip ── */}
|
||||
{(() => {
|
||||
const hoveredMetrics = hovered ? chain?.metrics[hovered] : null;
|
||||
const entries = hoveredMetrics ? Object.entries(hoveredMetrics) : [];
|
||||
const tipW = 220;
|
||||
const tipH = 20 + entries.length * 16;
|
||||
const tipX = Math.min(Math.max(tooltipPos.x + 14, 8), dims.w - tipW - 8);
|
||||
const tipY = Math.min(Math.max(tooltipPos.y + 14, 8), dims.h - tipH - 8);
|
||||
return entries.length > 0 && hovered && chain?.nodeIds.has(hovered) ? (
|
||||
<g transform={`translate(${tipX}, ${tipY})`} pointerEvents="none">
|
||||
<rect x={0} y={0} width={tipW} height={tipH} rx={8}
|
||||
fill={tokens.panelBgAlt} stroke={tokens.border} strokeWidth={1}
|
||||
filter={`url(#${idPrefix}-ont-soft)`} />
|
||||
{entries.map(([k, v], i) => (
|
||||
<text key={k} x={10} y={18 + i * 16} fontSize={11} fill={tokens.text}>
|
||||
<tspan fontWeight={700}>{k}:</tspan>
|
||||
<tspan x={70}>{v}</tspan>
|
||||
</text>
|
||||
))}
|
||||
</g>
|
||||
) : null;
|
||||
})()}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,754 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { AlertTriangle, Boxes, CircleSlash2, Lock, MapPin, Network, Search, ShieldAlert, X, Zap } from 'lucide-react';
|
||||
import { useTheme, type ThemeTokens } from '../../context/ThemeContext';
|
||||
import {
|
||||
actions, chainFor, graphEdges, graphNodes, objectById, objects, relations, rules,
|
||||
ONTOLOGY_AS_OF, type ChainNode, type OntAction, type OntInstance, type OntObject, type OntRelation, type OntRule, type Severity, type Tone,
|
||||
} from '../../data/ontology';
|
||||
import { salesOrders } from '../../data/ibp';
|
||||
import { money } from '../../lib/money';
|
||||
import OntologyGraph, { type ChainOverlay } from './OntologyGraph';
|
||||
|
||||
/**
|
||||
* 业务本体总览:把洁雅家居这批准单据(销售订单 / 生产工单 / 工单材料明细 / 采购订单 /
|
||||
* 客户 / 供应商 / 物料 / 仓库)抽象成「对象—关系—规则—动作」四层,结构在上方图谱里看,
|
||||
* 清单在下方四栏里选,点任意条目在右侧下钻到属性与真实实例。
|
||||
*
|
||||
* 所有数字(实例数、关系基数、规则命中数)都在 src/data/ontology.ts 里从 JSON 原始单据实时算出,
|
||||
* 页面不写死任何统计值。文案与本体数据层同源,全部是业务单据里的中文术语,因此不走 i18n 词典。
|
||||
*/
|
||||
|
||||
type Sel =
|
||||
| { kind: 'object'; id: string }
|
||||
| { kind: 'relation'; id: string }
|
||||
| { kind: 'rule'; id: string }
|
||||
| { kind: 'action'; id: 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 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>
|
||||
);
|
||||
};
|
||||
|
||||
interface Props {
|
||||
onExit: () => void;
|
||||
/** 点「定位到订单」:退出本体页并在左栏选中该销售订单 */
|
||||
onLocateSO: (so: string) => void;
|
||||
}
|
||||
|
||||
export default function OntologyView({ onExit, onLocateSO }: Props) {
|
||||
const { tokens } = useTheme();
|
||||
const [sel, setSel] = useState<Sel>({ kind: 'object', id: 'so' });
|
||||
const [query, setQuery] = useState('');
|
||||
const [selectedSONo, setSelectedSONo] = useState<string | null>(null);
|
||||
|
||||
const nodes = useMemo(() => graphNodes(), []);
|
||||
const edges = useMemo(() => graphEdges(), []);
|
||||
const hitTotal = useMemo(() => rules.reduce((a, r) => a + (r.blocked ? 0 : r.hits().n), 0), []);
|
||||
|
||||
const chain = useMemo(() => (selectedSONo ? chainFor(selectedSONo) : null), [selectedSONo]);
|
||||
|
||||
const chainOverlay = useMemo<ChainOverlay | null>(() => {
|
||||
if (!chain) return null;
|
||||
|
||||
const toneRank: Record<Tone, number> = { danger: 3, warning: 2, info: 1, success: 0 };
|
||||
const byObjectId = new Map<string, ChainNode[]>();
|
||||
for (const n of chain.nodes) {
|
||||
const list = byObjectId.get(n.objectId);
|
||||
if (list) list.push(n);
|
||||
else byObjectId.set(n.objectId, [n]);
|
||||
}
|
||||
|
||||
const tones: Record<string, Tone> = {};
|
||||
const metrics: Record<string, Record<string, string>> = {};
|
||||
for (const [objectId, nodes] of byObjectId) {
|
||||
const worst = nodes.reduce((acc, cur) => (toneRank[cur.tone] > toneRank[acc.tone] ? cur : acc));
|
||||
tones[objectId] = worst.tone;
|
||||
metrics[objectId] = { ...worst.metrics, 节点数: `${nodes.length}` };
|
||||
}
|
||||
|
||||
return {
|
||||
nodeIds: new Set(chain.nodes.map(n => n.objectId)),
|
||||
edgeIds: new Set(chain.edges.map(e => e.relationId)),
|
||||
tones,
|
||||
metrics,
|
||||
};
|
||||
}, [chain]);
|
||||
|
||||
const q = query.trim().toLowerCase();
|
||||
const match = (...fields: (string | undefined)[]) =>
|
||||
!q || fields.some(f => (f ?? '').toLowerCase().includes(q));
|
||||
|
||||
const visObjects = useMemo(() => objects.filter(o => match(o.name, o.en, o.desc, o.source)), [q]);
|
||||
const visRelations = useMemo(() => relations.filter(r => match(r.name, r.key, r.desc)), [q]);
|
||||
const visRules = useMemo(() => rules.filter(r => match(r.name, r.expr, r.desc, r.on)), [q]);
|
||||
const visActions = useMemo(() => actions.filter(a => match(a.name, a.en, a.desc, a.trigger, a.object)), [q]);
|
||||
|
||||
const detail = useMemo(() => {
|
||||
if (sel.kind === 'object') return objectById(sel.id) as OntObject | undefined;
|
||||
if (sel.kind === 'relation') return relations.find(r => r.id === sel.id);
|
||||
if (sel.kind === 'rule') return rules.find(r => r.id === sel.id);
|
||||
return actions.find(a => a.id === sel.id);
|
||||
}, [sel]);
|
||||
|
||||
/** 当前选中对象的实例列表(只在选中对象时计算,避免每帧重建 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',
|
||||
}}>
|
||||
<Boxes size={19} style={{ color: tokens.accent, flexShrink: 0 }} aria-hidden />
|
||||
<span style={{ fontSize: 15.5, fontWeight: 800, color: tokens.text, letterSpacing: '0.03em' }}>业务本体</span>
|
||||
<span style={{ fontSize: 11.5, color: tokens.textMuted, flexShrink: 0 }}>
|
||||
快照日 {ONTOLOGY_AS_OF} · 数据仅本批 Excel 单据
|
||||
</span>
|
||||
<span style={{ flex: '1 1 24px' }} />
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
|
||||
{[
|
||||
{ l: '对象', v: objects.length }, { l: '关系', v: relations.length },
|
||||
{ l: '规则', v: rules.length }, { l: '动作', v: actions.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 }} aria-hidden />
|
||||
<input
|
||||
value={query}
|
||||
onChange={e => setQuery(e.target.value)}
|
||||
placeholder="搜索对象 / 关系 / 规则 / 动作"
|
||||
aria-label="搜索对象 / 关系 / 规则 / 动作"
|
||||
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} aria-hidden />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={onExit}
|
||||
title="退出业务本体总览 (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} aria-hidden /> 退出 ESC
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* ── SCHEMA 徽标行:一眼看清每类对象有多少实例 ── */}
|
||||
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', flex: '0 0 auto' }}>
|
||||
{objects.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.12 1 0', minHeight: 210, display: 'flex', gap: 10 }}>
|
||||
{/* 销售订单选择器 */}
|
||||
<div style={{
|
||||
flex: '0 0 220px', 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',
|
||||
padding: '7px 12px', borderBottom: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<Boxes size={13} style={{ color: tokens.accent }} aria-hidden />
|
||||
<span style={{ fontSize: 12.5, fontWeight: 800, color: tokens.text }}>销售订单</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 11, color: tokens.textMuted, fontVariantNumeric: 'tabular-nums' }}>{salesOrders.length}</span>
|
||||
</div>
|
||||
<div style={{ flex: 1, minHeight: 0, overflowY: 'auto', overflowX: 'hidden', padding: '0 8px 8px' }}>
|
||||
{salesOrders.map(s => {
|
||||
const on = selectedSONo === s.销售订单号;
|
||||
return (
|
||||
<button
|
||||
key={s.销售订单号}
|
||||
onClick={() => setSelectedSONo(on ? null : s.销售订单号)}
|
||||
style={{
|
||||
width: '100%', textAlign: 'left', cursor: 'pointer', marginTop: 7,
|
||||
padding: '7px 9px', borderRadius: 9,
|
||||
background: on ? tokens.accentBg : tokens.panelBgAlt,
|
||||
border: `1px solid ${on ? tokens.accent : tokens.border}`,
|
||||
transition: 'background .15s ease, border-color .15s ease',
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 12, fontWeight: 700, color: tokens.text, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{s.销售订单号}
|
||||
</div>
|
||||
<div style={{ marginTop: 2, fontSize: 10.5, color: tokens.textMuted, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{s.客户简称} · {s.预计发货日期}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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',
|
||||
padding: '7px 12px', borderBottom: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
<Network size={13} style={{ color: tokens.accent }} aria-hidden />
|
||||
<span style={{ fontSize: 12.5, fontWeight: 800, color: tokens.text }}>本体图谱</span>
|
||||
<span style={{ fontSize: 11, color: tokens.textMuted }}>节点=对象(圈内数字为实例数)· 连线=关系 · 点节点或连线看定义</span>
|
||||
<span style={{ flex: 1 }} />
|
||||
<span style={{ fontSize: 10.5, color: tokens.textMuted }}>悬停可看关联链路</span>
|
||||
</div>
|
||||
<div style={{ flex: 1, minHeight: 0, position: 'relative' }}>
|
||||
<OntologyGraph
|
||||
nodes={nodes} edges={edges}
|
||||
selectedNodeId={selectedNodeId} selectedEdgeId={selectedEdgeId}
|
||||
chain={chainOverlay}
|
||||
onNodeClick={id => setSel({ kind: 'object', id })}
|
||||
onEdgeClick={id => setSel({ kind: 'relation', id })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 详情面板 */}
|
||||
<div style={{
|
||||
flex: '0 0 clamp(360px, 34%, 520px)', minWidth: 0, display: 'flex', flexDirection: 'column',
|
||||
borderRadius: 12, overflow: 'hidden', background: tokens.cardBg, border: `1px solid ${tokens.border}`,
|
||||
}}>
|
||||
{selectedSONo && chain && <ChainSummary summary={chain.summary} />}
|
||||
<DetailPanel
|
||||
sel={sel} detail={detail} instances={instances}
|
||||
onPickObject={id => setSel({ kind: 'object', id })}
|
||||
onLocateSO={onLocateSO}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── 下:对象 / 关系 / 规则 / 动作 四栏清单 ── */}
|
||||
<div style={{ flex: '1 1 0', minHeight: 178, display: 'flex', gap: 10 }}>
|
||||
<div style={colBox}>
|
||||
{colHead(<Boxes size={13} aria-hidden />, '对象 Object', visObjects.length, objects.length)}
|
||||
<div style={colScroll}>
|
||||
{visObjects.map(o => {
|
||||
const on = sel.kind === 'object' && sel.id === o.id;
|
||||
return (
|
||||
<button key={o.id} onClick={() => setSel({ kind: 'object', id: o.id })} style={cardBase(tokens, on)}>
|
||||
<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} aria-hidden />, '关系 Relation', visRelations.length, relations.length)}
|
||||
<div style={colScroll}>
|
||||
{visRelations.map(r => {
|
||||
const on = sel.kind === 'relation' && sel.id === r.id;
|
||||
return (
|
||||
<button key={r.id} onClick={() => setSel({ kind: 'relation', id: r.id })} style={cardBase(tokens, on)}>
|
||||
<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} aria-hidden />, '规则 Rule', visRules.length, rules.length)}
|
||||
<div style={colScroll}>
|
||||
{visRules.map(r => {
|
||||
const on = sel.kind === 'rule' && sel.id === r.id;
|
||||
const h = r.hits();
|
||||
return (
|
||||
<button
|
||||
key={r.id} onClick={() => setSel({ kind: 'rule', id: r.id })}
|
||||
style={{ ...cardBase(tokens, on), opacity: r.blocked ? 0.62 : 1 }}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
||||
{r.blocked
|
||||
? <CircleSlash2 size={11} style={{ color: tokens.textMuted, flexShrink: 0 }} aria-hidden />
|
||||
: <AlertTriangle size={11} style={{ color: toneColor(tokens, sevTone(r.severity)).c, flexShrink: 0 }} aria-hidden />}
|
||||
<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} aria-hidden />, '动作 Action', visActions.length, actions.length)}
|
||||
<div style={colScroll}>
|
||||
{visActions.map(a => {
|
||||
const on = sel.kind === 'action' && sel.id === a.id;
|
||||
const n = a.targets?.().length ?? 0;
|
||||
return (
|
||||
<button key={a.id} onClick={() => setSel({ kind: 'action', id: a.id })} style={cardBase(tokens, on)}>
|
||||
<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>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const Empty = ({ tk }: { tk: ThemeTokens }) => (
|
||||
<div style={{ padding: '22px 0', textAlign: 'center', fontSize: 12, color: tk.textMuted }}>无匹配条目</div>
|
||||
);
|
||||
|
||||
/* ── 链汇总 ──────────────────────────────────────────────────────────── */
|
||||
|
||||
function ChainSummary({ summary }: { summary: { level: Tone; text: string; redFlags: string[] } }) {
|
||||
const { tokens } = useTheme();
|
||||
const tc = toneColor(tokens, summary.level);
|
||||
return (
|
||||
<div style={{
|
||||
marginBottom: 10, padding: '9px 12px', borderRadius: 10,
|
||||
background: tc.bg, border: `1px solid ${tc.c}44`,
|
||||
}}>
|
||||
<div style={{ fontSize: 12, fontWeight: 800, color: tc.c }}>{summary.text}</div>
|
||||
{summary.redFlags.length > 0 && (
|
||||
<ul style={{ margin: '6px 0 0', paddingLeft: 16, fontSize: 11, color: tokens.textSub }}>
|
||||
{summary.redFlags.map((f, i) => <li key={i}>{f}</li>)}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── 右侧详情面板 ─────────────────────────────────────────────────────── */
|
||||
|
||||
function DetailPanel({
|
||||
sel, detail, instances, onPickObject, onLocateSO,
|
||||
}: {
|
||||
sel: Sel;
|
||||
detail: OntObject | OntRelation | OntRule | OntAction | undefined;
|
||||
instances: OntInstance[];
|
||||
onPickObject: (id: string) => void;
|
||||
onLocateSO: (so: string) => void;
|
||||
}) {
|
||||
const { tokens } = useTheme();
|
||||
|
||||
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 (!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;
|
||||
const locatable = o.id === 'so';
|
||||
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>
|
||||
<span style={{ flex: 1 }} />
|
||||
{locatable && <span style={{ fontSize: 10.5, color: tokens.accent }}>点击定位到左栏</span>}
|
||||
</div>
|
||||
{instances.map((it, i) => (
|
||||
<InstanceRow key={`${it.id}-${i}`} it={it} locatable={locatable} onLocateSO={onLocateSO} />
|
||||
))}
|
||||
</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 actionTargets = action.targets?.() ?? [];
|
||||
const targets = isRule ? rule.hits() : { n: actionTargets.length, unit: '个目标对象', targets: actionTargets };
|
||||
const list = isRule ? targets.targets : actionTargets;
|
||||
const soObject = objects.find(o => o.id === 'so');
|
||||
const soSet = new Set(soObject?.instances().map(i => i.id) ?? []);
|
||||
|
||||
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 }} aria-hidden />
|
||||
<span style={{ fontSize: 11.5, lineHeight: 1.6, color: tokens.textSub }}>
|
||||
该规则依赖现存量 / 已分配 / 安全库存 / 在途入库四类字段,本批 Excel 单据均未提供,
|
||||
因此只标注为数据缺口,不给「通过」结论。
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{list.length > 0 && (
|
||||
<>
|
||||
<div style={{ ...label, margin: '11px 0 6px' }}>命中清单 {list.length} 项</div>
|
||||
{list.map((code, i) => {
|
||||
const isSO = soSet.has(code);
|
||||
return (
|
||||
<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={{ fontSize: 11.5, fontWeight: 700, color: tokens.text, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{code}
|
||||
</span>
|
||||
{!isSO && <span style={{ fontSize: 10.5, color: tokens.textMuted }}>编码</span>}
|
||||
<span style={{ flex: 1 }} />
|
||||
{isSO ? (
|
||||
<button
|
||||
onClick={() => onLocateSO(code)}
|
||||
title="关闭本体页并在左栏选中该订单"
|
||||
style={{
|
||||
display: 'flex', alignItems: 'center', gap: 4, cursor: 'pointer', flexShrink: 0,
|
||||
fontSize: 10.5, fontWeight: 700, padding: '2px 8px', borderRadius: 999,
|
||||
color: tokens.accent, background: tokens.accentBg, border: `1px solid ${tokens.borderAccent}`,
|
||||
}}
|
||||
>
|
||||
<MapPin size={11} aria-hidden /> 定位
|
||||
</button>
|
||||
) : (
|
||||
<span style={{ fontSize: 10.5, color: tokens.textMuted }}>非订单主键</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** 实例行:对象实例的通用展示,销售订单额外给「定位」入口 */
|
||||
function InstanceRow({ it, locatable, onLocateSO }: { it: OntInstance; locatable: boolean; onLocateSO: (so: string) => void }) {
|
||||
const { tokens } = useTheme();
|
||||
const tone = toneColor(tokens, it.tone ?? 'info');
|
||||
const style: React.CSSProperties = {
|
||||
display: 'flex', alignItems: 'center', gap: 8, marginBottom: 5, padding: '6px 9px', borderRadius: 8,
|
||||
background: tokens.kpiCardBg, border: `1px solid ${tokens.border}`,
|
||||
};
|
||||
const content = (
|
||||
<>
|
||||
<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 }}>
|
||||
{it.amount !== undefined && (
|
||||
<div style={{ fontSize: 12, fontWeight: 800, color: tokens.accent, fontVariantNumeric: 'tabular-nums' }}>{money(it.amount)}</div>
|
||||
)}
|
||||
<div style={{ fontSize: 10.5, color: tokens.textMuted, marginTop: 1 }}>{it.meta}</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
if (locatable) {
|
||||
return (
|
||||
<button
|
||||
onClick={() => onLocateSO(it.id)}
|
||||
title="关闭本体页并在左栏选中该订单"
|
||||
style={{ ...style, width: '100%', textAlign: 'left', font: 'inherit', color: 'inherit', cursor: 'pointer' }}
|
||||
>
|
||||
{content}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
return <div style={{ ...style, cursor: 'default' }}>{content}</div>;
|
||||
}
|
||||
Reference in New Issue
Block a user