gin-vue-admin 2.0代码重构

This commit is contained in:
QM303176530
2020-04-04 21:39:07 +08:00
parent 5ed41ddd8c
commit 1b9adea284
202 changed files with 1240 additions and 1299 deletions

View File

@@ -0,0 +1,58 @@
import { asyncRouterHandle } from '@/utils/asyncRouter';
import { asyncMenu } from '@/api/menu'
const formatRouter = (routes) => {
routes && routes.map(item => {
item.meta.hidden = item.hidden
if (item.children.length > 0) {
formatRouter(item.children)
}
})
}
export const router = {
namespaced: true,
state: {
asyncRouters: []
},
mutations: {
// 设置动态路由
setAsyncRouter(state, asyncRouters) {
state.asyncRouters = asyncRouters
}
},
actions: {
// 从后台获取动态路由
async SetAsyncRouter({ commit }) {
const baseRouter = [{
path: '/layout',
name: 'layout',
component: "view/layout/index.vue",
meta: {
title: "底层layout"
},
children: []
}]
const asyncRouterRes = await asyncMenu()
const asyncRouter = asyncRouterRes.data.menus
formatRouter(asyncRouter)
baseRouter[0].children = asyncRouter
baseRouter.push({
path: '*',
redirect: '/404'
})
asyncRouterHandle(baseRouter)
commit('setAsyncRouter', baseRouter)
return true
}
},
getters: {
// 获取动态路由
asyncRouters(state) {
return state.asyncRouters
}
}
}