52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
// src/contexts/IndustryContext.js
|
|
// 行业分类数据全局上下文 - 直接使用静态数据
|
|
|
|
import React, { createContext, useContext } from 'react';
|
|
import { industryData as staticIndustryData } from '../data/industryData';
|
|
import { logger } from '../utils/logger';
|
|
|
|
const IndustryContext = createContext();
|
|
|
|
/**
|
|
* useIndustry Hook
|
|
* 在任何组件中使用行业数据
|
|
*/
|
|
export const useIndustry = () => {
|
|
const context = useContext(IndustryContext);
|
|
if (!context) {
|
|
throw new Error('useIndustry must be used within IndustryProvider');
|
|
}
|
|
return context;
|
|
};
|
|
|
|
/**
|
|
* IndustryProvider 组件
|
|
* 提供全局行业数据管理 - 直接使用静态数据,无需加载
|
|
*/
|
|
export const IndustryProvider = ({ children }) => {
|
|
// 直接使用静态数据,无需状态管理
|
|
const industryData = staticIndustryData;
|
|
|
|
logger.debug('IndustryContext', '使用静态行业数据', {
|
|
count: industryData?.length || 0
|
|
});
|
|
|
|
const value = {
|
|
industryData, // 行业数据(静态)
|
|
loading: false, // 静态数据无需加载
|
|
error: null, // 静态数据无错误
|
|
loadIndustryData: () => { // 兼容旧接口,返回数据
|
|
return Promise.resolve(industryData);
|
|
},
|
|
refreshIndustryData: () => { // 兼容旧接口,返回数据
|
|
return Promise.resolve(industryData);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<IndustryContext.Provider value={value}>
|
|
{children}
|
|
</IndustryContext.Provider>
|
|
);
|
|
};
|