import { Local } from "@/utils/storage";

let defaultConfig__ = require('@/utils/config/defaultConfig').default;
const SYSTEM_SET = "system_set_config__";
const isInstalled = () => {
  try {
    require('@/SystemConfig.json')
    return true;
  } catch (err) {
    return false;
  }
};

if (isInstalled()) {
  const customSystemConfig = require('@/SystemConfig.json');
  Local.set(SYSTEM_SET, Object.assign(defaultConfig__, customSystemConfig));
}

/**
 * 导出自定义的配置信息
 * @param systemConfig
 * @returns {{adminAccess: string, secretKey: string, adminUser: string, secretValue: string, systemConfig: string, loginTitle: string, language: string, loginPage: string, indexTitle: string, token: string, defaultLang: string}}
 */
export function initSystemConfig(systemConfig) {
  const config = Object.assign({}, defaultConfig__, systemConfig || {});
  Local.set(SYSTEM_SET, config)
}

/**
 * 导入默认的配置
 */
const defaultConfig = Local.get(SYSTEM_SET);
export default defaultConfig;