# 优化权限逻辑

This commit is contained in:
xianfuxing 2018-09-30 17:36:57 +08:00
parent 2cc2c2aa6a
commit 5b2f7d7c9d
3 changed files with 8 additions and 2 deletions

View File

@ -1,4 +1,4 @@
import { param2Obj } from '@/utils' import { param2Obj } from '@/utils'
const userMap = { const userMap = {
admin: { admin: {

View File

@ -131,6 +131,7 @@ export const asyncRouterMap = [
{ {
path: '/settings/system', path: '/settings/system',
component: Layout, component: Layout,
meta: { roles: ['admin'] },
children: [{ children: [{
path: 'index', path: 'index',
component: () => import('@/views/settings/system'), component: () => import('@/views/settings/system'),

View File

@ -14,6 +14,7 @@ export default {
components: { adminDashboard, editorDashboard }, components: { adminDashboard, editorDashboard },
data() { data() {
return { return {
allowRoles: ['admin', 'customer'],
currentRole: 'adminDashboard' currentRole: 'adminDashboard'
} }
}, },
@ -23,7 +24,11 @@ export default {
]) ])
}, },
created() { created() {
if (!this.roles.includes('admin')) { const adminDashboardRoles = new Set(['admin', 'customer'])
const userRoles = new Set(this.roles)
const intersection = new Set([...userRoles].filter(role => adminDashboardRoles.has(role)))
console.log(intersection.size)
if (intersection.size === 0) {
this.currentRole = 'editorDashboard' this.currentRole = 'editorDashboard'
} }
} }