import Layout from '@/layout' import { getInfo } from '../store/modules/user.js' export function getRoutes(permissions) { let userInfo = {} if (localStorage.userinfo) { userInfo = JSON.parse(localStorage.userinfo) } var permissions = userInfo.permissions || []; console.log(userInfo) let constantRoutes1 = [] if (userInfo.UserId == 1 || 1 == 1) { constantRoutes1 = [{ path: '/login', component: () => import('@/views/login/index'), hidden: true }, { path: '/404', component: () => import('@/views/404'), hidden: true }, { path: '/answerDetail', name: '答题详情', component: () => import('@/views/AnswerResult/detail.vue'), hidden: true }, { path: '/', component: Layout, redirect: '/dashboard', children: [{ path: 'dashboard', name: '首页', component: () => import('@/views/dashboard/index'), meta: { title: '首页', icon: 'dashboard' } }, { path: 'live', name: '直播观看', component: () => import('@/views/live/index'), meta: { title: '直播', icon: 'video' }, hidden: true }] }, { path: '/example', component: Layout, redirect: '/example/table', name: 'Example', meta: { title: '题库管理', icon: 'el-icon-s-help', permissions: ['admin'] }, children: [{ path: 'QuestionBank', name: 'Table', component: () => import('@/views/QuestionBank/index'), meta: { title: '题库', icon: 'table', permissions: ['admin'] } },] }, // { // path: '/moduleIndex', // component: Layout, // redirect: '/module/index', // name: 'module', // meta: { // title: '面试题', // icon: 'el-icon-s-help' // }, // children: [{ // path: 'index', // name: 'index', // component: () => // import ('@/views/TestPaper/index'), // hidden: true, // meta: { // title: '试卷维护', // icon: 'table' // } // }, ] // }, // { // path: '/realQuestion', // component: Layout, // redirect: '/module/realQuestion', // name: 'realQuestion', // meta: { // title: '历年真题', // icon: 'el-icon-s-help' // }, // children: [{ // path: 'recharge', // name: 'recharge', // component: () => // import ('@/views/module/realQuestion'), // meta: { // title: '历年真题', // icon: 'el-icon-s-management' // } // }] // }, { path: '/views', component: Layout, redirect: '/views/TestPaper', name: 'TestPaper', meta: { title: '试卷管理', icon: 'el-icon-s-help' }, children: [{ path: 'TestPaperList', name: 'Table', component: () => import('@/views/TestPaper/TestPaperList'), meta: { title: '试卷列表', icon: 'table' } }, { path: 'index', name: 'index', component: () => import('@/views/TestPaper/index'), hidden: true, meta: { title: '试卷维护', icon: 'table' } }, { path: 'ManualTestPaper', name: 'Table', component: () => import('@/views/TestPaper/ManualTestPaper'), meta: { title: '组卷', icon: 'table' } }, ] }, // { // path: '/order', // component: Layout, // redirect: '/', // name: 'order', // meta: { // title: '订单管理', // icon: 'el-icon-s-marketing' // }, // children: [{ // path: 'recharge', // name: 'recharge', // component: () => // import('@/views/order/rechargeList'), // meta: { // title: '充值记录', // } // }, { // path: 'shop', // name: 'shop', // component: () => // import('@/views/order/shopList'), // meta: { // title: '购买记录', // } // }] // }, { path: '/user', component: Layout, redirect: '/', name: 'user', meta: { title: '用户管理', icon: 'el-icon-s-help' }, children: [{ path: 'user', name: 'User', component: () => import('@/views/user/userlist'), meta: { title: '人才库', } }, { path: 'interviewSchedule', name: 'interviewSchedule', component: () => import('@/views/user/InterviewSchedule'), meta: { title: '面试时间表', } }, { path: 'importuser', name: 'importuser', component: () => import('@/views/user/picuserimport'), meta: { title: '图片导入用户', } }, { path: 'admin', name: 'admin', component: () => import('@/views/user/adminList'), meta: { title: '管理员列表', permissions: ['admin'] } }, ] }, { path: '/password', component: Layout, redirect: '/', name: 'password', meta: { title: '系统管理', icon: 'el-icon-s-platform' }, children: [ { path: 'userdimset', name: 'impouserdimsetrtuser', component: () => import('@/views/user/userdimset'), meta: { title: '维度规则设置', permissions:['admin' ] } }, { path: 'index', name: 'index', component: () => import('@/views/password/index'), meta: { title: '忘记密码', } }, { path: 'TestPaperClass', name: 'Table', component: () => import('@/views/TestPaper/TestPaperClass'), meta: { title: '分类管理', permissions:['admin' ] } }, { path: 'carousel', name: 'carousel', component: () => import('@/views/carousel/index'), meta: { title: '轮播图', permissions:['admin' ] } }, { path: 'new', name: 'new', component: () => import('@/views/carousel/new'), meta: { title: '最新资讯', permissions:['admin'] } }] }, // 404 page must be placed at the end !!! { path: '*', redirect: '/404', hidden: true } ] } else { return ; constantRoutes1 = [{ path: '/login', component: () => import('@/views/login/index'), hidden: true }, { path: '/404', component: () => import('@/views/404'), hidden: true }, { path: '/example', component: Layout, redirect: '/example/table', name: 'Example', meta: { title: '题库管理', icon: 'el-icon-s-help', permissions: ["admin", "user"], }, children: [{ path: 'QuestionBank', name: 'Table', component: () => import('@/views/QuestionBank/index'), meta: { title: '题库', icon: 'table' } },] }, { path: '/moduleIndex', component: Layout, redirect: '/module/index', name: 'module', meta: { title: '面试题', icon: 'el-icon-s-help' }, children: [{ path: 'recharge', name: 'recharge', component: () => import('@/views/module/index'), meta: { title: '面试题', icon: 'el-icon-s-operation' } }, { path: 'index', name: 'index', component: () => import('@/views/TestPaper/index'), hidden: true, meta: { title: '试卷维护', icon: 'table' } }, ] }, // { // path: '/realQuestion', // component: Layout, // redirect: '/module/realQuestion', // name: 'realQuestion', // meta: { // title: '历年真题', // icon: 'el-icon-s-help' // }, // children: [{ // path: 'recharge', // name: 'recharge', // component: () => // import ('@/views/module/realQuestion'), // meta: { // title: '历年真题', // icon: 'el-icon-s-management' // } // }] // }, { path: '/views', component: Layout, redirect: '/views/TestPaper', name: 'TestPaper', meta: { title: '试卷管理', icon: 'el-icon-s-help' }, children: [{ path: 'TestPaperList', name: 'Table', component: () => import('@/views/TestPaper/TestPaperList'), meta: { title: '试卷列表', icon: 'table' } }, { path: 'index', name: 'index', component: () => import('@/views/TestPaper/index'), hidden: true, meta: { title: '试卷维护', icon: 'table' } }, // { // path: 'ManualTestPaper', // name: 'Table', // component: () => import('@/views/TestPaper/ManualTestPaper'), // meta: { // title: '组卷', // icon: 'table' // } // }, ] }, // { // path: '/order', // component: Layout, // redirect: '/', // name: 'order', // meta: { // title: '订单管理', // icon: 'el-icon-s-marketing' // }, // children: [{ // path: 'recharge', // name: 'recharge', // component: () => // import('@/views/order/rechargeList'), // meta: { // title: '充值记录', // } // }, { // path: 'shop', // name: 'shop', // component: () => // import('@/views/order/shopList'), // meta: { // title: '购买记录', // } // }] // }, { path: '/user', component: Layout, redirect: '/', name: 'user', meta: { title: '用户管理', icon: 'el-icon-s-help' }, children: [{ path: 'user', name: 'User', component: () => import('@/views/user/userlist'), meta: { title: '人才库', } } ] }, { path: '/password', component: Layout, redirect: '/', name: 'password', meta: { title: '系统管理', icon: 'el-icon-s-platform', permissions:['admin','user'] }, children: [{ path: 'index', name: 'index', component: () => import('@/views/password/index'), meta: { title: '忘记密码', } }, { path: 'TestPaperClass', name: 'Table', component: () => import('@/views/TestPaper/TestPaperClass'), meta: { title: '分类管理', permissions: ['admin'] } }, { path: 'carousel', name: 'carousel', component: () => import('@/views/carousel/index'), meta: { title: '轮播图', permissions: ['admin'] } }, { path: 'new', name: 'new', component: () => import('@/views/carousel/new'), meta: { title: '最新资讯', permissions: ['admin'] } }] }, // 404 page must be placed at the end !!! { path: '*', redirect: '/404', hidden: true } ] } function hasPermission(permissions, route) { if (route.meta && route.meta.permissions) { return permissions.some((role) => route.meta.permissions.includes(role)); } else { return true; } } function filterAsyncRoutes(routes, permissions) { const finallyRoutes = []; routes.forEach((route) => { const item = { ...route }; if (hasPermission(permissions, item)) { if (item.children) { item.children = filterAsyncRoutes(item.children, permissions); } finallyRoutes.push(item); } }); return finallyRoutes; } constantRoutes1 = filterAsyncRoutes(constantRoutes1, permissions); return constantRoutes1; }