diff --git a/Web/src/utils/sysInfo.ts b/Web/src/utils/sysInfo.ts new file mode 100644 index 00000000..32814b1a --- /dev/null +++ b/Web/src/utils/sysInfo.ts @@ -0,0 +1,58 @@ +import { Local } from '/@/utils/storage'; +import { storeToRefs } from 'pinia'; +import { useThemeConfig } from '/@/stores/themeConfig'; +const storesThemeConfig = useThemeConfig(); +const { themeConfig } = storeToRefs(storesThemeConfig); +import { SysConfigApi } from '/@/api-services'; +import { feature, getAPI } from '/@/utils/axios-utils'; +// 加载系统信息 +export async function loadSysInfo () { + const [err, res] = await feature(getAPI(SysConfigApi).apiSysConfigSysInfoGet()); + if (err) { + // 置空 logo 地址 + themeConfig.value.logoUrl = ''; + // 保存配置 + Local.remove('themeConfig'); + Local.set('themeConfig', storesThemeConfig.themeConfig); + return; + } else { + if (res.data.type != 'success') return; + + const data = res.data.result; + // 系统logo + themeConfig.value.logoUrl = data.sysLogo; + // 主标题 + themeConfig.value.globalTitle = data.sysTitle; + // 副标题 + themeConfig.value.globalViceTitle = data.sysViceTitle; + // 系统说明 + themeConfig.value.globalViceTitleMsg = data.sysViceDesc; + // Icp备案信息 + themeConfig.value.icp = data.sysIcp; + themeConfig.value.icpUrl = data.sysIcpUrl; + // 水印 + themeConfig.value.isWatermark = data.sysWatermark != null; + themeConfig.value.watermarkText = data.sysWatermark; + // 版权说明 + themeConfig.value.copyright = data.sysCopyright; + // 登录验证 + themeConfig.value.secondVer = data.sysSecondVer; + themeConfig.value.captcha = data.sysCaptcha; + // 开启强制修改密码 + themeConfig.value.sysForceChangePassword = data.sysForceChangePassword; + // 密码加解密公匙 + window.__env__.VITE_SM_PUBLIC_KEY = data.publicKey; + // 更新 favicon + updateFavicon(data.sysLogo); + + // 保存配置 + Local.remove('themeConfig'); + Local.set('themeConfig', storesThemeConfig.themeConfig); + } +}; + +// 更新 favicon +const updateFavicon = (url: string): void => { + const favicon = document.getElementById('favicon') as HTMLAnchorElement; + favicon!.href = url ? url : 'data:;base64,='; +}; \ No newline at end of file