|
1
2
|
import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
|
|
3
4
|
const hasPermission = {
install (Vue, options) {
|
|
5
|
//console.log(options);
|
|
6
7
|
Vue.directive('has', {
inserted: (el, binding, vnode)=>{
|
|
8
9
|
//console.log("页面权限控制----");
console.time()
|
|
10
11
12
13
|
//节点权限处理,如果命中则不进行全局权限处理
if(!filterNodePermission(el, binding, vnode)){
filterGlobalPermission(el, binding, vnode);
}
|
|
14
|
console.timeEnd() //计时结束并输出时长
|
|
15
16
17
18
19
|
}
});
}
};
|
|
20
|
/**
|
|
21
|
* 流程节点权限控制
|
|
22
23
|
*/
export function filterNodePermission(el, binding, vnode) {
|
|
24
|
let permissionList = [];
|
|
25
|
try {
|
|
26
|
let obj = vnode.context.$props.formData;
|
|
27
28
|
if (obj) {
let bpmList = obj.permissionList;
|
|
29
|
for (let bpm of bpmList) {
|
|
30
31
32
33
|
if(bpm.type != '2') {
permissionList.push(bpm);
}
}
|
|
34
35
|
}else{
return false;
|
|
36
37
38
39
40
41
42
43
|
}
} catch (e) {
//console.log("页面权限异常----", e);
}
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
//el.parentNode.removeChild(el)
return false;
}
|
|
44
45
|
console.log("流程节点页面权限--NODE--");
|
|
46
|
let permissions = [];
|
|
47
|
for (let item of permissionList) {
|
|
48
49
50
51
52
53
54
55
56
57
|
if(item.type != '2') {
permissions.push(item.action);
}
}
//console.log("页面权限----"+permissions);
//console.log("页面权限----"+binding.value);
if (!permissions.includes(binding.value)) {
//el.parentNode.removeChild(el)
return false;
}else{
|
|
58
|
for (let item2 of permissionList) {
|
|
59
60
61
62
63
64
65
66
67
68
69
70
|
if(binding.value === item2.action){
return true;
}
}
}
return false;
}
/**
* 全局权限控制
*/
export function filterGlobalPermission(el, binding, vnode) {
|
|
71
|
console.log("全局页面权限--Global--");
|
|
72
|
|
|
73
74
|
let permissionList = [];
let allPermissionList = [];
|
|
75
76
77
|
//let authList = Vue.ls.get(USER_AUTH);
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
|
78
|
for (let auth of authList) {
|
|
79
80
81
82
83
84
|
if(auth.type != '2') {
permissionList.push(auth);
}
}
//console.log("页面权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
|
85
|
for (let gauth of allAuthList) {
|
|
86
87
88
89
90
|
if(gauth.type != '2') {
allPermissionList.push(gauth);
}
}
//设置全局配置是否有命中
|
|
91
|
let invalidFlag = false;//无效命中
|
|
92
|
if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
|
|
93
|
for (let itemG of allPermissionList) {
|
|
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
if(binding.value === itemG.action){
if(itemG.status == '0'){
invalidFlag = true;
break;
}
}
}
}
if(invalidFlag){
return;
}
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
el.parentNode.removeChild(el);
return;
}
let permissions = [];
|
|
110
|
for (let item of permissionList) {
|
|
111
112
113
114
115
116
117
118
119
|
if(item.type != '2'){
permissions.push(item.action);
}
}
if (!permissions.includes(binding.value)) {
el.parentNode.removeChild(el);
}
}
|
|
120
|
export default hasPermission;
|