bootstrap.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/naive';
  9. import { useTitle } from '@vueuse/core';
  10. import { $t, setupI18n } from '#/locales';
  11. import { initComponentAdapter } from './adapter/component';
  12. import App from './app.vue';
  13. import { router } from './router';
  14. async function bootstrap(namespace: string) {
  15. // 初始化组件适配器
  16. initComponentAdapter();
  17. // // 设置弹窗的默认配置
  18. // setDefaultModalProps({
  19. // fullscreenButton: false,
  20. // });
  21. // // 设置抽屉的默认配置
  22. // setDefaultDrawerProps({
  23. // // zIndex: 2000,
  24. // });
  25. const app = createApp(App);
  26. // 注册v-loading指令
  27. registerLoadingDirective(app, {
  28. loading: 'loading', // 在这里可以自定义指令名称,也可以明确提供false表示不注册这个指令
  29. spinning: 'spinning',
  30. });
  31. // 国际化 i18n 配置
  32. await setupI18n(app);
  33. // 配置 pinia-tore
  34. await initStores(app, { namespace });
  35. // 安装权限指令
  36. registerAccessDirective(app);
  37. // 初始化 tippy
  38. initTippy(app);
  39. // 配置路由及路由守卫
  40. app.use(router);
  41. // 配置Motion插件
  42. app.use(MotionPlugin);
  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 };