feat: init ai-platform - 源码 + 配置
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { initStore } from '../core/store';
|
||||
import BomBrowser from '../components/BomBrowser';
|
||||
import MiningView from '../components/MiningView';
|
||||
import SimilarityView from '../components/SimilarityView';
|
||||
import StandardLibrary from '../components/StandardLibrary';
|
||||
import ReuseSearch from '../components/ReuseSearch';
|
||||
import ToastContainer from '../components/Toast';
|
||||
import SidePanelHost, { closeSidePanel } from '../components/SidePanel';
|
||||
import LoadingScreen from '../components/LoadingScreen';
|
||||
import { IconBox, IconNetwork, IconCompare, IconLayers, IconTarget } from '../components/Icons';
|
||||
import '../styles.css';
|
||||
|
||||
const VIEWS = [
|
||||
{ key: 'bom-browser', label: '产品BOM库', icon: IconBox },
|
||||
{ key: 'mining-view', label: '公共组件挖掘', icon: IconNetwork },
|
||||
{ key: 'standard-library', label: '标准组件库', icon: IconLayers },
|
||||
{ key: 'similarity-view', label: '产品相似度', icon: IconCompare },
|
||||
{ key: 'reuse-search', label: '新需求复用', icon: IconTarget },
|
||||
];
|
||||
|
||||
const DATA_SOURCES = [
|
||||
{ key: 'compact-10k', label: '10K 模拟数据', url: '/bomx/bom-data.json' },
|
||||
{ key: 'real-137', label: '137 真实数据', url: '/bomx/bom-data-real.json' },
|
||||
];
|
||||
|
||||
const LOAD_STAGES = [
|
||||
{ key: 'download', label: '下载数据', icon: '↓' },
|
||||
{ key: 'parse', label: '解析 JSON', icon: '{}' },
|
||||
];
|
||||
|
||||
export default function BomxReuseHome() {
|
||||
const navigate = useNavigate();
|
||||
const [current, setCurrent] = useState('bom-browser');
|
||||
const [miningResult, setMiningResult] = useState<any[]>([]);
|
||||
const [thresholds, setThresholds] = useState<any>({ minCoveragePct: 0.5, minNodes: 3 });
|
||||
const [data, setData] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [dataSource, setDataSource] = useState('compact-10k');
|
||||
|
||||
// LoadingScreen 状态
|
||||
const [phase, setPhase] = useState('download');
|
||||
const [stageStatus, setStageStatus] = useState<Record<string, any>>({});
|
||||
const [stageDetail, setStageDetail] = useState<Record<string, any>>({});
|
||||
const [totalBytes, setTotalBytes] = useState(0);
|
||||
const [loadError, setLoadError] = useState<any>(null);
|
||||
const [fadingOut, setFadingOut] = useState(false);
|
||||
|
||||
const loadData = useCallback(async (sourceKey: string) => {
|
||||
setLoading(true);
|
||||
setFadingOut(false);
|
||||
setLoadError(null);
|
||||
setMiningResult([]);
|
||||
setData(null);
|
||||
setStageStatus({});
|
||||
setStageDetail({});
|
||||
setTotalBytes(0);
|
||||
setPhase('download');
|
||||
|
||||
const source = DATA_SOURCES.find(s => s.key === sourceKey);
|
||||
if (!source) return;
|
||||
|
||||
try {
|
||||
// 阶段 1:下载数据
|
||||
setPhase('download');
|
||||
const res = await fetch(source.url);
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const contentLength = parseInt(res.headers.get('content-length') || '0', 10);
|
||||
setTotalBytes(contentLength);
|
||||
setStageStatus(prev => ({ ...prev, download: 'done' }));
|
||||
setStageDetail(prev => ({
|
||||
...prev,
|
||||
download: contentLength ? `${(contentLength / 1024 / 1024).toFixed(1)} MB` : '完成',
|
||||
}));
|
||||
|
||||
// 阶段 2:解析 JSON
|
||||
setPhase('parse');
|
||||
const bomData = await res.json();
|
||||
setStageStatus(prev => ({ ...prev, parse: 'done' }));
|
||||
setStageDetail(prev => ({ ...prev, parse: `${bomData.products.length} 个产品` }));
|
||||
|
||||
setData(bomData);
|
||||
|
||||
// 渐隐过渡
|
||||
setFadingOut(true);
|
||||
await new Promise(r => setTimeout(r, 350));
|
||||
setLoading(false);
|
||||
setFadingOut(false);
|
||||
} catch (e: any) {
|
||||
setLoadError(e.message);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
initStore();
|
||||
loadData(dataSource);
|
||||
}, [dataSource, loadData]);
|
||||
|
||||
const products = data?.products || [];
|
||||
const newRequirements = data?.newRequirements || [];
|
||||
|
||||
return (
|
||||
<div className="bomx-app">
|
||||
<header className="app-header">
|
||||
<span className="app-logo"><img src="/bomx/logo.png" alt="logo" /></span>
|
||||
<h1 className="app-title">企业级BOM标准化治理</h1>
|
||||
<nav className="app-nav">
|
||||
{VIEWS.map(v => {
|
||||
const Icon = v.icon;
|
||||
return (
|
||||
<button
|
||||
key={v.key}
|
||||
className={`nav-btn ${current === v.key ? 'active' : ''}`}
|
||||
onClick={() => { setCurrent(v.key); closeSidePanel(); }}
|
||||
disabled={loading}
|
||||
>
|
||||
<span className="nav-icon"><Icon /></span>
|
||||
{v.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
<button
|
||||
onClick={() => navigate('/')}
|
||||
style={{
|
||||
marginLeft: 'auto', flexShrink: 0,
|
||||
padding: '6px 14px', borderRadius: 8, cursor: 'pointer',
|
||||
border: '1px solid #4F46E5',
|
||||
background: 'rgba(99,102,241,0.08)',
|
||||
color: '#4F46E5', fontSize: 13, fontWeight: 600,
|
||||
transition: 'all 0.18s ease',
|
||||
}}
|
||||
onMouseEnter={e => { e.currentTarget.style.background = 'rgba(99,102,241,0.18)'; }}
|
||||
onMouseLeave={e => { e.currentTarget.style.background = 'rgba(99,102,241,0.08)'; }}
|
||||
>
|
||||
← 返回平台
|
||||
</button>
|
||||
</header>
|
||||
<div className="app-body">
|
||||
{loading ? (
|
||||
<LoadingScreen
|
||||
phase={phase}
|
||||
stageStatus={stageStatus}
|
||||
stageDetail={stageDetail}
|
||||
totalBytes={totalBytes}
|
||||
error={loadError}
|
||||
onRetry={() => loadData(dataSource)}
|
||||
fadingOut={fadingOut}
|
||||
stages={LOAD_STAGES}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<main id="view-container" key={current}>
|
||||
{current === 'bom-browser' && <BomBrowser products={products} />}
|
||||
{current === 'mining-view' && <MiningView products={products} miningResult={miningResult} setMiningResult={setMiningResult} thresholds={thresholds} setThresholds={setThresholds} />}
|
||||
{current === 'similarity-view' && <SimilarityView products={products} miningResult={miningResult} />}
|
||||
{current === 'standard-library' && <StandardLibrary />}
|
||||
{current === 'reuse-search' && <ReuseSearch newRequirements={newRequirements} />}
|
||||
</main>
|
||||
<SidePanelHost />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<ToastContainer />
|
||||
|
||||
{data && (
|
||||
<div className="data-source-switch">
|
||||
<select
|
||||
value={dataSource}
|
||||
onChange={e => setDataSource(e.target.value)}
|
||||
className="data-source-select"
|
||||
>
|
||||
{DATA_SOURCES.map(s => <option key={s.key} value={s.key}>{s.label}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user