Merge pull request '加载系统信息放到页面初始化前' (#209) from 362270511/Admin.NET.Pro:main into main

Reviewed-on: http://101.43.53.74:3000/Admin.NET/Admin.NET.Pro/pulls/209
This commit is contained in:
zuohuaijun 2024-12-20 02:16:12 +08:00
commit f76e4e7d36
3 changed files with 71 additions and 64 deletions

View File

@ -99,65 +99,6 @@ watch(
}
);
//
const loadSysInfo = () => {
getAPI(SysConfigApi)
.apiSysConfigSysInfoGet()
.then((res) => {
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.forceChangePassword = data.sysForceChangePassword;
//
themeConfig.value.passwordExpirationTime = data.sysPasswordExpirationTime;
//
window.__env__.VITE_SM_PUBLIC_KEY = data.publicKey;
// favicon
updateFavicon(data.sysLogo);
//
Local.remove('themeConfig');
Local.set('themeConfig', storesThemeConfig.themeConfig);
})
.catch(() => {
// logo
themeConfig.value.logoUrl = '';
//
Local.remove('themeConfig');
Local.set('themeConfig', storesThemeConfig.themeConfig);
return;
});
};
// favicon
const updateFavicon = (url: string): void => {
const favicon = document.getElementById('favicon') as HTMLAnchorElement;
favicon!.href = url ? url : 'data:;base64,=';
};
//
loadSysInfo();
//
document.body.ondrop = function (event) {

View File

@ -26,11 +26,19 @@ import JwChat from 'jwchat';
import 'jwchat/lib/style.css';
// 关闭自动打印
import { disAutoConnect } from 'vue-plugin-hiprint';
import { loadSysInfo } from '/@/utils/sysInfo';
disAutoConnect();
//加载系统信息放在app.vue会和挂载router产生异步冲突
//由于挂载的机制是异步的,导致还没有获取到数据库的系统信息的时候,【密码加解密公匙】则一直为空(特别是在网络不好的情况下)
//由于获取验证码需要【密码加解密公匙】信息,如果没有则会一直刷新页面,导致登录页面会一直刷新
async function initApp() {
// 加载系统信息
await loadSysInfo();
const app = createApp(App);
const app = createApp(App);
directive(app);
other.elSvg(app);
directive(app);
other.elSvg(app);
app.use(pinia).use(router).use(ElementPlus).use(setupVXETable).use(i18n).use(VueGridLayout).use(VForm3).use(VueSignaturePad).use(vue3TreeOrg).use(JwChat).mount('#app');
app.use(pinia).use(router).use(ElementPlus).use(setupVXETable).use(i18n).use(VueGridLayout).use(VForm3).use(VueSignaturePad).use(vue3TreeOrg).use(JwChat).mount('#app');
}
initApp();

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