1.2.3 后台操作按钮调整及其新增开启拼团功能
This commit is contained in:
44
src/store/modules/permission.js
Normal file
44
src/store/modules/permission.js
Normal file
@ -0,0 +1,44 @@
|
||||
import { constantRouterMap } from '@/router/routers'
|
||||
import Layout from '@/layout/Layout'
|
||||
|
||||
const permission = {
|
||||
state: {
|
||||
routers: constantRouterMap,
|
||||
addRouters: []
|
||||
},
|
||||
mutations: {
|
||||
SET_ROUTERS: (state, routers) => {
|
||||
state.addRouters = routers
|
||||
state.routers = constantRouterMap.concat(routers)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
GenerateRoutes({ commit }, asyncRouter) {
|
||||
commit('SET_ROUTERS', asyncRouter)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const filterAsyncRouter = (routers) => { // 遍历后台传来的路由字符串,转换为组件对象
|
||||
const accessedRouters = routers.filter(router => {
|
||||
if (router.component) {
|
||||
if (router.component === 'Layout') { // Layout组件特殊处理
|
||||
router.component = Layout
|
||||
} else {
|
||||
const component = router.component
|
||||
router.component = loadView(component)
|
||||
}
|
||||
}
|
||||
if (router.children && router.children.length) {
|
||||
router.children = filterAsyncRouter(router.children)
|
||||
}
|
||||
return true
|
||||
})
|
||||
return accessedRouters
|
||||
}
|
||||
|
||||
export const loadView = (view) => { // 路由懒加载
|
||||
return () => import(`@/views/${view}`)
|
||||
}
|
||||
|
||||
export default permission
|
Reference in New Issue
Block a user