根据用户角色集合展示对应的内容

This commit is contained in:
shiziyuan9527 2020-02-19 13:19:12 +08:00
parent 9c6d4fa7cd
commit 618846c73a
4 changed files with 14 additions and 11 deletions

View File

@ -109,8 +109,10 @@
this.$post("signin", this.form, (response) => {
// cookie
Cookies.set(TokenKey, response.data);
//
localStorage.setItem("lastSourceId", JSON.parse(Cookies.get(TokenKey)).lastSourceId);
let rolesArray = response.data.roles;
let roles = rolesArray.map(r => r.id);
//
localStorage.setItem("roles", roles);
window.location.href = "/"
});
} else {

View File

@ -2,7 +2,6 @@
<el-col v-if="auth">
<el-row id="header-top" type="flex" justify="space-between" align="middle">
<a class="logo"/>
<ms-switch-user/>
<ms-user/>
</el-row>
<el-row id="header-bottom" type="flex" justify="space-between" align="middle">
@ -11,7 +10,7 @@
</el-col>
<el-col :span="4">
<el-row type="flex" justify="center" align="middle">
<router-link to="/createTest">
<router-link to="/createTest" v-permission="['test_user','test_manager']">
<el-button type="primary" size="small">创建测试</el-button>
</router-link>
</el-row>
@ -30,7 +29,6 @@
import MsSetting from "./components/HeaderSetting";
import MsView from "./components/router/View";
import MsUser from "./components/HeaderUser";
import MsSwitchUser from "./components/HeaderSwitchUser";
import MsWebSocket from "./components/websocket/WebSocket";
export default {
@ -51,7 +49,7 @@
window.location.href = "/login"
});
},
components: {MsWebSocket, MsUser, MsMenus, MsSetting, MsView, MsSwitchUser},
components: {MsWebSocket, MsUser, MsMenus, MsSetting, MsView},
methods: {
}
}

View File

@ -1,17 +1,17 @@
<template>
<el-menu menu-trigger="click" :default-active="$route.path" router>
<el-submenu index="1">
<el-submenu index="1" v-permission="['admin']">
<template slot="title">
<font-awesome-icon class="icon account" :icon="['far', 'address-card']" size="lg"/>
<span>账号</span>
</template>
<el-menu-item index="/setting/user">用户</el-menu-item>
<el-menu-item index="/setting/testresourcepool">测试资源池</el-menu-item>
<el-menu-item index="/setting/testresourcepool" v-permission="['test']">测试资源池</el-menu-item>
<el-menu-item index="/setting/organization">组织</el-menu-item>
<el-menu-item index="/setting/workspace">工作空间</el-menu-item>
<el-menu-item>API Keys</el-menu-item>
</el-submenu>
<el-submenu index=2>
<el-submenu index=2 v-permission="['admin','org_admin']">
<template slot="title">
<font-awesome-icon class="icon workspace" :icon="['far', 'clone']" size="lg"/>
<span>工作空间</span>

View File

@ -7,10 +7,13 @@ const whiteList = ['/login']; // no redirect whitelist
export const permission = {
inserted(el, binding) {
const { value } = binding;
const roles = localStorage.getItem("lastSourceId");
const rolesString = localStorage.getItem("roles");
const roles = rolesString.split(',');
if (value && value instanceof Array && value.length > 0) {
const permissionRoles = value;
const hasPermission = permissionRoles.includes(roles);
const hasPermission = roles.some(role => {
return permissionRoles.includes(role)
});
if (!hasPermission) {
el.parentNode && el.parentNode.removeChild(el)
}