Files
SEONexus/code/public/template/shikong/huiyuan/js/class/config.js
2025-04-21 17:49:17 +08:00

50 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import EncAndDec from '../public/enc.js'
/**
* 后台-网站配置数据
*/
class Configs {
constructor() {
// 初始化配置数据
this.arrConfigs = this.getAll();
}
// 添加或更新配置项
set(key, value) {
this.arrConfigs[key] = value;
}
/**
* 获取配置项
* @param {string} strKey
* @param {string} strType
* @returns string | int | null
*/
get(strKey,strType=null) {
return
let intIndex = this.arrConfigs.findIndex((item) => strKey == item.conf_code)
let strVal = intIndex != -1 ? this.arrConfigs[intIndex].conf_val : null;
if(strType == 'int' && strVal != null)[
strVal = parseInt(strVal)
]
return strVal;
}
// 读取所有配置数据
getAll() {
return
let configEncoded = EncAndDec.decryptData(configEncodedData, configDecData.MIAO_API_ENCRYPT_KEY);
configEncoded = JSON.parse(configEncoded)
return configEncoded.data;
}
}
export default Configs ;
// 使用示例
// var configs = new Configs();
// console.log(Configs.get('PLAY_CCTV_OPENING_TIME','int'));
// console.log(configs.get('PLAY_CCTV_OPENING_TIME','int')); // 输出特定配置blue