|  | @@ -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();
 |