lighter 1 год назад
Родитель
Сommit
e844182ed0
4 измененных файлов с 121 добавлено и 19 удалено
  1. 8 1
      src/App.vue
  2. 7 6
      src/layout/MenuV2/MenuV2.vue
  3. 104 12
      src/router/index.ts
  4. 2 0
      src/views/medical-insurance/inpatient/Home.vue

+ 8 - 1
src/App.vue

@@ -1,5 +1,12 @@
 <template>
-  <router-view/>
+<!--  <router-view/>-->
+
+  <router-view v-slot="{ Component }">
+    <keep-alive>
+      <component :is="Component"/>
+    </keep-alive>
+  </router-view>
+
   <soctet-dialog v-if="socketErrDialog"/>
   <progress-bar/>
   <JsDialogComp/>

+ 7 - 6
src/layout/MenuV2/MenuV2.vue

@@ -3,12 +3,13 @@
     <div>
       <Logo :show-logo="!isCollapse"/>
       <div style="height: 30px; padding: 0 8px 8px 8px" @click="expandMenu" id="tutorial_search_menu">
-        <el-input ref="searchRef"
-                  v-model="menuText"
-                  prefix-icon="Search"
-                  clearable
-                  @input="searchInput"
-                  placeholder="菜单太难找?在这里搜索。"/>
+        <el-input
+            ref="searchRef"
+            v-model="menuText"
+            prefix-icon="Search"
+            clearable
+            @input="searchInput"
+            placeholder="菜单太难找?在这里搜索。"/>
       </div>
     </div>
 

+ 104 - 12
src/router/index.ts

@@ -16,7 +16,6 @@ import {createVNode, defineComponent, h, Ref} from "vue";
 import {stringNotBlank} from "@/utils/blank-utils";
 import {useUserStore} from "@/pinia/user-store";
 
-
 const router = createRouter({
     history: createWebHistory(),
     routes: [...Dashboard],
@@ -32,10 +31,29 @@ export const routerMenus: Ref<IntergrationMenu[]> = ref([])
 async function beforeAddRoutes() {
     await useUserStore().getUserInfo
     routerMenus.value = await getUserMenu()
-    const routers = addRoutes(routerMenus.value)
-    routers.forEach(item => {
-        router.addRoute(item)
-    })
+
+    const routers = addRoutes('',routerMenus.value)
+    const homeRouter: Ref<IntergrationMenu> = ref({})
+    for (let i:IntergrationMenu = 0; i < routers.length; i++) {
+        let item = routers[i]
+        if (item.name === 'Home') {
+            item.children = item.children?.concat(finalRouters.value);
+            homeRouter.value = item
+        } else {
+            if (item.componentName === 'Layout') {
+                if (item.children && item.children.length > 0) {
+                    homeRouter.value.children.push(...item.children)
+                }
+            } else {
+                homeRouter.value.children.push(item)
+            }
+        }
+    }
+    console.log(homeRouter.value)
+    router.addRoute(homeRouter.value)
+    // routers.forEach(item => {
+    //     router.addRoute(item)
+    // })
 }
 
 function createNameComponent(item) {
@@ -76,8 +94,6 @@ function createNameComponent(item) {
             } catch (e) {
                 reject('路由错误')
                 router.push('/500')
-                console.error(e)
-                console.error('数据', item)
             }
         })
     }
@@ -87,7 +103,42 @@ const capitalizeFirstLower = (word: string) => {
     return word.charAt(0).toLowerCase() + word.slice(1);
 }
 
-function addRoutes(menus: IntergrationMenu[]) {
+// function addRoutes(menus: IntergrationMenu[]) {
+//     const routers: RouteRecordRaw[] = []
+//     menus.forEach(item => {
+//         const meta: { [key: string]: any } = {}
+//         for (let key in item) {
+//             if (key.startsWith("meta")) {
+//                 const metaKey = capitalizeFirstLower(key.replace("meta", ""))
+//                 meta[metaKey] = item[key]
+//             }
+//         }
+//
+//         let path = item.path
+//         if (item.pathParams?.length > 0) {
+//             const paths = item.path.split("/$")
+//             path = paths[0]
+//         }
+//
+//         const data: RouteRecordRaw = {
+//             path: path + item.pathParams,
+//             name: item.name,
+//             redirect: item.redirect,
+//             meta: meta,
+//             component: createNameComponent(item)
+//         };
+//         if (item.children && item.children.length > 0) {
+//             data.children = addRoutes(item.children)
+//         }
+//         routers.push(data)
+//     })
+//     return routers
+// }
+
+
+const finalRouters: IntergrationMenu[] = ref([])
+
+function addRoutes(parentPath: string, menus: IntergrationMenu[]) {
     const routers: RouteRecordRaw[] = []
     menus.forEach(item => {
         const meta: { [key: string]: any } = {}
@@ -98,7 +149,10 @@ function addRoutes(menus: IntergrationMenu[]) {
             }
         }
 
-        let path = item.path
+        if (!item.path.startsWith('/') && !parentPath.endsWith("/")) {
+            item.path = parentPath + '/' + item.path;
+        }
+        let path = item.path;
         if (item.pathParams?.length > 0) {
             const paths = item.path.split("/$")
             path = paths[0]
@@ -109,16 +163,54 @@ function addRoutes(menus: IntergrationMenu[]) {
             name: item.name,
             redirect: item.redirect,
             meta: meta,
+            componentName: item.component,
             component: createNameComponent(item)
         };
-        if (item.children && item.children.length > 0) {
-            data.children = addRoutes(item.children)
+
+        if (data.componentName === 'EmptyRouter') {
+            if (data.componentName === 'EmptyRouter' && item.children && item.children.length > 0) {
+                recurseChildren(item.path, item.children);
+            }
+        } else {
+            if (item.children && item.children.length > 0) {
+                data.children = addRoutes(item.path,item.children);
+            }
+            routers.push(data)
         }
-        routers.push(data)
     })
     return routers
 }
 
+function recurseChildren(parentPath: string, menus: IntergrationMenu[]) {
+    menus.forEach(item => {
+        if (item.children && item.children.length > 0) {
+            recurseChildren(item.path, item.children);
+        } else {
+            const meta: { [key: string]: any } = {}
+            for (let key in item) {
+                if (key.startsWith("meta")) {
+                    const metaKey = capitalizeFirstLower(key.replace("meta", ""))
+                    meta[metaKey] = item[key]
+                }
+            }
+            let path = item.path;
+            if (item.pathParams?.length > 0) {
+                const paths = item.path.split("/$")
+                path = paths[0]
+            }
+
+            const data: RouteRecordRaw = {
+                path: parentPath + '/' + path + item.pathParams,
+                name: item.name,
+                redirect: item.redirect,
+                meta: meta,
+                component: createNameComponent(item)
+            };
+            finalRouters.value.push(data)
+        }
+    })
+}
+
 
 router.beforeEach(async (to, _from, next) => {
         NProgress.start();

+ 2 - 0
src/views/medical-insurance/inpatient/Home.vue

@@ -62,6 +62,8 @@ import {useMedinsStore} from "@/pinia/medins-store";
 import BloodSugar from "@/views/hospitalization/zhu-yuan-yi-sheng/yi-zhu-lu-ru/components/BloodSugar.vue";
 import {useCompRef} from "@/utils/useCompRef";
 
+console.log(121)
+
 const search = initSearchParam()
 const permission = getGreatestRole()
 const patient = computed(() => {