bootstrap.ts 1.6 KB

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