refactor: 为路由设置roles

This commit is contained in:
Captain.B 2020-08-26 15:45:43 +08:00
parent db635a2c6f
commit a487a1f2aa
3 changed files with 9 additions and 3 deletions

View File

@ -35,7 +35,8 @@
<font-awesome-icon class="icon" :icon="['far', 'user']" size="lg"/> <font-awesome-icon class="icon" :icon="['far', 'user']" size="lg"/>
<span>{{ $t('commons.personal_info') }}</span> <span>{{ $t('commons.personal_info') }}</span>
</template> </template>
<el-menu-item v-for="menu in persons" :key="menu.index" :index="menu.index" class="setting-item"> <el-menu-item v-for="menu in persons" :key="menu.index" :index="menu.index" class="setting-item"
v-permission="menu.roles">
{{ $t(menu.title) }} {{ $t(menu.title) }}
</el-menu-item> </el-menu-item>
</el-submenu> </el-submenu>
@ -56,6 +57,7 @@ export default {
if (child.meta[group] === true) { if (child.meta[group] === true) {
let menu = {index: Setting.path + "/" + child.path} let menu = {index: Setting.path + "/" + child.path}
menu.title = child.meta.title; menu.title = child.meta.title;
menu.roles = child.meta.roles;
menus.push(menu); menus.push(menu);
} }
}) })

View File

@ -67,7 +67,11 @@ export default {
{ {
path: 'apikeys', path: 'apikeys',
component: () => import(/* webpackChunkName: "setting" */ '@/business/components/settings/personal/ApiKeys'), component: () => import(/* webpackChunkName: "setting" */ '@/business/components/settings/personal/ApiKeys'),
meta: {person: true, title: 'commons.api_keys'} meta: {
person: true,
title: 'commons.api_keys',
roles: ['test_manager', 'test_user', 'test_viewer', 'org_admin', 'admin']
}
}, },
] ]

View File

@ -32,7 +32,7 @@ function checkRolePermission(el, binding, type) {
el.parentNode && el.parentNode.removeChild(el) el.parentNode && el.parentNode.removeChild(el)
} }
} else { } else {
throw new Error(`need roles! Like v-permission="['admin','editor']"`) // throw new Error(`need roles! Like v-permission="['admin','editor']"`)
} }
} }