You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tanghe-report/report-ui/src/mixins/access.js

62 lines
1.6 KiB
JavaScript

import { getToken, getAccessUser } from '@/utils/auth'
4 years ago
export default {
data () {
4 years ago
return {
}
},
computed: {
operator: function () {
return this.getUser.loginName
},
operatorText: function () {
return `${this.getUser.realName}[${this.getUser.loginName}]`
},
operatorToken: function (){
return getToken()
4 years ago
},
getUser: function () {
var user = getAccessUser()
if (user != null) {
4 years ago
return user;
} else {
4 years ago
return {};
}
},
opAuthorities () {
return this.getUser == null ? [] : this.getUser.authorities
4 years ago
}
},
created () {
4 years ago
},
mounted () {
4 years ago
},
destroyed () {
4 years ago
},
methods: {
hasPermission (permissionStr) {
if (permissionStr == null || permissionStr.length == 0) {
return true
4 years ago
}
// 登录用户权限列表
if (this.opAuthorities == null) {
return false
4 years ago
}
// 用户有的全部权限码
var opAuthoritiesStr = JSON.stringify(this.opAuthorities)
// permissionStr可能是authorityManage、authorityManage:insert、authorityManage:insert|authorityManage:update
var needPermissionArray = permissionStr.split('|')
for (var i = 0; i < needPermissionArray.length; i++) {
// 只要有其中的一个权限就返回true
var needPermission = needPermissionArray[i] // authorityManage、authorityManage:insert
needPermission = needPermission.replace(/\ /g, "") // 去除authorityManage : insert中:前后的空格
if(opAuthoritiesStr.indexOf(needPermission)>=0){
4 years ago
return true
}
}
return false
4 years ago
},
}
}