| | |
| | | import { asyncRoutes, commonRoutes } from '@/router' |
| | | import { asyncRoutes, asyncRoutesCloud, commonRoutes } from '@/router' |
| | | import Layout from '@/layout' |
| | | import { getCookie } from '@/utils/auth' |
| | | |
| | | // 判断是否有权限 |
| | | function hasPermission(roles, route) { |
| | |
| | | * @param {*} menu |
| | | */ |
| | | export function getAsyncRoutes(routes, menu) { |
| | | // menu 中flag "0" 表示 true "1"表示false |
| | | const menuCode = []// 将后端code取出存成数组形式 |
| | | const menuNameAndCode = []// 将后端code与name取出存成数组形式 |
| | | menu.forEach(item => { |
| | | menuCode.push(item.code) |
| | | menuNameAndCode.push({ code: item.code, name: item.name }) |
| | | if (item.children && item.children.length > 0) { |
| | | item.children.forEach(it => { |
| | | menuCode.push(it.code) |
| | | menuNameAndCode.push({ code: it.code, name: it.name }) |
| | | }) |
| | | if (item.flag === '0') { |
| | | menuCode.push(item.code) |
| | | menuNameAndCode.push({ code: item.code, name: item.name }) |
| | | if (item.children && item.children.length > 0) { |
| | | item.children.forEach(it => { |
| | | if (it.flag === '0') { |
| | | menuCode.push(it.code) |
| | | menuNameAndCode.push({ code: it.code, name: it.name }) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | |
| | |
| | | const actions = { |
| | | generateRoutes({ commit }, menu) { |
| | | return new Promise(resolve => { |
| | | const newRoutes = getAsyncRoutes(asyncRoutes, menu) |
| | | // const newRoutes = getAsyncRoutes(asyncRoutes, menu) |
| | | let newRoutes |
| | | if (getCookie('cloud')) { |
| | | const arr = menu.map(i => i.code) |
| | | newRoutes = asyncRoutesCloud.filter(i => { |
| | | if (arr.includes(i.code)) { |
| | | return i |
| | | } |
| | | }) |
| | | newRoutes.push({ path: '*', redirect: '/404', hidden: true }) |
| | | } else { |
| | | newRoutes = getAsyncRoutes(asyncRoutes, menu) |
| | | } |
| | | commit('SET_ROUTES', newRoutes) |
| | | resolve(newRoutes) |
| | | }) |