Skip to content

Commit 3a727d5

Browse files
committed
fix(view): route 动态处理
1 parent 6bc4258 commit 3a727d5

File tree

4 files changed

+4
-250
lines changed

4 files changed

+4
-250
lines changed

admin/src/permission.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import router from './router'
2-
import { routeManage, routerAdmin } from './router'
2+
import { routeManage, routerAdmin } from './router/router'
33
import store from './store'
44
import NProgress from 'nprogress' // Progress 进度条
55
import 'nprogress/nprogress.css'// Progress 进度条样式
@@ -20,6 +20,7 @@ router.beforeEach((to, from, next) => {
2020
if (store.getters.roles.length === 0) {
2121
store.dispatch('GetInfo').then(res => { // 拉取用户信息
2222
const roles = res.data.roles
23+
console.log(roles)
2324
store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表
2425
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
2526
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record

admin/src/router/index.js

Lines changed: 0 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const Layout = () => import('../views/layout/Layout')
2121
icon: 'svg-name' the icon show in the sidebar,
2222
}
2323
**/
24-
const Super = 'Super Administrator'
25-
const Admin = 'Admin'
2624

2725
// 基础路由
2826
const routeBase = [
@@ -48,179 +46,6 @@ const routeBase = [
4846
}
4947
]
5048

51-
// 管理一般路由
52-
export const routeManage = [
53-
{
54-
path: '/api_excel',
55-
component: Layout,
56-
redirect: '/api_excel/index',
57-
name: 'Excel-List',
58-
meta: { title: '批量测试管理', icon: 'ico-table', role: Admin },
59-
children: [
60-
{ path: '/api_excel/edit/:id', name: 'EditExcel', component: () => import('@/views/api_excel/edit'), hidden: true },
61-
{
62-
path: '/api_excel/add',
63-
name: 'AddExcel',
64-
component: () => import('@/views/api_excel/add'),
65-
meta: { title: '上传测试', icon: 'excel', role: Admin }
66-
},
67-
{
68-
path: '/api_excel/index',
69-
name: 'Excel',
70-
component: () => import('@/views/api_excel/index'),
71-
meta: { title: '测试管理', icon: 'ico-aliyun', role: Admin }
72-
},
73-
{ path: '/api_param/add', name: 'AddApiParam', component: () => import('@/views/api_param/add'), hidden: true },
74-
{ path: '/api_param/edit/:id', name: 'EditApiParam', component: () => import('@/views/api_param/edit'), hidden: true },
75-
{
76-
path: '/api_param/index',
77-
name: 'ApiParam',
78-
component: () => import('@/views/api_param/index'),
79-
meta: { title: '接口列表', icon: 'api', role: Admin }
80-
}
81-
]
82-
}
83-
]
84-
85-
export const routerAdmin = [
86-
// { path: '/', redirect: '/index', hidden: true },
87-
88-
{
89-
path: '/category',
90-
component: Layout,
91-
redirect: '/category/index',
92-
name: 'Category-Nav',
93-
meta: { title: '栏目菜单', icon: 'category', role: Super },
94-
children: [
95-
{ path: '/category/add', name: 'AddCategory', component: () => import('@/views/category/add'), meta: { title: '添加栏目' }, hidden: true },
96-
{ path: '/category/edit/:id', name: 'EditCategory', component: () => import('@/views/category/edit'), hidden: true },
97-
{
98-
path: '/category/index',
99-
name: 'Category',
100-
component: () => import('@/views/category/index'),
101-
meta: { title: '栏目管理', icon: 'ico-category', role: Super }
102-
},
103-
{ path: '/nav/add', name: 'AddNav', component: () => import('@/views/nav/add'), hidden: true },
104-
{ path: '/nav/edit/:id', name: 'EditNav', component: () => import('@/views/nav/edit'), hidden: true },
105-
{
106-
path: '/nav',
107-
name: 'Nav',
108-
component: () => import('@/views/nav'),
109-
meta: { title: '导航管理', icon: 'nav', role: Super }
110-
},
111-
{ path: '/tag/add', name: 'AddTag', component: () => import('@/views/tag/add'), meta: { title: '添加标签' }, hidden: true },
112-
{ path: '/tag/edit/:id', name: 'EditTag', component: () => import('@/views/tag/edit'), hidden: true },
113-
{
114-
path: '/tag',
115-
name: 'Tag',
116-
component: () => import('@/views/tag/index'),
117-
meta: { title: '标签列表', icon: 'tag', role: Super }
118-
}
119-
]
120-
},
121-
122-
{
123-
path: '/article',
124-
component: Layout,
125-
// redirect: '/article',
126-
name: 'Article-List',
127-
meta: { title: '文章管理', icon: 'article', role: Super },
128-
children: [
129-
{ path: '/article/edit/:id', name: 'EditArticle', component: () => import('@/views/article/edit'), hidden: true },
130-
{
131-
path: '/article/index',
132-
name: 'Article',
133-
component: () => import('@/views/article/index'),
134-
meta: { title: '文章管理', icon: 'ico-article', role: Super }
135-
},
136-
{
137-
path: '/article/add',
138-
name: 'AddArticle',
139-
component: () => import('@/views/article/add'),
140-
meta: { title: '添加文章', icon: 'add', role: Super }
141-
}
142-
]
143-
},
144-
145-
{
146-
path: '/list',
147-
component: Layout,
148-
redirect: '/task',
149-
name: '公交',
150-
meta: { title: '公交管理', icon: 'bus', role: Super },
151-
children: [
152-
{ path: '/task/search', name: 'search', component: () => import('@/views/task/search'), hidden: true },
153-
{ path: '/task/newBus', name: 'NewBus', component: () => import('@/views/task/newBus'), hidden: true },
154-
{ path: '/task/edit/:id', name: 'taskEdit', component: () => import('@/views/task/edit'), hidden: true },
155-
{
156-
path: '/task',
157-
name: '定时任务',
158-
component: () => import('@/views/task/index'),
159-
meta: { title: '定时任务', icon: 'task', role: Super }
160-
},
161-
{ path: 'lines/add', name: 'linesAdd', component: () => import('@/views/lines/add'), hidden: true },
162-
{ path: 'lines/edit/:id', name: 'linesEdit', component: () => import('@/views/lines/edit'), hidden: true },
163-
{
164-
path: 'lines',
165-
name: '公交列表',
166-
component: () => import('@/views/lines/index'),
167-
meta: { title: '公交列表', icon: 'table', role: Super }
168-
},
169-
{
170-
path: 'config',
171-
name: '配置管理',
172-
component: () => import('@/views/lines/index'),
173-
meta: { title: '配置列表', icon: 'table', role: Super }
174-
},
175-
{
176-
path: 'tree',
177-
name: 'Tree',
178-
component: () => import('@/views/tree/index'),
179-
meta: { title: 'Tree', icon: 'tree', role: Super },
180-
hidden: true
181-
}
182-
]
183-
},
184-
185-
{
186-
path: 'user',
187-
component: Layout,
188-
redirect: '/user',
189-
name: '权限',
190-
meta: { title: '权限管理', icon: 'auth', role: Super },
191-
children: [
192-
{ path: 'index', name: 'userIndex', component: () => import('@/views/user/index'), hidden: true },
193-
{ path: 'password', name: 'userPassword', component: () => import('@/views/user/password'), hidden: true },
194-
{ path: '/user/add', name: 'AddUser', component: () => import('@/views/user/add'), hidden: true },
195-
{ path: '/user/edit/:id', name: 'EditUser', component: () => import('@/views/user/edit'), hidden: true },
196-
{
197-
path: '/user',
198-
name: '用户管理',
199-
component: () => import('@/views/user/index'),
200-
meta: { title: '用户列表', icon: 'user', role: Super }
201-
},
202-
{ path: '/permission/add', name: 'AddPermission', component: () => import('@/views/permission/add'), hidden: true },
203-
{ path: '/permission/edit/:id', name: 'EditPermission', component: () => import('@/views/permission/edit'), hidden: true },
204-
{
205-
path: '/permission',
206-
name: '权限列表',
207-
component: () => import('@/views/permission/index'),
208-
meta: { title: '权限列表', icon: 'permission', role: Super }
209-
},
210-
211-
{ path: '/role/add', name: 'AddRole', component: () => import('@/views/role/add'), hidden: true },
212-
{ path: '/role/edit/:id', name: 'EditRole', component: () => import('@/views/role/edit'), hidden: true },
213-
{
214-
path: '/role',
215-
name: '角色管理',
216-
component: () => import('@/views/role/index'),
217-
meta: { title: '角色管理', icon: 'role', role: Super }
218-
}
219-
]
220-
}
221-
222-
]
223-
22449
const routeOther = [
22550
{
22651
path: '/form',

admin/src/router/router.js

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -189,75 +189,4 @@ export const routerAdmin = [
189189

190190
]
191191

192-
export const routeOther = [
193-
{
194-
path: '/form',
195-
component: Layout,
196-
children: [
197-
{
198-
path: 'index',
199-
name: 'Form',
200-
component: () => import('@/views/form/index'),
201-
meta: { title: 'Form', icon: 'form' }
202-
}
203-
], hidden: true
204-
},
205-
{
206-
path: '/nested',
207-
component: Layout,
208-
redirect: '/nested/menu1',
209-
name: 'Nested',
210-
meta: {
211-
title: 'Nested',
212-
icon: 'nested'
213-
},
214-
children: [
215-
{
216-
path: 'menu1',
217-
component: () => import('@/views/nested/menu1/index'), // Parent router-view
218-
name: 'Menu1',
219-
meta: { title: 'Menu1' },
220-
children: [
221-
{
222-
path: 'menu1-1',
223-
component: () => import('@/views/nested/menu1/menu1-1'),
224-
name: 'Menu1-1',
225-
meta: { title: 'Menu1-1' }
226-
},
227-
{
228-
path: 'menu1-2',
229-
component: () => import('@/views/nested/menu1/menu1-2'),
230-
name: 'Menu1-2',
231-
meta: { title: 'Menu1-2' },
232-
children: [
233-
{
234-
path: 'menu1-2-1',
235-
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
236-
name: 'Menu1-2-1',
237-
meta: { title: 'Menu1-2-1' }
238-
},
239-
{
240-
path: 'menu1-2-2',
241-
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
242-
name: 'Menu1-2-2',
243-
meta: { title: 'Menu1-2-2' }
244-
}
245-
]
246-
},
247-
{
248-
path: 'menu1-3',
249-
component: () => import('@/views/nested/menu1/menu1-3'),
250-
name: 'Menu1-3',
251-
meta: { title: 'Menu1-3' }
252-
}
253-
]
254-
},
255-
{
256-
path: 'menu2',
257-
component: () => import('@/views/nested/menu2/index'),
258-
meta: { title: 'menu2' }
259-
}
260-
]
261-
},
262-
{ path: '*', redirect: '/404', hidden: true }
263-
]
192+
export const routeOther = []

admin/src/store/modules/user.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ const user = {
8989
GenerateRoutes({ commit }, data) {
9090
return new Promise(resolve => {
9191
let userLimitRouters = null
92-
console.log(data)
92+
// console.log(data)
9393
if (data.roles.indexOf('Super Administrator') >= 0) {
94-
console.log('SuperAdmin')
9594
userLimitRouters = [...routerAdmin, ...routeManage, ...routeOther]
9695
} else if (data.roles.indexOf('Admin') >= 0) {
9796
userLimitRouters = routeManage

0 commit comments

Comments
 (0)