Files
ai-platform/src/modules/order-cost-analysis/pages-orig/CostCockpit.tsx
T
dongskandClaude Sonnet 4.6 noreply@anthropic.com> 8699798ea5 feat: 模组全维度独立,消除全局 DOM/Portal/存储污染
- jieya-ibp/welltrust-qap ThemeContext 改为作用域容器承载 CSS 变量与背景色,不再写 document
- 删除 order-cost CostCockpit 对 documentElement 的死变量写入
- bomx Drawer createPortal 挂载点内移到 .bomx-app,移除 document.body 兜底
- knowledge-graph 拖拽 cursor 改为根容器 ref
- 新增 check-module-independence 门禁并接入 build
- SOP 与融合技能文档补充「模组完全独立互不影响」章节

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com>
2026-10-19 09:10:30 +08:00

311 lines
13 KiB
TypeScript

import { useState, useEffect, useRef, type DragEvent } from 'react';
import StarBackground from '../components/StarBackground';
import CostHeader from '../components/CostHeader';
import LeftOrderPanel from '../components/LeftOrderPanel';
import CenterBOMView from '../components/CenterBOMView';
import CenterTheoryCost from '../components/CenterTheoryCost';
import CenterProductionSim from '../components/CenterProductionSim';
import CenterCostCompare from '../components/CenterCostCompare';
import RightAIPanel from '../components/RightAIPanel';
import BottomCostBar from '../components/BottomCostBar';
import type { Order } from '../data/orders';
import type { Equipment } from '../components/CenterProductionSim';
import { useTheme } from '../context/ThemeContext';
import { useOrders } from '../services/hooks/useOrders';
const NAV_ITEMS = [
{ id: 'decompose', icon: '🔍', label: '拆解客户需求产品' },
{ id: 'theory', icon: '📐', label: '智能测算理论成本' },
{ id: 'profit', icon: '📊', label: '智能模拟实际成本' },
{ id: 'compare', icon: '🔀', label: '成本对比' },
];
export default function CostCockpit() {
const { theme, tokens, toggleTheme } = useTheme();
const { orders } = useOrders();
const [selectedOrder, setSelectedOrder] = useState<Order | null>(null);
const [leftExpanded, setLeftExpanded] = useState(false);
const [rightExpanded, setRightExpanded] = useState(false);
const [centerFullscreen, setCenterFullscreen] = useState(false);
const [centerTab, setCenterTab] = useState('decompose');
const [droppedEquipment, setDroppedEquipment] = useState<Equipment | null>(null);
const [processingOrder, setProcessingOrder] = useState<Order | null>(null);
const [isProcessing, setIsProcessing] = useState(false);
const [workspaceResetKey] = useState(0);
const [bottomHidden, setBottomHidden] = useState(false);
const processingTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const startProcessing = (order: Order) => {
if (processingTimer.current) clearTimeout(processingTimer.current);
setSelectedOrder(order);
setIsProcessing(true);
setProcessingOrder(order);
processingTimer.current = setTimeout(() => {
setIsProcessing(false);
setProcessingOrder(null);
}, 3500);
};
const handleCenterDrop = (e: DragEvent<HTMLDivElement>) => {
e.preventDefault();
const orderData = e.dataTransfer.getData('application/x-order-json');
const orderEqData = e.dataTransfer.getData('application/x-equipment-json');
if (orderEqData) {
try {
const eq: Equipment = JSON.parse(orderEqData);
setDroppedEquipment(eq);
setCenterTab('profit');
} catch { /* ignore */ }
return;
}
if (orderData) {
try {
const order: Order = JSON.parse(orderData);
startProcessing(order);
setCenterTab('decompose');
} catch { /* ignore */ }
}
};
// Esc 退出全屏
useEffect(() => {
const handleKey = (e: KeyboardEvent) => {
if (e.key === 'Escape' && centerFullscreen) setCenterFullscreen(false);
};
window.addEventListener('keydown', handleKey);
return () => window.removeEventListener('keydown', handleKey);
}, [centerFullscreen]);
return (
<div className="ordercost-root" style={{
width: '100vw', height: '100vh',
overflow: 'hidden',
display: 'flex', flexDirection: 'column',
position: 'relative',
fontFamily: "-apple-system, 'SF Pro Text', 'PingFang SC', sans-serif",
color: tokens.text,
background: tokens.bodyBg,
}}>
{/* 星空背景 */}
<StarBackground theme={theme} />
{/* 内容层 */}
<div style={{ position: 'relative', zIndex: 1, display: 'flex', flexDirection: 'column', height: '100%' }}>
{/* 顶部标题栏 */}
<CostHeader theme={theme} onToggleTheme={toggleTheme} orders={orders} />
{/* 留白 */}
<div style={{ height: 14, flexShrink: 0 }} />
{/* 中部三栏区域 */}
<div style={{ flex: 1, display: 'flex', minHeight: 0, position: 'relative', gap: 0, padding: '0 0' }}>
{/* 左侧:订单列表面板 */}
<div style={{
display: 'flex', flexDirection: 'column', flexShrink: 0,
marginTop: 80, height: '100%',
transition: 'width 0.3s cubic-bezier(0.4,0,0.2,1)',
width: leftExpanded ? 474 : 282,
}}>
<LeftOrderPanel
selectedId={selectedOrder?.id ?? null}
onExpandChange={setLeftExpanded}
orders={orders}
onSelect={(order) => { setSelectedOrder(order); setCenterTab('decompose'); }}
/>
</div>
{/* 间隙 */}
<div style={{ width: 20, flexShrink: 0 }} />
{/* 中央:智能成本分析 */}
<div style={{ flex: 1, minWidth: 0, display: 'flex', position: 'relative', marginTop: 80 }}>
<div style={{
flex: 1, borderRadius: 16, overflow: 'hidden',
border: `1px solid ${tokens.border}`,
boxShadow: `0 0 30px ${tokens.accent}10, 0 0 60px ${tokens.accent}06`,
background: tokens.centerBg,
backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
position: 'relative',
display: 'flex', flexDirection: 'column',
}}>
{/* 四角装饰 */}
{['top-left', 'top-right', 'bottom-left', 'bottom-right'].map(pos => {
const isTop = pos.includes('top');
const isLeft = pos.includes('left');
return (
<div key={pos} style={{
position: 'absolute',
top: isTop ? 8 : undefined, bottom: !isTop ? 8 : undefined,
left: isLeft ? 8 : undefined, right: !isLeft ? 8 : undefined,
width: 16, height: 16, zIndex: 5, pointerEvents: 'none',
borderTop: isTop ? `2px solid ${tokens.accent}60` : 'none',
borderBottom: !isTop ? `2px solid ${tokens.accent}60` : 'none',
borderLeft: isLeft ? `2px solid ${tokens.accent}60` : 'none',
borderRight: !isLeft ? `2px solid ${tokens.accent}60` : 'none',
}} />
);
})}
{/* 中央标题栏 */}
<div style={{
padding: '12px 16px 10px', borderBottom: `1px solid ${tokens.border}`,
display: 'grid', gridTemplateColumns: '1fr auto 1fr', alignItems: 'center', gap: 10, flexShrink: 0,
}}>
<div />
<span style={{
color: tokens.text, fontSize: 21, fontWeight: 800,
letterSpacing: '0.05em', lineHeight: 1.1, textAlign: 'center',
}}>
智能成本分析 Agentic Cost Analysis
</span>
<div style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center', gap: 8 }}>
{selectedOrder && (
<span style={{
padding: '2px 8px', borderRadius: 6,
background: tokens.accentBg, border: `1px solid ${tokens.accent}25`,
color: tokens.accent, fontSize: 12,
}}>
{selectedOrder.orderNo}
</span>
)}
<button onClick={() => setCenterFullscreen(f => !f)} style={{
padding: '3px 8px', borderRadius: 6,
border: `1px solid ${tokens.border}`,
background: 'transparent', color: tokens.textMuted,
fontSize: 12, cursor: 'pointer',
}}>
{centerFullscreen ? '退出全屏' : '全屏'}
</button>
</div>
</div>
{/* 功能导航栏 */}
<div style={{
display: 'flex', justifyContent: 'center', gap: 4,
padding: '8px 24px', borderBottom: `1px solid ${tokens.border}`,
flexShrink: 0,
}}>
{NAV_ITEMS.map(item => {
const active = centerTab === item.id;
return (
<button key={item.id} onClick={() => setCenterTab(item.id)} style={{
flex: 1, maxWidth: 200,
padding: '8px 12px', borderRadius: 8,
border: `1px solid ${active ? tokens.accent + '50' : 'transparent'}`,
background: active ? tokens.accentBg : 'transparent',
color: active ? tokens.accent : tokens.textMuted,
fontSize: 13, fontWeight: active ? 700 : 500,
cursor: 'pointer', transition: 'all 0.2s ease',
borderBottom: active ? `2px solid ${tokens.accent}` : '2px solid transparent',
display: 'flex', alignItems: 'center', gap: 5, justifyContent: 'center',
}}>
<span>{item.icon}</span>
<span>{item.label}</span>
</button>
);
})}
</div>
{/* 中央内容区 */}
<div
onDragOver={e => e.preventDefault()}
onDrop={handleCenterDrop}
style={{ flex: 1, minHeight: 0, overflow: 'hidden', position: 'relative', display: 'flex', flexDirection: 'column' }}
>
{centerTab === 'decompose' && (
<CenterBOMView
key="bom"
order={selectedOrder}
onDrop={handleCenterDrop}
isProcessing={isProcessing}
processingOrder={processingOrder}
/>
)}
{centerTab === 'theory' && (
<CenterTheoryCost
key="theory"
order={selectedOrder}
resetKey={workspaceResetKey}
onDrop={handleCenterDrop}
isProcessing={isProcessing}
processingOrder={processingOrder}
/>
)}
{centerTab === 'profit' && (
<CenterProductionSim
key="profit"
order={selectedOrder}
equipment={droppedEquipment}
onEquipmentUsed={() => setDroppedEquipment(null)}
/>
)}
{centerTab === 'compare' && (
<CenterCostCompare
key="compare"
order={selectedOrder}
/>
)}
</div>
</div>
</div>
{/* 间隙 */}
<div style={{ width: 20, flexShrink: 0 }} />
{/* 右侧:生产设备库 */}
<div style={{
display: 'flex', flexDirection: 'column', flexShrink: 0,
marginTop: 80, height: '100%',
transition: 'width 0.3s cubic-bezier(0.4,0,0.2,1)',
width: rightExpanded ? 494 : 282,
}}>
<RightAIPanel
selectedOrder={selectedOrder}
onExpandChange={setRightExpanded}
/>
</div>
</div>
{/* 底部AI问答区 — 根据左右侧板展开状态自动收缩避让,支持隐藏为浮标 */}
{bottomHidden ? (
<div style={{ flexShrink: 0, display: 'flex', justifyContent: 'center', paddingBottom: 12, position: 'relative', zIndex: 10 }}>
<button onClick={() => setBottomHidden(false)} style={{
display: 'flex', alignItems: 'center', gap: 8,
padding: '10px 18px', borderRadius: 24,
border: `1px solid ${tokens.accent}50`,
background: tokens.bottomBg,
backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)',
color: tokens.accent, fontSize: 13, fontWeight: 700,
cursor: 'pointer', boxShadow: `0 4px 20px ${tokens.accent}20`,
transition: 'all 0.2s ease',
}}>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none">
<circle cx="9" cy="9" r="7" stroke={tokens.accent} strokeWidth="1.5"/>
<path d="M 6,7 L 12,7 M 6,9 L 12,9 M 6,11 L 10,11" stroke={tokens.accent} strokeWidth="1.2" strokeLinecap="round"/>
</svg>
AI 智能问答
</button>
</div>
) : (
<>
{/* 底部留白 */}
<div style={{ height: 12, flexShrink: 0 }} />
<div style={{
flexShrink: 0,
marginLeft: (leftExpanded ? 474 : 282) + 20,
marginRight: (rightExpanded ? 494 : 282) + 20,
transition: 'margin 0.3s cubic-bezier(0.4,0,0.2,1)',
}}>
<BottomCostBar selectedOrder={selectedOrder} onHide={() => setBottomHidden(true)} />
</div>
</>
)}
</div>
</div>
);
}