// 配置管理工具 export class ConfigManager { constructor() { this.config = null; } // 异步加载配置文件 async loadConfig() { try { const response = await fetch('/config.json'); if (!response.ok) { throw new Error('Failed to load config'); } this.config = await response.json(); return this.config; } catch (error) { console.error('Error loading config:', error); // 返回默认配置 return this.getDefaultConfig(); } } // 获取默认配置 getDefaultConfig() { return { screen: { width: 5120, height: 1440, title: "智慧活畜交易大数据中心" }, dashboard: { refreshInterval: 5000, animationDuration: 300 } }; } // 获取屏幕配置 getScreenConfig() { return this.config?.screen || this.getDefaultConfig().screen; } // 获取仪表板配置 getDashboardConfig() { return this.config?.dashboard || this.getDefaultConfig().dashboard; } // 设置CSS变量 setCSSVariables() { const screenConfig = this.getScreenConfig(); const root = document.documentElement; root.style.setProperty('--screen-width', `${screenConfig.width}px`); root.style.setProperty('--screen-height', `${screenConfig.height}px`); } } // 创建全局配置管理器实例 export const configManager = new ConfigManager();