父史诗: 史诗005 - 史诗005 - 供应链可视化大屏实现 docs/prd/epic-005-supply-chain-visualization.md
In Progress
As a 前端开发者
I want 组件能够动态加载SupplyChainContext中的种业-果蔬组合数据
so that 用户可以通过路由参数/supply-chain/seed-fruit访问种业-果蔬组合大屏,并看到基于动态数据的完整供应链地图可视化、关键指标和数据卡片
Scope: 修改现有组件以动态加载SupplyChainContext中的种业-果蔬组合数据,包括定位点坐标、关键指标、供应链网络和弹出框数据
/supply-chain/seed-fruit正确加载种业-果蔬数据src/client/home/pages/SupplyChainDashboards/context/SupplyChainContext.tsxsrc/client/home/pages/SupplyChainDashboards/components/src/share/types.ts (共享类型)tests/unit/client/home/pages/SupplyChainDashboards/context/// 组合类型定义
type DashboardType = 'grain-oil' | 'seed-fruit' | 'livestock-aquaculture' | 'fresh-food-salt';
// 产业类型定义(继承自现有ThemeContext)
type IndustryType = "粮食" | "油脂" | "种业" | "果蔬" | "畜牧" | "水产" | "鲜食" | "泛盐";
// 定位点坐标接口
interface LocationPoint {
id: string;
type: 'base' | 'chain';
x: number;
y: number;
industry: IndustryType;
name?: string;
data?: Record<string, any>;
}
// 关键指标数据接口
interface MetricData {
id: string;
label: string;
value: string | number;
unit?: string;
industry: IndustryType;
}
// 供应链网络数据接口
interface SupplyChainNetwork {
connections: Array<{
from: string;
to: string;
type: string;
}>;
nodes: Record<string, LocationPoint>;
}
// 弹出框数据接口
interface PopupData {
id: string;
title: string;
content: string;
position: { x: number; y: number };
industry: IndustryType;
}
// 供应链数据接口
interface SupplyChainData {
// 组合名称
name: string;
// 支持的产业
industries: IndustryType[];
// 定位点数据
mapPoints: Record<IndustryType, LocationPoint[]>;
// 关键指标数据
keyMetrics: Record<IndustryType, MetricData[]>;
// 供应链网络数据
supplyChainNetwork: Record<IndustryType, SupplyChainNetwork>;
// 弹出框数据
popupData: Record<IndustryType, PopupData[]>;
}
src/client/home/pages/SupplyChainDashboards/components/SupplyChainMap.tsxsrc/client/home/pages/SupplyChainDashboards/components/KeyMetrics.tsxsrc/client/home/pages/SupplyChainDashboards/components/PopupInfoBox.tsxseed-popup1、fruit-popup1)// 正确的数据获取方式
const { currentData, currentIndustry } = useSupplyChain();
// 获取当前产业的定位点数据
const mapPoints = currentData?.mapPoints[currentIndustry] || [];
// 获取当前产业的关键指标数据
const keyMetrics = currentData?.keyMetrics[currentIndustry] || [];
款式分配规则:
定位逻辑:
// 根据定位点索引确定款式和定位方式
const getPopupStyle = (pointIndex: number) => {
const isFirstStyle = pointIndex % 2 === 0; // 偶数索引使用第一款,奇数索引使用第二款
return {
variant: isFirstStyle ? 'first' : 'second',
anchor: isFirstStyle ? 'bottom-right' : 'top-right'
};
};
实现策略:
使用@tanstack/react-query进行服务端状态管理,实现数据获取、缓存和同步:
// React Query配置
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 5 * 60 * 1000, // 5分钟
gcTime: 10 * 60 * 1000, // 10分钟
},
},
});
// 数据查询Hook
const useSupplyChainData = (dashboardType: DashboardType) => {
return useQuery({
queryKey: ['supply-chain', dashboardType],
queryFn: () => loadStaticData(dashboardType),
enabled: !!dashboardType,
});
};
基于现有SupplyChainContext数据,修改组件使用动态数据:
// SupplyChainMap组件修改示例
const SupplyChainMap: React.FC<SupplyChainMapProps> = ({ onPointClick }) => {
const { currentData, currentIndustry } = useSupplyChain();
// 从context获取当前产业的定位点数据
const mapPoints = currentData?.mapPoints[currentIndustry] || [];
return (
<div className="supply-chain-map">
{mapPoints.map(point => (
<MapPoint
key={point.id}
point={point}
onClick={() => onPointClick(point)}
/>
))}
</div>
);
};
// KeyMetrics组件修改示例
const KeyMetrics: React.FC<KeyMetricsProps> = ({ title, subtitle }) => {
const { currentData, currentIndustry } = useSupplyChain();
// 从context获取当前产业的关键指标数据
const keyMetrics = currentData?.keyMetrics[currentIndustry] || [];
return (
<div className="key-metrics">
{keyMetrics.map(metric => (
<DataCard
key={metric.id}
title={metric.label}
value={metric.value}
unit={metric.unit}
/>
))}
</div>
);
};
SupplyChainMap组件修改步骤:
KeyMetrics组件修改步骤:
tests/unit/client/home/pages/SupplyChainDashboards/context//supply-chain/seed-fruit正确解析| Date | Version | Description | Author |
|---|---|---|---|
| 2025-11-16 | 1.0 | 初始故事创建,基于Epic 005需求 | Bob (SM) |
/supply-chain/:dashboardType已支持seed-fruit组合src/client/home/pages/SupplyChainDashboards/components/SupplyChainMap.tsx - 需要修改为使用动态定位点数据src/client/home/pages/SupplyChainDashboards/components/KeyMetrics.tsx - 需要修改为使用动态关键指标数据src/client/home/pages/SupplyChainDashboards/components/PopupInfoBox.tsx - ✅ 已修改为使用动态弹出框数据,并建立定位点ID与弹出框数据的映射关系,添加双款式支持和定位逻辑src/client/home/pages/SupplyChainDashboards/components/icons/PopupInfoBox2.tsx - ✅ 已修复SVG属性语法src/client/home/pages/SupplyChainDashboards/context/SupplyChainContext.tsx - ✅ 已为所有4个组合的49个定位点添加对应的弹出框数据,并移除重复的坐标定义src/client/home/pages/SupplyChainDashboards/context/SupplyChainContext.tsx - 包含完整的种业-果蔬组合数据src/client/home/routes.tsx - 动态路由配置src/client/home/pages/SupplyChainDashboards/SupplyChainDashboard.tsx - 统一组件已支持所有组合