2025-09-01 18:09:56 +08:00
|
|
|
|
import { createApp, watchEffect } from 'vue'
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
import { registerAccessDirective } from '@vben/access'
|
|
|
|
|
import { registerLoadingDirective } from '@vben/common-ui/es/loading'
|
|
|
|
|
import { preferences } from '@vben/preferences'
|
|
|
|
|
import { initStores } from '@vben/stores'
|
|
|
|
|
import '@vben/styles'
|
|
|
|
|
import '@vben/styles/antd'
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
import { useTitle } from '@vueuse/core'
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
import { setupGlobalComponent } from '#/components/global'
|
|
|
|
|
import { $t, setupI18n } from '#/locales'
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
import { initComponentAdapter } from './adapter/component'
|
|
|
|
|
import { initSetupVbenForm } from './adapter/form'
|
|
|
|
|
import App from './app.vue'
|
|
|
|
|
import { router } from './router'
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-08-16 17:58:59 +08:00
|
|
|
|
|
|
|
|
|
|
2025-06-18 11:03:42 +08:00
|
|
|
|
async function bootstrap(namespace: string) {
|
|
|
|
|
// 初始化组件适配器
|
2025-09-01 18:09:56 +08:00
|
|
|
|
await initComponentAdapter()
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// 初始化表单组件
|
2025-09-01 18:09:56 +08:00
|
|
|
|
await initSetupVbenForm()
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// // 设置弹窗的默认配置
|
|
|
|
|
// setDefaultModalProps({
|
|
|
|
|
// fullscreenButton: false,
|
|
|
|
|
// });
|
|
|
|
|
// // 设置抽屉的默认配置
|
|
|
|
|
// setDefaultDrawerProps({
|
|
|
|
|
// zIndex: 1020,
|
|
|
|
|
// });
|
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
|
|
|
|
|
const app = createApp(App)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// 全局组件
|
2025-09-01 18:09:56 +08:00
|
|
|
|
setupGlobalComponent(app)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
// 注册v-loading指令
|
|
|
|
|
registerLoadingDirective(app, {
|
|
|
|
|
loading: 'loading', // 在这里可以自定义指令名称,也可以明确提供false表示不注册这个指令
|
|
|
|
|
spinning: 'spinning',
|
2025-09-01 18:09:56 +08:00
|
|
|
|
})
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-08-16 17:58:59 +08:00
|
|
|
|
|
2025-06-18 11:03:42 +08:00
|
|
|
|
// 国际化 i18n 配置
|
2025-09-01 18:09:56 +08:00
|
|
|
|
await setupI18n(app)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// 配置 pinia-tore
|
2025-09-01 18:09:56 +08:00
|
|
|
|
await initStores(app, { namespace })
|
|
|
|
|
|
2025-06-18 11:03:42 +08:00
|
|
|
|
// 安装权限指令
|
2025-09-01 18:09:56 +08:00
|
|
|
|
registerAccessDirective(app)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// 初始化 tippy
|
2025-09-01 18:09:56 +08:00
|
|
|
|
const { initTippy } = await import('@vben/common-ui/es/tippy')
|
|
|
|
|
initTippy(app)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// 配置路由及路由守卫
|
2025-09-01 18:09:56 +08:00
|
|
|
|
app.use(router)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-08-16 17:58:59 +08:00
|
|
|
|
|
2025-06-18 11:03:42 +08:00
|
|
|
|
// 配置Motion插件
|
2025-09-01 18:09:56 +08:00
|
|
|
|
const { MotionPlugin } = await import('@vben/plugins/motion')
|
|
|
|
|
app.use(MotionPlugin)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
|
|
|
|
// 动态更新标题
|
|
|
|
|
watchEffect(() => {
|
|
|
|
|
if (preferences.app.dynamicTitle) {
|
2025-09-01 18:09:56 +08:00
|
|
|
|
const routeTitle = router.currentRoute.value.meta?.title
|
2025-06-18 11:03:42 +08:00
|
|
|
|
const pageTitle =
|
2025-09-01 18:09:56 +08:00
|
|
|
|
(routeTitle ? `${$t(routeTitle)} - ` : '') + preferences.app.name
|
|
|
|
|
useTitle(pageTitle)
|
2025-06-18 11:03:42 +08:00
|
|
|
|
}
|
2025-09-01 18:09:56 +08:00
|
|
|
|
})
|
2025-06-18 11:03:42 +08:00
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
app.mount('#app')
|
2025-06-18 11:03:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 18:09:56 +08:00
|
|
|
|
export { bootstrap }
|