| | |
| | | |
| | | import VueDOMPurifyHTML from 'vue-dompurify-html' // 解决v-html 的安全隐患 |
| | | |
| | | import WujieVue from 'wujie-vue3' |
| | | |
| | | const { setupApp } = WujieVue |
| | | |
| | | import { micros, getUrl } from '@/utils/micors' |
| | | |
| | | import lifecycles from '@/utils/lifecycles' // 生命周期函数 |
| | | |
| | | // 创建实例 |
| | | const setupAll = async () => { |
| | | const app = createApp(App) |
| | |
| | | |
| | | app.use(VueDOMPurifyHTML) |
| | | |
| | | app.use(WujieVue) |
| | | |
| | | app.mount('#app') |
| | | } |
| | | |
| | | setupAll() |
| | | |
| | | // 模拟接口查询,实现动动态子应用加载与动态路由添加 |
| | | const setMiro = () => |
| | | new Promise((resolve) => { |
| | | for (const value of micros) { |
| | | const obj: any = { |
| | | path: `/${value.name}`, |
| | | name: value.name, |
| | | component: () => import(`@/views/micro/index.vue`) |
| | | } |
| | | router.addRoute('home', obj) |
| | | setupApp({ |
| | | name: value.name, |
| | | url: getUrl(value.name, micros), |
| | | exec: true, |
| | | ...lifecycles |
| | | }) |
| | | } |
| | | resolve(true) |
| | | }) |
| | | // eslint-disable-next-line require-await |
| | | router.beforeEach(async (to, _from, next) => { |
| | | if (router.getRoutes().length <= 3) { |
| | | // 如果路由个数为基础路由,则说明没有进行路由和子应用添加,需要动态添加,添加完成,根据路由地址进行跳转 |
| | | await setMiro() |
| | | next({ |
| | | path: to.path, |
| | | query: { ...to.query } |
| | | }) |
| | | } else { |
| | | next() |
| | | } |
| | | }) |
| | | |
| | | Logger.prettyPrimary(`欢迎使用`, import.meta.env.VITE_APP_TITLE) |