优化绑定权限

role1.0
fanluyan 1 year ago
parent 414554c0e5
commit 3c55c84392

@ -67,7 +67,7 @@ const routes = [
{ {
path: "/userManagement", path: "/userManagement",
component: () => import("../views/system/userManagement.vue"), component: () => import("../views/system/user/userManagement.vue"),
name: "userManagement", name: "userManagement",
meta: { title: "用户管理", icon: "el-icon-monitor", keepAlive: true }, meta: { title: "用户管理", icon: "el-icon-monitor", keepAlive: true },
}, },

@ -11,7 +11,7 @@
<el-tree <el-tree
:data="treeData" :data="treeData"
show-checkbox show-checkbox
node-key="id" node-key="compositeKey"
ref="tree" ref="tree"
highlight-current highlight-current
:default-expanded-keys="defaultExpandedArr" :default-expanded-keys="defaultExpandedArr"
@ -42,6 +42,7 @@ export default {
// //
children: "list", children: "list",
label: "name", label: "name",
key: "compositeKey", // 使 uniqueKey
}, },
treeLoading: false, treeLoading: false,
rowData: "", rowData: "",
@ -60,7 +61,6 @@ export default {
// //
getdataform(val) { getdataform(val) {
this.rowData = JSON.parse(JSON.stringify(val)); this.rowData = JSON.parse(JSON.stringify(val));
this.getPermissionRole();
}, },
// //
getPermissionList() { getPermissionList() {
@ -69,40 +69,66 @@ export default {
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
console.log(res); console.log(res);
this.treeLoading = false; // this.treeLoading = false;
this.treeData = res.data.list; //this.treeData = res.data.list;
this.treeData = this.processData(res.data);
console.log(this.treeData);
// this.treeData.forEach((item) => { // this.treeData.forEach((item) => {
// this.defaultExpandedArr.push(item.id); // this.defaultExpandedArr.push(item.id);
// }); // });
this.defaultExpandedArr.push(this.treeData[0].id); this.defaultExpandedArr.push(this.treeData[0].compositeKey);
// console.log("id", this.defaultExpandedArr); // console.log("id", this.defaultExpandedArr);
this.getPermissionRole();
} else { } else {
this.$message.error(res.msg); this.$message.error(res.msg);
} }
}) })
.catch((err) => {}); .catch((err) => {});
}, },
processData(data, level = 0) {
return data.map((node) => {
const compositeKey = `${level}-${node.id}`; //
node.compositeKey = compositeKey; //
if (node.list) {
node.list = this.processData(node.list, level + 1); //
}
return node;
});
},
// //
getPermissionRole() { getPermissionRole() {
console.log(this.rowData);
getPermission({ id: this.rowData.id }) getPermission({ id: this.rowData.id })
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
console.log(res); console.log(res);
this.premissData = res.data; this.premissData = res.data;
// let setCheckedKeysList = this.premissData.map(function (item) {
let setCheckedKeysList = this.premissData.map(function (item) { // return item.resourceId;
return item.resourceId; // });
let setCheckedKeysList = [];
this.premissData.forEach((node) => {
if (node.resourceType == 1) {
console.log(node);
setCheckedKeysList.push("0-" + node.resourceId);
} else if (node.resourceType == 2) {
setCheckedKeysList.push("1-" + node.resourceId);
} else if (node.resourceType == 3) {
setCheckedKeysList.push("2-" + node.resourceId);
} else if (node.resourceType == 4) {
setCheckedKeysList.push("3-" + node.resourceId);
}
}); });
console.log(setCheckedKeysList); console.log(setCheckedKeysList);
this.$nextTick(() => {
this.$refs.tree.setCheckedKeys(setCheckedKeysList); this.$refs.tree.setCheckedKeys(setCheckedKeysList);
this.treeLoading = false;
});
} else { } else {
this.$message.error(res.msg); this.$message.error(res.msg);
} }
}) })
.catch((err) => {}); .catch((err) => {});
}, },
// //
submitForm() { submitForm() {
// //
@ -131,8 +157,10 @@ export default {
paramsList.push({ resourceType: 1, resourceId: node.id }); paramsList.push({ resourceType: 1, resourceId: node.id });
} else if ("bsManufacturer" in node) { } else if ("bsManufacturer" in node) {
paramsList.push({ resourceType: 2, resourceId: node.id }); paramsList.push({ resourceType: 2, resourceId: node.id });
} else if ("id" in node) { } else if ("lineId" in node) {
paramsList.push({ resourceType: 3, resourceId: node.id }); paramsList.push({ resourceType: 3, resourceId: node.id });
} else if ("towerid" in node) {
paramsList.push({ resourceType: 4, resourceId: node.id });
} }
}); });
console.log(paramsList); console.log(paramsList);

@ -101,7 +101,8 @@ export default {
getRoleListAll() { getRoleListAll() {
getRoleList() getRoleList()
.then((res) => { .then((res) => {
this.roleoptions = res.data; //
this.roleoptions = res.data.filter((role) => role.id !== 0);
}) })
.catch((err) => {}); .catch((err) => {});
}, },
Loading…
Cancel
Save