|
|
@@ -990,10 +990,23 @@ const loadStaticData = async (dashboardType: DashboardType): Promise<SupplyChain
|
|
|
export const SupplyChainProvider: React.FC<SupplyChainProviderProps> = ({
|
|
|
children,
|
|
|
defaultDashboard = 'grain-oil',
|
|
|
- defaultIndustry = '粮食'
|
|
|
+ defaultIndustry
|
|
|
}) => {
|
|
|
+ // 根据组合类型获取默认产业
|
|
|
+ const getDefaultIndustry = (dashboard: DashboardType): IndustryType => {
|
|
|
+ const defaultIndustries: Record<DashboardType, IndustryType> = {
|
|
|
+ 'grain-oil': '粮食',
|
|
|
+ 'seed-fruit': '种业',
|
|
|
+ 'livestock-aquaculture': '畜牧',
|
|
|
+ 'fresh-food-salt': '鲜食'
|
|
|
+ };
|
|
|
+ return defaultIndustries[dashboard];
|
|
|
+ };
|
|
|
+
|
|
|
const [currentDashboard, setCurrentDashboard] = useState<DashboardType>(defaultDashboard);
|
|
|
- const [currentIndustry, setCurrentIndustry] = useState<IndustryType>(defaultIndustry);
|
|
|
+ const [currentIndustry, setCurrentIndustry] = useState<IndustryType>(
|
|
|
+ defaultIndustry || getDefaultIndustry(defaultDashboard)
|
|
|
+ );
|
|
|
const [currentData, setCurrentData] = useState<SupplyChainData | null>(null);
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
@@ -1034,9 +1047,8 @@ export const SupplyChainProvider: React.FC<SupplyChainProviderProps> = ({
|
|
|
const handleSetDashboard = (dashboard: DashboardType) => {
|
|
|
setCurrentDashboard(dashboard);
|
|
|
// 重置当前产业为组合的第一个产业
|
|
|
- if (currentData && currentData.industries.length > 0) {
|
|
|
- setCurrentIndustry(currentData.industries[0]);
|
|
|
- }
|
|
|
+ const newDefaultIndustry = getDefaultIndustry(dashboard);
|
|
|
+ setCurrentIndustry(newDefaultIndustry);
|
|
|
};
|
|
|
|
|
|
// 设置产业
|