From b45bad33154fb97b76e6c54a86609d446f02ad21 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期四, 10 十月 2024 14:22:44 +0800
Subject: [PATCH] 分页bug修复,打包历史发布功能

---
 src/main.ts |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/main.ts b/src/main.ts
index 76c7247..6065dc7 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -42,6 +42,14 @@
 
 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)
@@ -64,9 +72,44 @@
 
   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)

--
Gitblit v1.9.3