Skip to content

Commit 69cef26

Browse files
committed
add demo permission
1 parent 1415b75 commit 69cef26

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

src/components/layout/LayoutMain.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@
6666
}
6767
},
6868
created() {
69-
this.menus = asyncRouterMap
69+
this.menus = this.mainMenu
7070
},
7171
computed: {
7272
...mapState({
73+
mainMenu: state => state.permission.addRouters,
7374
siderOpen: state => state.app.sidebar.opened,
7475
theme: state => state.app.theme,
7576
device: state => state.app.device,

src/router/index.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,26 @@ export const asyncRouterMap = [
5252
component: Layout,
5353
name: 'dashboard',
5454
redirect: '/dashboard/workplace',
55-
meta: { title: '仪表盘', icon: 'dashboard' },
55+
meta: { title: '仪表盘', icon: 'dashboard', permission: [ 'dashboard' ] },
5656
children: [
5757
{
5858
path: '/dashboard/analysis',
5959
name: 'Analysis',
6060
component: () => import('../views/dashboard/Analysis'),
61-
meta: { title: '分析页', hideHeader: true }
61+
meta: { title: '分析页', hideHeader: true, permission: [ 'dashboard' ] }
6262
},
6363
{
6464
path: '/dashboard/monitor',
6565
name: 'Monitor',
6666
hidden: true,
6767
component: () => import('../views/dashboard/Monitor'),
68-
meta: { title: '监控页', hideHeader: true }
68+
meta: { title: '监控页', hideHeader: true, permission: [ 'dashboard' ] }
6969
},
7070
{
7171
path: '/dashboard/workplace',
7272
name: 'Workplace',
7373
component: () => import('../views/dashboard/Workplace'),
74-
meta: { title: '工作台' }
74+
meta: { title: '工作台', permission: [ 'dashboard' ] }
7575
}
7676
]
7777
},
@@ -80,25 +80,25 @@ export const asyncRouterMap = [
8080
component: LayoutBase,
8181
name: 'form',
8282
redirect: '/form/base-form',
83-
meta: { title: '表单页', icon: 'form' },
83+
meta: { title: '表单页', icon: 'form', permission: [ 'form' ] },
8484
children: [
8585
{
8686
path: '/form/base-form',
8787
name: 'BaseForm',
8888
component: () => import('../views/form/BasicForm'),
89-
meta: { title: '基础表单' }
89+
meta: { title: '基础表单', permission: [ 'form' ] }
9090
},
9191
{
9292
path: '/form/step-form',
9393
name: 'StepForm',
9494
component: () => import('../views/form/stepForm/StepForm'),
95-
meta: { title: '分步表单' }
95+
meta: { title: '分步表单', permission: [ 'form' ] }
9696
},
9797
{
9898
path: '/form/advanced-form',
9999
name: 'AdvanceForm',
100100
component: () => import('../views/form/advancedForm/AdvancedForm'),
101-
meta: { title: '高级表单' }
101+
meta: { title: '高级表单', permission: [ 'form' ] }
102102
}
103103
]
104104
},
@@ -107,68 +107,68 @@ export const asyncRouterMap = [
107107
component: LayoutBase,
108108
name: 'list',
109109
redirect: '/list/query-list',
110-
meta: { title: '列表页', icon: 'table' },
110+
meta: { title: '列表页', icon: 'table', permission: [ 'table' ] },
111111
children: [
112112
{
113113
path: '/list/query-list',
114114
name: 'QueryList',
115115
component: () => import('@/views/list/TableList'),
116-
meta: { title: '查询表格' }
116+
meta: { title: '查询表格', permission: [ 'table' ] }
117117
},
118118
{
119119
path: '/list/edit-table',
120120
name: 'EditList',
121121
component: () => import('@/views/list/TableInnerEditList'),
122-
meta: { title: '内联编辑表格' }
122+
meta: { title: '内联编辑表格', permission: [ 'table' ] }
123123
},
124124
{
125125
path: '/list/role-list',
126126
name: 'RoleList',
127127
component: () => import('@/views/list/RoleList'),
128-
meta: { title: '角色列表' }
128+
meta: { title: '角色列表', permission: [ 'table' ] }
129129
},
130130
{
131131
path: '/list/permission-list',
132132
name: 'PermissionList',
133133
component: () => import('@/views/list/PermissionList'),
134-
meta: { title: '权限列表' }
134+
meta: { title: '权限列表', permission: [ 'table' ] }
135135
},
136136
{
137137
path: '/list/basic-list',
138138
name: 'BasicList',
139139
component: () => import('@/views/list/StandardList'),
140-
meta: { title: '标准列表' }
140+
meta: { title: '标准列表', permission: [ 'table' ] }
141141
},
142142
{
143143
path: '/list/card',
144144
name: 'CardList',
145145
component: () => import('@/views/list/CardList'),
146-
meta: { title: '卡片列表' }
146+
meta: { title: '卡片列表', permission: [ 'table' ] }
147147
},
148148
{
149149
path: '/list/search',
150150
name: 'SearchList',
151151
component: () => import('@/views/list/search/SearchLayout'),
152152
redirect: '/list/search/article',
153-
meta: { title: '搜索列表' },
153+
meta: { title: '搜索列表', permission: [ 'table' ] },
154154
children: [
155155
{
156156
path: '/list/search/article',
157157
name: 'SearchArticles',
158158
component: () => import('../views/list/TableList'),
159-
meta: { title: '搜索列表(文章)' }
159+
meta: { title: '搜索列表(文章)', permission: [ 'table' ] }
160160
},
161161
{
162162
path: '/list/search/project',
163163
name: 'SearchProjects',
164164
component: () => import('../views/list/TableList'),
165-
meta: { title: '搜索列表(项目)' }
165+
meta: { title: '搜索列表(项目)', permission: [ 'table' ] }
166166
},
167167
{
168168
path: '/list/search/application',
169169
name: 'SearchApplications',
170170
component: () => import('../views/list/TableList'),
171-
meta: { title: '搜索列表(应用)' }
171+
meta: { title: '搜索列表(应用)', permission: [ 'table' ] }
172172
},
173173
]
174174
},
@@ -179,19 +179,19 @@ export const asyncRouterMap = [
179179
component: Layout,
180180
name: 'profile',
181181
redirect: '/profile/basic',
182-
meta: { title: '详情页', icon: 'profile' },
182+
meta: { title: '详情页', icon: 'profile', permission: [ 'profile' ] },
183183
children: [
184184
{
185185
path: '/profile/basic',
186186
name: 'ProfileBasic',
187187
component: () => import('@/views/profile/basic/Index'),
188-
meta: { title: '基础详情页' }
188+
meta: { title: '基础详情页', permission: [ 'profile' ] }
189189
},
190190
{
191191
path: '/profile/advanced',
192192
name: 'ProfileAdvanced',
193193
component: () => import('@/views/profile/advanced/Advanced'),
194-
meta: { title: '高级详情页' }
194+
meta: { title: '高级详情页', permission: [ 'profile' ] }
195195
}
196196
]
197197
},
@@ -200,13 +200,13 @@ export const asyncRouterMap = [
200200
component: LayoutBase,
201201
name: 'result',
202202
redirect: '/result/success',
203-
meta: { title: '结果页', icon: 'check-circle-o' },
203+
meta: { title: '结果页', icon: 'check-circle-o', permission: [ 'result' ] },
204204
children: [
205205
{
206206
path: '/result/success',
207207
name: 'ResultSuccess',
208208
component: () => import(/* webpackChunkName: "result" */ '../views/result/Success'),
209-
meta: { title: '成功', hiddenPageHeader: true }
209+
meta: { title: '成功', hiddenPageHeader: true, permission: [ 'result' ] }
210210
},
211211
{
212212
path: '/result/fail',
@@ -215,7 +215,7 @@ export const asyncRouterMap = [
215215
// this generates a separate chunk (about.[hash].js) for this route
216216
// which is lazy-loaded when the route is visited.
217217
component: () => import(/* webpackChunkName: "result" */ '../views/result/Error'),
218-
meta: { title: '失败', hiddenPageHeader: true }
218+
meta: { title: '失败', hiddenPageHeader: true, permission: [ 'result' ] }
219219
}
220220
]
221221
},
@@ -224,13 +224,13 @@ export const asyncRouterMap = [
224224
component: Layout,
225225
name: 'exception',
226226
redirect: '/exception/403',
227-
meta: { title: '异常页', icon: 'warning' },
227+
meta: { title: '异常页', icon: 'warning', permission: [ 'exception' ] },
228228
children: [
229229
{
230230
path: '/exception/403',
231231
name: 'Exception403',
232232
component: () => import(/* webpackChunkName: "fail" */ '../views/exception/403'),
233-
meta: { title: '403' }
233+
meta: { title: '403', permission: [ 'exception' ] }
234234
},
235235
{
236236
path: '/exception/404',
@@ -239,7 +239,7 @@ export const asyncRouterMap = [
239239
// this generates a separate chunk (about.[hash].js) for this route
240240
// which is lazy-loaded when the route is visited.
241241
component: () => import(/* webpackChunkName: "fail" */ '../views/exception/404'),
242-
meta: { title: '404' }
242+
meta: { title: '404', permission: [ 'exception' ] }
243243
},
244244
{
245245
path: '/exception/500',
@@ -248,59 +248,59 @@ export const asyncRouterMap = [
248248
// this generates a separate chunk (about.[hash].js) for this route
249249
// which is lazy-loaded when the route is visited.
250250
component: () => import(/* webpackChunkName: "fail" */ '../views/exception/500'),
251-
meta: { title: '500' }
251+
meta: { title: '500', permission: [ 'exception' ] }
252252
}
253253
]
254254
},
255255
{
256256
path: '/account',
257257
component: Layout,
258258
name: 'account',
259-
meta: { title: '个人页', icon: 'user', keepAlive: true },
259+
meta: { title: '个人页', icon: 'user', keepAlive: true, permission: [ 'user' ] },
260260
children: [
261261
{
262262
path: '/account/center',
263263
name: 'center',
264264
component: () => import('@/views/account/center/Index'),
265-
meta: { title: '个人中心', keepAlive: true }
265+
meta: { title: '个人中心', keepAlive: true, permission: [ 'user' ] }
266266
},
267267
{
268268
path: '/account/settings',
269269
name: 'settings',
270270
component: () => import('@/views/account/settings/Index'),
271-
meta: { title: '个人设置', hideHeader: true, keepAlive: true },
271+
meta: { title: '个人设置', hideHeader: true, keepAlive: true, permission: [ 'user' ] },
272272
redirect: '/account/settings/base',
273273
alwaysShow: true,
274274
children: [
275275
{
276276
path: '/account/settings/base',
277277
name: 'BaseSettings',
278278
component: () => import('@/views/account/settings/BaseSetting'),
279-
meta: { title: '基本设置', hidden: true, keepAlive: true }
279+
meta: { title: '基本设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
280280
},
281281
{
282282
path: '/account/settings/security',
283283
name: 'SecuritySettings',
284284
component: () => import('@/views/account/settings/Security'),
285-
meta: { title: '安全设置', hidden: true, keepAlive: true }
285+
meta: { title: '安全设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
286286
},
287287
{
288288
path: '/account/settings/custom',
289289
name: 'CustomSettings',
290290
component: () => import('@/views/account/settings/Custom'),
291-
meta: { title: '个性化设置', hidden: true, keepAlive: true }
291+
meta: { title: '个性化设置', hidden: true, keepAlive: true, permission: [ 'user' ] }
292292
},
293293
{
294294
path: '/account/settings/binding',
295295
name: 'BindingSettings',
296296
component: () => import('@/views/account/settings/Binding'),
297-
meta: { title: '账户绑定', hidden: true, keepAlive: true }
297+
meta: { title: '账户绑定', hidden: true, keepAlive: true, permission: [ 'user' ] }
298298
},
299299
{
300300
path: '/account/settings/notification',
301301
name: 'NotificationSettings',
302302
component: () => import('@/views/account/settings/Notification'),
303-
meta: { title: '新消息通知', hidden: true, keepAlive: true }
303+
meta: { title: '新消息通知', hidden: true, keepAlive: true, permission: [ 'user' ] }
304304
},
305305
]
306306
},

src/store/modules/permission.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function hasPermission(permission, route) {
1717
}
1818
}
1919
}
20-
return true
20+
return false
2121
}
2222

2323
/**

src/store/modules/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ const user = {
5252
getInfo().then(response => {
5353
const result = response.result
5454

55-
if (result.role && result.permissions.length > 0) {
55+
if (result.role && result.role.permissions.length > 0) {
5656
const role = result.role
57-
role.permissions = result.permissions
57+
role.permissions = result.role.permissions
5858
role.permissions.map(per => {
5959
if (per.actionEntitySet != null && per.actionEntitySet.length > 0) {
6060
let action = per.actionEntitySet.map(action => { return action.action })

0 commit comments

Comments
 (0)