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

79 lines
2.1 KiB
JavaScript

4 years ago
import { setItem, getItem } from '@/utils/storage';
export default {
data () {
4 years ago
return {
}
},
computed: {
operator: function () {
var operator = getItem('loginName')
return operator
4 years ago
},
getUser: function () {
4 years ago
// var user = getItem('user');
var user = JSON.parse(localStorage.getItem('user'))
if (user != null) {
4 years ago
return user;
} else {
4 years ago
return {};
}
},
opAuthorities () {
4 years ago
return this.getUser == null ? [] : this.getUser.authorityWithOrgIds
}
},
created () {
4 years ago
},
mounted () {
4 years ago
},
destroyed () {
4 years ago
},
methods: {
hasPermission (permissionStr, orgIds) {
4 years ago
//判断用户权限列表是否为空
if (this.opAuthorities == null) {
return false
4 years ago
}
if (permissionStr && permissionStr.indexOf('|') !== -1) {
4 years ago
let flag = false
let arr = permissionStr.split('|')
for (let i = 0; i < arr.length; i++) {
4 years ago
let a = arr[i].replace(/(^\s*)|(\s*$)/g, "");
if (this.opAuthorities.hasOwnProperty(a)) {
flag = true
}
}
return flag
}
//登录用户没有某个操作权限
if (!this.opAuthorities.hasOwnProperty(permissionStr)) {
return false
4 years ago
}
//如果当前验证,不包含项目级别验证,直接返回
if (typeof (orgIds) == 'undefined' || orgIds == null) {
4 years ago
return true
}
4 years ago
//验证登录用户是否有某个项目的有操作权限
var orgIdsHasPermission = this.opAuthorities[permissionStr]
//如果projectIds是个数字只要验证登录用户是否有该项目的操作权限
if (typeof orgIds == 'number') {
if (orgIdsHasPermission.indexOf(orgIds) > -1) {
return true
} else {
4 years ago
return false
}
} else {
4 years ago
var result = false
for (var i in orgIdsHasPermission) {
var flag = orgIds.indexOf(orgIdsHasPermission[i]) > -1
if (flag) {
result = true
}
}
return result
}
},
}
}