bootstrap.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { createApp, watchEffect } from 'vue';
  2. import { registerAccessDirective } from '@vben/access';
  3. import { initTippy, registerLoadingDirective } 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. // 注册Vben提供的v-loading和v-spinning指令
  30. registerLoadingDirective(app, {
  31. loading: false, // Vben提供的v-loading指令和Element Plus提供的v-loading指令二选一即可,此处false表示不注册Vben提供的v-loading指令
  32. spinning: 'spinning',
  33. });
  34. // 国际化 i18n 配置
  35. await setupI18n(app);
  36. // 配置 pinia-tore
  37. await initStores(app, { namespace });
  38. // 安装权限指令
  39. registerAccessDirective(app);
  40. // 初始化 tippy
  41. initTippy(app);
  42. // 配置路由及路由守卫
  43. app.use(router);
  44. // 配置Motion插件
  45. app.use(MotionPlugin);
  46. // 动态更新标题
  47. watchEffect(() => {
  48. if (preferences.app.dynamicTitle) {
  49. const routeTitle = router.currentRoute.value.meta?.title;
  50. const pageTitle =
  51. (routeTitle ? `${$t(routeTitle)} - ` : '') + preferences.app.name;
  52. useTitle(pageTitle);
  53. }
  54. });
  55. app.mount('#app');
  56. }
  57. export { bootstrap };