上传文件至 Web/src/utils

封装加载系统信息
This commit is contained in:
362270511 2024-12-19 18:07:20 +08:00
parent d05591645a
commit 89c93c0380

58
Web/src/utils/sysInfo.ts Normal file
View File

@ -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,=';
};