bootstrap.ts 2.1 KB

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