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

73 lines
1.8 KiB
TypeScript
Raw Normal View History

import { createApp, watchEffect } from 'vue';
2024-05-24 23:11:03 +08:00
2024-07-30 21:10:28 +08:00
import { registerAccessDirective } from '@vben/access';
import { registerLoadingDirective } from '@vben/common-ui/es/loading';
import { preferences } from '@vben/preferences';
2024-07-30 21:10:28 +08:00
import { initStores } from '@vben/stores';
2024-06-08 19:49:06 +08:00
import '@vben/styles';
import '@vben/styles/antd';
2024-06-01 23:15:29 +08:00
import { useTitle } from '@vueuse/core';
import { $t, setupI18n } from '#/locales';
2024-05-24 23:11:03 +08:00
import { initComponentAdapter } from './adapter/component';
2024-05-24 23:11:03 +08:00
import App from './app.vue';
import { router } from './router';
async function bootstrap(namespace: string) {
// 初始化组件适配器
await initComponentAdapter();
// // 设置弹窗的默认配置
// setDefaultModalProps({
// fullscreenButton: false,
// });
// // 设置抽屉的默认配置
// setDefaultDrawerProps({
// zIndex: 1020,
// });
2024-05-24 23:11:03 +08:00
const app = createApp(App);
// 注册v-loading指令
registerLoadingDirective(app, {
loading: 'loading', // 在这里可以自定义指令名称也可以明确提供false表示不注册这个指令
spinning: 'spinning',
});
2024-05-24 23:11:03 +08:00
// 国际化 i18n 配置
await setupI18n(app);
2024-05-24 23:11:03 +08:00
// 配置 pinia-tore
2024-07-30 21:10:28 +08:00
await initStores(app, { namespace });
2024-05-24 23:11:03 +08:00
// 安装权限指令
2024-07-30 21:10:28 +08:00
registerAccessDirective(app);
// 初始化 tippy
const { initTippy } = await import('@vben/common-ui/es/tippy');
initTippy(app);
2024-05-24 23:11:03 +08:00
// 配置路由及路由守卫
app.use(router);
// 配置Motion插件
const { MotionPlugin } = await import('@vben/plugins/motion');
app.use(MotionPlugin);
// 动态更新标题
watchEffect(() => {
if (preferences.app.dynamicTitle) {
const routeTitle = router.currentRoute.value.meta?.title;
const pageTitle =
(routeTitle ? `${$t(routeTitle)} - ` : '') + preferences.app.name;
useTitle(pageTitle);
}
});
2024-05-24 23:11:03 +08:00
app.mount('#app');
}
export { bootstrap };