|
@@ -1,13 +1,17 @@
|
|
|
import React from 'react';
|
|
import React from 'react';
|
|
|
import BasePointIcon from './icons/BasePointIcon';
|
|
import BasePointIcon from './icons/BasePointIcon';
|
|
|
import SupplyChainIcons from './icons/SupplyChainIcons';
|
|
import SupplyChainIcons from './icons/SupplyChainIcons';
|
|
|
|
|
+import { useSupplyChain } from '../context/SupplyChainContext';
|
|
|
|
|
|
|
|
-// 定义定位点类型
|
|
|
|
|
|
|
+// 定义定位点类型 - 与SupplyChainContext保持一致
|
|
|
interface LocationPoint {
|
|
interface LocationPoint {
|
|
|
id: string;
|
|
id: string;
|
|
|
- type: 'base' | 'industryChain';
|
|
|
|
|
- position: { x: number; y: number };
|
|
|
|
|
|
|
+ type: 'base' | 'chain';
|
|
|
|
|
+ x: number;
|
|
|
|
|
+ y: number;
|
|
|
|
|
+ industry: string;
|
|
|
name?: string;
|
|
name?: string;
|
|
|
|
|
+ data?: Record<string, any>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 定义连接线类型
|
|
// 定义连接线类型
|
|
@@ -32,8 +36,8 @@ const BasePoint: React.FC<{
|
|
|
<div
|
|
<div
|
|
|
className="absolute cursor-pointer transition-transform hover:scale-110"
|
|
className="absolute cursor-pointer transition-transform hover:scale-110"
|
|
|
style={{
|
|
style={{
|
|
|
- left: `${point.position.x}px`,
|
|
|
|
|
- top: `${point.position.y}px`,
|
|
|
|
|
|
|
+ left: `${point.x}px`,
|
|
|
|
|
+ top: `${point.y}px`,
|
|
|
width: '40px',
|
|
width: '40px',
|
|
|
height: '48px'
|
|
height: '48px'
|
|
|
}}
|
|
}}
|
|
@@ -60,8 +64,8 @@ const IndustryChainPoint: React.FC<{
|
|
|
<div
|
|
<div
|
|
|
className="absolute cursor-pointer transition-transform hover:scale-110"
|
|
className="absolute cursor-pointer transition-transform hover:scale-110"
|
|
|
style={{
|
|
style={{
|
|
|
- left: `${point.position.x}px`,
|
|
|
|
|
- top: `${point.position.y}px`,
|
|
|
|
|
|
|
+ left: `${point.x}px`,
|
|
|
|
|
+ top: `${point.y}px`,
|
|
|
width: '40px',
|
|
width: '40px',
|
|
|
height: '48px'
|
|
height: '48px'
|
|
|
}}
|
|
}}
|
|
@@ -85,8 +89,8 @@ const ConnectionLine: React.FC<{
|
|
|
toPoint: LocationPoint;
|
|
toPoint: LocationPoint;
|
|
|
}> = ({ fromPoint, toPoint }) => {
|
|
}> = ({ fromPoint, toPoint }) => {
|
|
|
// 计算连接线的位置和角度
|
|
// 计算连接线的位置和角度
|
|
|
- const dx = toPoint.position.x - fromPoint.position.x;
|
|
|
|
|
- const dy = toPoint.position.y - fromPoint.position.y;
|
|
|
|
|
|
|
+ const dx = toPoint.x - fromPoint.x;
|
|
|
|
|
+ const dy = toPoint.y - fromPoint.y;
|
|
|
const length = Math.sqrt(dx * dx + dy * dy);
|
|
const length = Math.sqrt(dx * dx + dy * dy);
|
|
|
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
|
|
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
|
|
|
|
|
|
|
@@ -94,8 +98,8 @@ const ConnectionLine: React.FC<{
|
|
|
<div
|
|
<div
|
|
|
className="absolute pointer-events-none"
|
|
className="absolute pointer-events-none"
|
|
|
style={{
|
|
style={{
|
|
|
- left: `${fromPoint.position.x + 20}px`,
|
|
|
|
|
- top: `${fromPoint.position.y + 24}px`,
|
|
|
|
|
|
|
+ left: `${fromPoint.x + 20}px`,
|
|
|
|
|
+ top: `${fromPoint.y + 24}px`,
|
|
|
width: `${length}px`,
|
|
width: `${length}px`,
|
|
|
height: '2px',
|
|
height: '2px',
|
|
|
transform: `rotate(${angle}deg)`,
|
|
transform: `rotate(${angle}deg)`,
|
|
@@ -146,21 +150,14 @@ const SupplyChainMap: React.FC<SupplyChainMapProps> = ({
|
|
|
points = [],
|
|
points = [],
|
|
|
onPointClick
|
|
onPointClick
|
|
|
}) => {
|
|
}) => {
|
|
|
- // 默认定位点数据
|
|
|
|
|
- const defaultPoints: LocationPoint[] = [
|
|
|
|
|
- { id: 'base1', type: 'base', position: { x: 1142.89, y: 717.84 }, name: '基地1' },
|
|
|
|
|
- { id: 'base2', type: 'base', position: { x: 1664.25, y: 530.82 }, name: '基地2' },
|
|
|
|
|
- { id: 'base3', type: 'base', position: { x: 1435, y: 527.14 }, name: '基地3' },
|
|
|
|
|
- { id: 'base4', type: 'base', position: { x: 1203.07, y: 514.31 }, name: '基地4' },
|
|
|
|
|
- { id: 'chain1', type: 'industryChain', position: { x: 1273.12, y: 551.14 }, name: '产业链1' },
|
|
|
|
|
- { id: 'chain2', type: 'industryChain', position: { x: 1403, y: 597.5 }, name: '产业链2' },
|
|
|
|
|
- { id: 'chain3', type: 'industryChain', position: { x: 1694.25, y: 645.5 }, name: '产业链3' },
|
|
|
|
|
- { id: 'chain4', type: 'industryChain', position: { x: 1237.87, y: 761.84 }, name: '产业链4' }
|
|
|
|
|
- ];
|
|
|
|
|
|
|
+ // 使用SupplyChainContext获取动态数据
|
|
|
|
|
+ const { currentData, currentIndustry } = useSupplyChain();
|
|
|
|
|
|
|
|
|
|
+ // 从context获取当前产业的定位点数据
|
|
|
|
|
+ const dynamicPoints = currentData?.mapPoints[currentIndustry] || [];
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- const displayPoints = points.length > 0 ? points : defaultPoints;
|
|
|
|
|
|
|
+ // 优先使用传入的points,否则使用动态数据
|
|
|
|
|
+ const displayPoints = points.length > 0 ? points : dynamicPoints;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="absolute contents left-[529.88px] top-[calc(50%+64.03px)] translate-y-[-50%]">
|
|
<div className="absolute contents left-[529.88px] top-[calc(50%+64.03px)] translate-y-[-50%]">
|
|
@@ -197,7 +194,7 @@ const SupplyChainMap: React.FC<SupplyChainMapProps> = ({
|
|
|
onClick={onPointClick}
|
|
onClick={onPointClick}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
- } else {
|
|
|
|
|
|
|
+ } else if (point.type === 'chain') {
|
|
|
return (
|
|
return (
|
|
|
<IndustryChainPoint
|
|
<IndustryChainPoint
|
|
|
key={point.id}
|
|
key={point.id}
|
|
@@ -206,6 +203,7 @@ const SupplyChainMap: React.FC<SupplyChainMapProps> = ({
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
+ return null;
|
|
|
})}
|
|
})}
|
|
|
|
|
|
|
|
{/* 图例 */}
|
|
{/* 图例 */}
|