admin-vben5/apps/web-antd/src/main.ts

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-06-01 23:15:29 +08:00
import { preferencesManager } from '@vben-core/preferences';
2024-05-19 21:20:42 +08:00
2024-06-01 23:15:29 +08:00
import { overridesPreferences } from './preferences';
2024-05-19 21:20:42 +08:00
2024-05-24 23:11:03 +08:00
/**
*
*/
async function initApplication() {
2024-06-01 23:15:29 +08:00
// name用于指定项目唯一标识
// 用于区分不同项目的偏好设置以及存储数据的key前缀以及其他一些需要隔离的数据
2024-05-24 23:11:03 +08:00
const env = import.meta.env.PROD ? 'prod' : 'dev';
const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${env}`;
2024-05-24 23:11:03 +08:00
// app偏好设置初始化
2024-06-01 23:15:29 +08:00
await preferencesManager.initPreferences({
2024-05-24 23:11:03 +08:00
namespace,
2024-06-01 23:15:29 +08:00
overrides: overridesPreferences,
2024-05-19 21:20:42 +08:00
});
// 启动应用并挂载
// vue应用主要逻辑及视图
const { bootstrap } = await import('./bootstrap');
await bootstrap(namespace);
// 移除并销毁loading
destoryAppLoading();
}
/**
* loading
* index.html app标签内
* css动画隐藏loading节点来改善体验
*/
function destoryAppLoading() {
// 全局搜索文件 loading.html, 找到对应的节点
const loadingElement = document.querySelector('#__app-loading__');
if (loadingElement) {
loadingElement.classList.add('hidden');
const injectLoadingElements = document.querySelectorAll(
'[data-app-loading^="inject"]',
);
// 过渡动画结束后移除loading节点
loadingElement.addEventListener(
'transitionend',
() => {
loadingElement.remove();
injectLoadingElements.forEach((el) => el?.remove());
},
{ once: true },
);
}
2024-05-19 21:20:42 +08:00
}
2024-05-24 23:11:03 +08:00
initApplication();