You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 lines
1.4 KiB

// 配置管理工具
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();