feat: init ai-platform - 源码 + 配置

This commit is contained in:
2026-08-25 16:27:43 +08:00
commit 83210a606a
122 changed files with 27401 additions and 0 deletions
@@ -0,0 +1,276 @@
import { useState, useCallback, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import ThemeToggle from '@/shared/components/ThemeToggle';
import KnowledgeGraph from '../components/KnowledgeGraph';
import NodeDetailPanel from '../components/NodeDetailPanel';
import StatsOverview from '../components/StatsOverview';
import MaterialList from '../components/MaterialList';
import type { Material } from '../data/materials';
type ViewMode = 'category' | 'project' | 'aging';
type SideTab = 'stats' | 'list' | 'assistant';
interface SelectedNode {
id: string;
label: string;
type: string;
color: string;
material?: Material;
count?: number;
agingRange?: string;
}
const SIDEBAR_MIN = 240;
const SIDEBAR_MAX = 600;
export default function KnowledgeGraphHome() {
const navigate = useNavigate();
const [viewMode, setViewMode] = useState<ViewMode>('category');
const [filterCategory, setFilterCategory] = useState<string | null>(null);
const [filterAging, setFilterAging] = useState<string | null>(null);
const [selectedNode, setSelectedNode] = useState<SelectedNode | null>(null);
const [sideTab, setSideTab] = useState<SideTab>('stats');
const [sidebarWidth, setSidebarWidth] = useState(320);
const isDragging = useRef(false);
const handleNodeSelect = (node: SelectedNode | null) => setSelectedNode(node);
const handleMaterialSelect = (mat: Material | null) => {
if (!mat) { setSelectedNode(null); return; }
setSelectedNode({ id: mat.id, label: mat.name, type: 'material', color: '#0A7AFF', material: mat });
};
const handleFilterCategory = (c: string | null) => { setFilterCategory(c); setSelectedNode(null); };
const handleFilterAging = (a: string | null) => { setFilterAging(a); setSelectedNode(null); };
const handleDividerMouseDown = useCallback((e: React.MouseEvent) => {
e.preventDefault();
isDragging.current = true;
const startX = e.clientX;
const startWidth = sidebarWidth;
document.body.style.cursor = 'col-resize';
document.body.style.userSelect = 'none';
const onMouseMove = (ev: MouseEvent) => {
if (!isDragging.current) return;
const delta = ev.clientX - startX;
const newWidth = Math.min(SIDEBAR_MAX, Math.max(SIDEBAR_MIN, startWidth + delta));
setSidebarWidth(newWidth);
};
const onMouseUp = () => {
isDragging.current = false;
document.body.style.cursor = '';
document.body.style.userSelect = '';
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
};
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
}, [sidebarWidth]);
const viewLabels: Record<ViewMode, string> = { category: '按分类', project: '按项目', aging: '按账龄' };
return (
<div className="flex h-screen w-screen overflow-hidden" style={{ backgroundColor:'#f5f5f7' }}>
{/* Sidebar */}
<aside className="flex-shrink-0 flex flex-col sidebar-bg" style={{ width:sidebarWidth, borderRight:'none' }}>
{/* Logo header */}
<div style={{ padding:'20px 20px 16px' }}>
<div style={{ display:'flex', alignItems:'center', gap:14 }}>
<div style={{ width:52, height:52, borderRadius:14, backgroundColor:'#fff', display:'flex', alignItems:'center', justifyContent:'center', flexShrink:0, boxShadow:'0 3px 12px rgba(26,58,92,0.28)' }}>
<img src="/ology-logo.png" alt="OLOGY 欧力杰" style={{ width:46, height:'auto', objectFit:'contain' }} />
</div>
<div>
<h1 style={{ color:'#1c1c1e', fontSize:17, fontWeight:700, letterSpacing:'-0.03em', lineHeight:1.2, margin:0 }}>采购域知识图谱</h1>
<p style={{ color:'#8e8e93', fontSize:13, marginTop:4, letterSpacing:'-0.01em' }}>采购单关系可视化</p>
</div>
</div>
</div>
<div style={{ height:1, backgroundColor:'#e5e5ea', margin:'0 20px' }} />
{/* Segmented tab */}
<div style={{ padding:'12px 16px' }}>
<div style={{ display:'flex', borderRadius:10, padding:3, gap:2, backgroundColor:'#ebebf0' }}>
{(['stats','list','assistant'] as SideTab[]).map(tab => (
<button key={tab} onClick={() => setSideTab(tab)}
style={{
flex:1, padding:'8px 0', borderRadius:8,
fontSize:14, fontWeight:500, letterSpacing:'-0.01em', cursor:'pointer',
backgroundColor: sideTab===tab ? '#ffffff' : 'transparent',
color: sideTab===tab ? '#1c1c1e' : '#8e8e93',
boxShadow: sideTab===tab ? '0 1px 4px rgba(0,0,0,0.12)' : 'none',
transition:'all 0.18s ease',
border:'none',
}}>
{tab==='stats' ? '统计概览' : tab==='list' ? '物料列表' : '物料助手'}
</button>
))}
</div>
</div>
{/* Content */}
<div style={{ flex:1, overflow:'hidden' }}>
{sideTab==='stats' ? (
<div style={{ padding:'0 16px 16px', height:'100%', overflowY:'auto' }}>
<StatsOverview filterCategory={filterCategory} filterAging={filterAging}
onFilterCategory={handleFilterCategory} onFilterAging={handleFilterAging} />
</div>
) : sideTab==='list' ? (
<MaterialList filterCategory={filterCategory} filterAging={filterAging}
onSelect={handleMaterialSelect} selectedId={selectedNode?.id || null} />
) : (
<iframe
src="https://kai-skc.apps.digiwincloud.com.cn/assistant/web/ncqomq10wgh338c9"
style={{ width:'100%', height:'100%', border:'none' }}
title="物料助手"
/>
)}
</div>
</aside>
{/* Resizable Divider */}
<div
onMouseDown={handleDividerMouseDown}
style={{
width: 6,
cursor: 'col-resize',
position: 'relative',
flexShrink: 0,
zIndex: 10,
}}
>
<div style={{
position: 'absolute',
top: 0, bottom: 0, left: 2, right: 2,
backgroundColor: '#e5e5ea',
borderRadius: 3,
transition: 'background-color 0.18s ease',
}}
onMouseEnter={e => { e.currentTarget.style.backgroundColor = '#007AFF'; }}
onMouseLeave={e => { e.currentTarget.style.backgroundColor = '#e5e5ea'; }}
/>
</div>
{/* Main */}
<main style={{ flex:1, display:'flex', flexDirection:'column', minWidth:0 }}>
{/* Toolbar */}
<div style={{
height:60, flexShrink:0, display:'flex', alignItems:'center', gap:16, padding:'0 24px',
backgroundColor:'rgba(248,248,250,0.92)', backdropFilter:'blur(20px)',
borderBottom:'1px solid #e5e5ea',
}}>
{/* View mode */}
<div style={{ display:'flex', borderRadius:10, padding:3, gap:2, backgroundColor:'#ebebf0' }}>
{(Object.keys(viewLabels) as ViewMode[]).map(mode => (
<button key={mode} onClick={() => { setViewMode(mode); setSelectedNode(null); }}
style={{
padding:'7px 18px', borderRadius:8,
fontSize:14, fontWeight:500, letterSpacing:'-0.01em', cursor:'pointer',
backgroundColor: viewMode===mode ? '#ffffff' : 'transparent',
color: viewMode===mode ? '#007AFF' : '#8e8e93',
boxShadow: viewMode===mode ? '0 1px 4px rgba(0,0,0,0.12)' : 'none',
transition:'all 0.18s ease',
border:'none',
}}>
{viewLabels[mode]}
</button>
))}
</div>
{/* Active filters */}
<div style={{ display:'flex', alignItems:'center', gap:8, flex:1 }}>
{filterCategory && (
<span style={{ display:'inline-flex', alignItems:'center', gap:6, padding:'5px 12px', borderRadius:20, fontSize:13, fontWeight:500, backgroundColor:'rgba(10,122,255,0.08)', color:'#0A7AFF', border:'1px solid rgba(10,122,255,0.18)' }}>
{filterCategory}
<button onClick={() => setFilterCategory(null)} style={{ width:16, height:16, borderRadius:'50%', backgroundColor:'rgba(10,122,255,0.18)', display:'flex', alignItems:'center', justifyContent:'center', fontSize:12, lineHeight:1, border:'none', cursor:'pointer', color:'#0A7AFF' }}>×</button>
</span>
)}
{filterAging && (
<span style={{ display:'inline-flex', alignItems:'center', gap:6, padding:'5px 12px', borderRadius:20, fontSize:13, fontWeight:500, backgroundColor:'rgba(224,140,0,0.08)', color:'#C07800', border:'1px solid rgba(224,140,0,0.20)' }}>
账龄 {filterAging} 天
<button onClick={() => setFilterAging(null)} style={{ width:16, height:16, borderRadius:'50%', backgroundColor:'rgba(224,140,0,0.20)', display:'flex', alignItems:'center', justifyContent:'center', fontSize:12, lineHeight:1, border:'none', cursor:'pointer', color:'#C07800' }}>×</button>
</span>
)}
{(filterCategory || filterAging) && (
<button onClick={() => { setFilterCategory(null); setFilterAging(null); }}
style={{ fontSize:13, color:'#8e8e93', border:'none', cursor:'pointer', backgroundColor:'transparent', letterSpacing:'-0.01em' }}>
清除筛选
</button>
)}
</div>
<p style={{ fontSize:13, color:'#aeaeb2', letterSpacing:'-0.01em', whiteSpace:'nowrap' }}>
点击节点查看详情 · 滚轮缩放 · 拖拽平移
</p>
<ThemeToggle />
<button onClick={() => navigate('/')} style={{
display:'flex', alignItems:'center', gap:4,
padding:'6px 12px', borderRadius:8, cursor:'pointer',
backgroundColor:'transparent',
border:'1px solid #e5e5ea',
color:'#8e8e93', fontSize:13, fontWeight:500, letterSpacing:'-0.01em',
transition:'all 0.18s ease', whiteSpace:'nowrap',
}}
onMouseEnter={e => { e.currentTarget.style.borderColor = 'rgba(0,122,255,0.3)'; e.currentTarget.style.color = '#007AFF'; }}
onMouseLeave={e => { e.currentTarget.style.borderColor = '#e5e5ea'; e.currentTarget.style.color = '#8e8e93'; }}
>
← 返回平台
</button>
{/* 进入EIOS按钮 */}
<button
onClick={() => navigate('/knowledge-graph/space')}
style={{
display:'flex', alignItems:'center', gap:6,
padding:'8px 16px', borderRadius:10, cursor:'pointer',
backgroundColor:'#ffffff',
border:'1px solid #e5e5ea',
color:'#007AFF', fontSize:13, fontWeight:600, letterSpacing:'-0.01em',
boxShadow:'0 1px 4px rgba(0,0,0,0.08)', whiteSpace:'nowrap',
transition:'all 0.18s ease',
}}
onMouseEnter={e => {
e.currentTarget.style.backgroundColor = '#f0f7ff';
e.currentTarget.style.borderColor = 'rgba(0,122,255,0.3)';
e.currentTarget.style.boxShadow = '0 2px 8px rgba(0,122,255,0.12)';
}}
onMouseLeave={e => {
e.currentTarget.style.backgroundColor = '#ffffff';
e.currentTarget.style.borderColor = '#e5e5ea';
e.currentTarget.style.boxShadow = '0 1px 4px rgba(0,0,0,0.08)';
}}
>
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="#007AFF" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" style={{ flexShrink: 0 }}>
{/* 六边形外框 */}
<path d="M12 2l8 4.5v9L12 20l-8-4.5v-9L12 2z" />
{/* 中心节点 */}
<circle cx="12" cy="11.5" r="2" />
{/* 三条辐射线 */}
<line x1="12" y1="9.5" x2="12" y2="6" />
<line x1="10.27" y1="10.5" x2="7" y2="8.7" />
<line x1="13.73" y1="10.5" x2="17" y2="8.7" />
</svg> 进入EIOS
</button>
</div>
{/* Graph + detail */}
<div style={{ flex:1, display:'flex', overflow:'hidden', padding:16, gap:12 }}>
<div style={{ flex:1, minWidth:0, borderRadius:20, overflow:'hidden', backgroundColor:'#ffffff', boxShadow:'0 2px 20px rgba(0,0,0,0.06)', border:'1px solid #e5e5ea' }}>
<KnowledgeGraph
onNodeSelect={handleNodeSelect}
filterCategory={filterCategory}
filterAging={filterAging}
viewMode={viewMode}
/>
</div>
{selectedNode && (
<div style={{ width:320, flexShrink:0 }} className="animate-slide-in-right">
<NodeDetailPanel node={selectedNode} onClose={() => setSelectedNode(null)} />
</div>
)}
</div>
</main>
</div>
);
}