浏览代码

动态路由以及医技费用录入问题

xiaochan 1 年之前
父节点
当前提交
10615f7aa2

+ 1 - 1
src/api/settings/menu-settings.ts

@@ -19,7 +19,7 @@ export interface IntergrationMenu {
     component: string | 'EmptyRouter' | 'Layout';
     redirect?: string;
     pathParams?: string;
-    children?: IntergrationMenu[];
+    children: IntergrationMenu[] | null;
     completePath: string
     cascaders?: number[] | null
 }

+ 0 - 1
src/components/med-tec-mod/HuanZheFeiYong.vue

@@ -4,7 +4,6 @@
       <el-button type="danger" @click="xiangMuTuiFeiClick" icon="Delete">退费</el-button>
       <el-button type="primary" @click="weiGuiTuiFeiFenXiDialogOpen(true)">违规费用分析</el-button>
       <el-button type="primary" @click="exportExecl" icon="Download">导出 Excel</el-button>
-      {{ patient.feiYongLeiXingCode }}
     </div>
 
     <div class="layout_flex_1-y layout_display_flex_y">

+ 102 - 93
src/router/index.ts

@@ -15,6 +15,7 @@ import {getUserMenu, IntergrationMenu} from "@/api/settings/menu-settings";
 import {createVNode, defineComponent, h, Ref} from "vue";
 import {stringNotBlank} from "@/utils/blank-utils";
 import {useUserStore} from "@/pinia/user-store";
+import XEUtils from "xe-utils";
 
 const router = createRouter({
     history: createWebHistory(),
@@ -27,28 +28,111 @@ vueFile.Layout = import.meta.glob('../layout/index.vue')['../layout/index.vue']
 let asyncFinished = false
 export const routerMenus: Ref<IntergrationMenu[]> = ref([])
 
+const 一级路由 = []
+const 二级路由 = []
+
+function emptyRouter(routers: IntergrationMenu[]) {
+    routers.forEach((item) => {
+        const hasChildren = item.children !== null && item.children.length > 0
+        if (['EmptyRouter', 'Layout'].includes(item.component) && hasChildren) {
+            item.children?.forEach(child => {
+                child.path = item.path + '/' + child.path
+                一级路由.push(child)
+            })
+        } else if (hasChildren) {
+            item.children!.forEach(child => {
+                child.path = child.path.replace(item.path + '/', '')
+            })
+            二级路由.push(item)
+        }
+
+        if (item.children !== null && item.children.length > 0) {
+            emptyRouter(item.children)
+        }
+    })
+}
+
+function 转化为路由(value: IntergrationMenu[]) {
+    const routers: RouteRecordRaw[] = []
+
+    value.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,
+            componentName: item.component,
+            component: createNameComponent(item)
+        };
+        if (item.children && item.children.length > 0) {
+            data.children = 转化为路由(item.children);
+        }
+        routers.push(data)
+    })
+    return routers
+}
+
 async function beforeAddRoutes() {
     await useUserStore().getUserInfo
     routerMenus.value = await getUserMenu()
 
-    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)
-            }
-        }
-    }
-    router.addRoute(homeRouter.value)
+    emptyRouter(XEUtils.clone(routerMenus.value, true))
+    const data = 转化为路由([{
+        completePath: "/",
+        pathParams: '',
+        component: 'Layout',
+        icon: "",
+        id: 0,
+        metaLink: false,
+        metaTitle: "",
+        name: "",
+        path: "/",
+        sort: 0,
+        type: 0,
+        children: [
+            {
+                "id": 260,
+                "type": 2,
+                "path": "dashboard",
+                "icon": "",
+                "name": "dashboard",
+                "parentId": 259,
+                "metaTitle": "首页",
+                "metaHideTabs": false,
+                "metaPassRule": true,
+                "metaShowMenu": true,
+                "sort": 0,
+                "component": "../views/dashboard/index.vue",
+                "redirect": "",
+                "pathParams": "",
+                "mainCard": false,
+                "mainOverflowAuto": false,
+                "metaLink": null,
+                "completePath": "dashboard",
+                "cascaders": [
+                    259
+                ],
+                "children": null,
+                "metaNeedToken": true
+            },
+            ...一级路由, ...二级路由
+        ],
+    }])
+    data.forEach(item => {
+        router.addRoute(item)
+    })
 }
 
 function createNameComponent(item) {
@@ -98,81 +182,6 @@ const capitalizeFirstLower = (word: string) => {
     return word.charAt(0).toLowerCase() + word.slice(1);
 }
 
-const finalRouters: IntergrationMenu[] = ref([])
-
-function addRoutes(parentPath: string, 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]
-            }
-        }
-
-        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]
-        }
-
-        const data: RouteRecordRaw = {
-            path: path + item.pathParams,
-            name: item.name,
-            redirect: item.redirect,
-            meta: meta,
-            componentName: item.component,
-            component: createNameComponent(item)
-        };
-
-        if (data.componentName === 'EmptyRouter') {
-            if (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)
-        }
-    })
-    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();
         const hasToken = stringNotBlank(localStorage.token)

+ 0 - 1
src/views/med-tec-mod/YiJiFeiYongLuRu.vue

@@ -145,7 +145,6 @@ import {stringNotBlank} from "@/utils/blank-utils";
 import {xcMessage} from "@/utils/xiaochan-element-plus";
 import {receiveAndRecalculateCost} from "@/api/inpatient/patient";
 import {useUserStore} from "@/pinia/user-store";
-import {isDev} from "@/utils/public";
 
 const userInfo = useUserStore().userInfo
 const dangQianShiJian = new Date()