bootstrap.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { createApp, watchEffect } from 'vue';
  2. import { registerAccessDirective } from '@vben/access';
  3. import {
  4. initTippy,
  5. setDefaultDrawerProps,
  6. setDefaultModalProps,
  7. } from '@vben/common-ui';
  8. import { preferences } from '@vben/preferences';
  9. import { initStores } from '@vben/stores';
  10. import '@vben/styles';
  11. import '@vben/styles/ele';
  12. import { useTitle } from '@vueuse/core';
  13. import { ElLoading } from 'element-plus';
  14. import { $t, setupI18n } from '#/locales';
  15. import { initComponentAdapter } from './adapter/component';
  16. import App from './app.vue';
  17. import { router } from './router';
  18. async function bootstrap(namespace: string) {
  19. // 初始化组件适配器
  20. await initComponentAdapter();
  21. // 设置弹窗的默认配置
  22. setDefaultModalProps({
  23. fullscreenButton: false,
  24. zIndex: 2000,
  25. });
  26. // 设置抽屉的默认配置
  27. setDefaultDrawerProps({
  28. zIndex: 2000,
  29. });
  30. const app = createApp(App);
  31. // 注册Element Plus提供的v-loading指令
  32. app.directive('loading', ElLoading.directive);
  33. // 国际化 i18n 配置
  34. await setupI18n(app);
  35. // 配置 pinia-tore
  36. await initStores(app, { namespace });
  37. // 安装权限指令
  38. registerAccessDirective(app);
  39. // 初始化 tippy
  40. initTippy(app);
  41. // 配置路由及路由守卫
  42. app.use(router);
  43. // 动态更新标题
  44. watchEffect(() => {
  45. if (preferences.app.dynamicTitle) {
  46. const routeTitle = router.currentRoute.value.meta?.title;
  47. const pageTitle =
  48. (routeTitle ? `${$t(routeTitle)} - ` : '') + preferences.app.name;
  49. useTitle(pageTitle);
  50. }
  51. });
  52. app.mount('#app');
  53. }
  54. export { bootstrap };