bootstrap.ts 1.9 KB

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