common.js
3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import store from "@/store/index";
import MenuService from "services/Menu";
export const Common = {
setAuthBtn(resData) {
let data = resData || store.getters.curMenuAuth.data;
//console.log('setAuthBtn', data)
const authBtnEl = document.getElementsByTagName("button");
const authStringArr = [
"新增",
"编辑",
"删除",
"导出",
"导入",
"修改",
"解绑",
"选择试驾车辆",
"新增车辆",
"查看",
];
if (authBtnEl && authBtnEl.length > 0) {
if (data && data.length > 0) {
authBtnEl.forEach((elItem) => {
let flag = true;
let authFlag = false;
const elText = elItem.innerText;
authStringArr.forEach((authItem) => {
if (elText.includes(authItem)) {
authFlag = true;
return;
}
});
if (authFlag) {
data.forEach((labelItem) => {
if (flag) {
elItem.style.display = "none";
if (elText.includes(labelItem.label)) {
elItem.style.display = "inline-block";
flag = false;
}
}
});
}
});
}
}
},
getAuthData() {
return store.getters.curMenuAuth.data || [];
},
// 获取二级菜单权限
getSecondMenu(parentId, menuName) {
const menuService = new MenuService();
menuService.getMenuAuth({ parentId }).then(
(res) => {
const { code, data } = res;
if (code == 200) {
store.dispatch("menu/setMenuAuth", { menuName, data });
}
},
(err) => {}
);
},
// 动态设置面包屑
setBreadCrumbs(url) {
let list = store.state.menu.menuList;
let m = "";
if (!url) {
return false;
}
let o = list.find((k) => {
let n = (k.children || []).find((j) => j.origin.frontRoute == url);
if (n) {
m = n;
return k;
}
});
let arr = [];
// 一级菜单
if (o) {
arr.push({ name: o.label, path: o.origin.frontRoute });
}
// 二级菜单
if (m) {
arr.push({ name: m.label, path: m.origin.frontRoute });
}
// 控制菜单展开
if (o && m) {
list.map((k) => {
if (k.label == o.label) {
k.showSubList = true;
} else {
k.showSubList = false;
}
(k.children || []).map((j) => {
if (j.origin.frontRoute == m.origin.frontRoute) {
j.subItemActive = true;
} else {
j.subItemActive = false;
}
});
});
}
store.dispatch("menu/setBreadCrumb", arr);
store.commit("menu/SET_MENU_LIST", list);
},
// 公共页面跳转方法
navigateTo: function(options) {},
// 判断是否有权限
hasPermission: function(pid) {
let list = Common.getAuthData();
let idx = list.findIndex((k) => k.origin.permissionTag == pid);
if (idx < 0) {
return false;
} else {
return true;
}
},
// 全局判断是否有权限(针对所有页面的权限按钮,为了兼容一个权限按钮控制多个页面) v1.25.0版本需求添加
isPermission(pid) {
return new Promise((resolve) => {
const menuService = new MenuService();
menuService.getPermission({ permissionTag: pid }).then((res) => {
let _list = res.data || [];
if (_list && _list.length) {
resolve(true);
} else {
resolve(false);
}
});
});
},
// 隐藏菜单和header的路由
hiddenMenu: [
"/monitor/activeLocation",
"/monitor/resident",
"/monitor/monitor",
"/monitor/fence",
"/monitor/replay",
"/monitor/historyLocation",
"monitor/zoneCar",
],
};