根据menu树状图,从staticRoutes中取值,构建新的routeList

比较menu中的url和staticRoutes中的path,生成符合menu结构的routeList
遇到staticRoutes中没有的设置为{path:'#'}

const menu =
            [
                {
                    "parent": {},
                    "createdAt": null,
                    "code": "has_routes",
                    "children": [
                        {
                            "parent": {
                                "code": "has_routes",
                                "name": "导航",
                                "sort": 9,
                                "uuid": 10,
                                "url": "/has_routes"
                            },
                            "createdAt": null,
                            "code": "second",
                            "name": "second",
                            "iconUrl": null,
                            "sort": 11,
                            "uuid": 12,
                            "version": null,
                            "url": "second",
                            "updatedAt": null
                        },
                        {
                            "parent": {
                                "code": "has_routes",
                                "name": "导航",
                                "sort": 9,
                                "uuid": 10,
                                "url": "/has_routes"
                            },
                            "createdAt": null,
                            "code": "primary",
                            "name": "primary",
                            "iconUrl": null,
                            "sort": 10,
                            "uuid": 11,
                            "version": null,
                            "url": "primary",
                            "updatedAt": null
                        }
                    ],
                    "name": "导航",
                    "iconUrl": null,
                    "sort": 9,
                    "uuid": 10,
                    "version": null,
                    "url": "/has_routes",
                    "updatedAt": null
                },
                {
                    "parent": {},
                    "createdAt": null,
                    "code": "mall",
                    "name": "商城",
                    "iconUrl": null,
                    "sort": 8,
                    "uuid": 8,
                    "version": null,
                    "url": "http://m.tmall.com",
                    "updatedAt": null
                },
                {
                    "parent": {},
                    "createdAt": null,
                    "code": "human_resource",
                    "children": [
                        {
                            "parent": {
                                "code": "human_resource",
                                "name": "人资",
                                "sort": 4,
                                "uuid": 5,
                                "url": "/human_resource"
                            },
                            "createdAt": null,
                            "code": "manager",
                            "children": [
                                {
                                    "parent": {
                                        "code": "manager",
                                        "name": "管理",
                                        "sort": 5,
                                        "uuid": 9,
                                        "url": ""
                                    },
                                    "createdAt": null,
                                    "code": "roles",
                                    "name": "角色管理",
                                    "iconUrl": null,
                                    "sort": 7,
                                    "uuid": 7,
                                    "version": null,
                                    "url": "roles",
                                    "updatedAt": null
                                },
                                {
                                    "parent": {
                                        "code": "manager",
                                        "name": "管理",
                                        "sort": 5,
                                        "uuid": 9,
                                        "url": ""
                                    },
                                    "createdAt": null,
                                    "code": "deparment",
                                    "name": "部门管理",
                                    "iconUrl": null,
                                    "sort": 6,
                                    "uuid": 6,
                                    "version": null,
                                    "url": "department",
                                    "updatedAt": null
                                }
                            ],
                            "name": "管理",
                            "iconUrl": null,
                            "sort": 5,
                            "uuid": 9,
                            "version": null,
                            "url": "",
                            "updatedAt": null
                        }
                    ],
                    "name": "人资",
                    "iconUrl": null,
                    "sort": 4,
                    "uuid": 5,
                    "version": null,
                    "url": "/human_resource",
                    "updatedAt": null
                },
                {
                    "parent": {},
                    "createdAt": "2020-03-21 09:19:57",
                    "code": "state_setting",
                    "name": "状态机",
                    "iconUrl": null,
                    "sort": 3,
                    "uuid": 4,
                    "version": 0,
                    "url": "/state_setting",
                    "updatedAt": "2020-03-21 09:19:57"
                },
                {
                    "parent": {},
                    "createdAt": "2020-03-21 09:19:57",
                    "code": "friend",
                    "name": "联系人",
                    "iconUrl": null,
                    "sort": 2,
                    "uuid": 3,
                    "version": 0,
                    "url": "/im_friend",
                    "updatedAt": "2020-03-21 09:19:57"
                },
                {
                    "parent": {},
                    "createdAt": "2020-03-21 09:19:57",
                    "code": "conversation",
                    "name": "会话",
                    "iconUrl": null,
                    "sort": 1,
                    "uuid": 2,
                    "version": 0,
                    "url": "/im_conversation",
                    "updatedAt": "2020-03-21 09:19:57"
                },
                {
                    "parent": {},
                    "createdAt": "2020-03-21 09:19:57",
                    "code": "dashboard",
                    "name": "主页",
                    "iconUrl": null,
                    "sort": 0,
                    "uuid": 1,
                    "version": 0,
                    "url": "/dashboard",
                    "updatedAt": "2020-03-21 09:19:57"
                }
            ]

        const staticRoutes = [
            {
                path: '/human_resource',
                component: 'Layout',
                meta: {
                    title: '人资',
                    icon: 'people'
                },
            },
            {
                path: "/im_conversation",
                component: 'Layout',
                meta: { title: "会话", icon: "wechat" },
                children: [
                    {
                        path: 'index',
                        name: 'Conversation',
                        meta: { title: '会话' },
                        component: () => import('@/views/im/conversation/index.vue')
                    }
                ]
            },
            {
                path: "/im_friend",
                component: 'Layout',
                meta: { title: "联系人", icon: "peoples" },
                children: [
                    {
                        path: 'index',
                        component: () => import('@/views/im/friend/index.vue'),
                        name: 'Friend',
                        meta: { title: '联系人' }
                    },
                ]
            },
            {
                path: "/state_setting",
                component: 'Layout',
                meta: {
                    title: "状态",
                    icon: "example",
                },
                children: [
                    {
                        path: 'index',
                        component: () => import('@/views/statesetting/index.vue')
                    }
                ]
            },
            {
                path: 'role',
                component: () => import('@/views/human-resource/roles'),
                meta: { title: '角色管理', icon: 'user' }
            },
            {
                path: 'department',
                component: () => import('@/views/human-resource/department'),
                meta: { title: '部门管理', icon: 'user' }
            },
            {
                path: 'primary',
                name: 'primary',
                component: () => import('./components/primary.vue'),
                meta: { title: 'primary' }
            },
            {
                path: 'second',
                name: 'second',
                component: () => import('./components/second.vue'),
                meta: { title: 'second' }
            }
        ]
阅读 1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题