添加角色管理

role1.0
fanluyan 1 year ago
parent 45b1aacc7e
commit 01b008bfec

@ -125,6 +125,10 @@ export default {
index: "/roleManagement", index: "/roleManagement",
title: "角色管理", title: "角色管理",
}, },
{
index: "/menuManagement",
title: "菜单功能管理",
},
{ {
index: "/deviceUpgrade", index: "/deviceUpgrade",
title: "升级管理", title: "升级管理",

@ -77,6 +77,17 @@ const routes = [
name: "roleManagement", name: "roleManagement",
meta: { title: "角色管理", icon: "el-icon-monitor", keepAlive: true }, meta: { title: "角色管理", icon: "el-icon-monitor", keepAlive: true },
}, },
{
path: "/menuManagement",
component: () => import("../views/system/menuManagement/index.vue"),
name: "menuManagement",
meta: {
title: "菜单功能管理",
icon: "el-icon-monitor",
keepAlive: true,
},
},
{ {
path: "/deviceUpgrade", path: "/deviceUpgrade",
component: () => import("../views/system/deviceUpgrade/index.vue"), component: () => import("../views/system/deviceUpgrade/index.vue"),

@ -899,3 +899,56 @@ export function deleteApkApi(data) {
data, data,
}); });
} }
//获取菜单功能列表
export function getMenuListApi(data) {
return request({
url: "/xymanager/resource/listAll",
method: "get",
params: data,
});
}
//新增菜单功能
export function addResourceApi(data) {
return request({
url: "/xymanager/resource/add",
method: "post",
data,
});
}
//修改菜单功能
export function updateResourceApi(data) {
return request({
url: "/xymanager/resource/update",
method: "post",
data,
});
}
//删除菜单功能
export function deleteResourceApi(data) {
return request({
url: "/xymanager/resource/delete",
method: "post",
params: data,
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
},
});
}
//查询角色权限数结构
export function getRolePermissionApi(data) {
return request({
url: "/xymanager/role/getPermission",
method: "get",
params: data,
});
}
//@Api0peration("修改角色杈限")
export function getRolechangePermissionApi(data) {
return request({
url: "/xymanager/role/changePermission",
method: "post",
data,
});
}

@ -1,6 +1,6 @@
<template> <template>
<el-dialog <el-dialog
class="addUserDialog" class="addMenuDialog"
:title="title" :title="title"
:visible.sync="isShow" :visible.sync="isShow"
:close-on-click-modal="false" :close-on-click-modal="false"
@ -14,10 +14,17 @@
:rules="title == '新增' ? rules : xgrules" :rules="title == '新增' ? rules : xgrules"
:model="formdata" :model="formdata"
> >
<el-form-item label="角色名称:" prop="name"> <el-form-item label="key" prop="key">
<el-input <el-input
placeholder="请输入角色名称" placeholder="请输入key"
v-model="formdata.name" v-model="formdata.key"
autocomplete="off"
></el-input>
</el-form-item>
<el-form-item label="desc" prop="desc">
<el-input
placeholder="请输入desc"
v-model="formdata.desc"
autocomplete="off" autocomplete="off"
></el-input> ></el-input>
</el-form-item> </el-form-item>
@ -29,7 +36,7 @@
</el-dialog> </el-dialog>
</template> </template>
<script> <script>
import { addRole, updateRole } from "@/utils/api/index"; import { addResourceApi, updateResourceApi } from "@/utils/api/index";
export default { export default {
props: { props: {
title: String, title: String,
@ -41,10 +48,12 @@ export default {
formdata: {}, formdata: {},
rules: { rules: {
name: [{ required: true, message: "请输入用户名", trigger: "blur" }], key: [{ required: true, message: "请输入key", trigger: "blur" }],
desc: [{ required: true, message: "请输入desc", trigger: "blur" }],
}, },
xgrules: { xgrules: {
name: [{ required: true, message: "请输入用户名", trigger: "blur" }], key: [{ required: true, message: "请输入key", trigger: "blur" }],
desc: [{ required: true, message: "请输入desc", trigger: "blur" }],
}, },
}; };
}, },
@ -54,7 +63,8 @@ export default {
console.log(val); console.log(val);
if (val == null) { if (val == null) {
return (this.formdata = { return (this.formdata = {
name: "", key: "",
desc: "",
}); });
} }
//this.formdata = val; //this.formdata = val;
@ -65,7 +75,7 @@ export default {
this.$refs.formInfo.validate((valid) => { this.$refs.formInfo.validate((valid) => {
if (valid) { if (valid) {
if (this.title == "新增") { if (this.title == "新增") {
addRole(this.formdata) addResourceApi(this.formdata)
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
this.$message({ this.$message({
@ -81,7 +91,7 @@ export default {
}) })
.catch((err) => {}); .catch((err) => {});
} else { } else {
updateRole(this.formdata) updateResourceApi(this.formdata)
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
this.$message.success("修改成功"); this.$message.success("修改成功");
@ -106,14 +116,14 @@ export default {
this.isShow = false; this.isShow = false;
}, },
handleclose() { handleclose() {
this.$parent.roleListAll(); this.$parent.menuListAll();
}, },
}, },
mounted() {}, mounted() {},
}; };
</script> </script>
<style lang="less"> <style lang="less">
.addUserDialog { .addMenuDialog {
.el-form-item { .el-form-item {
.el-input, .el-input,
.el-select, .el-select,

@ -1,8 +1,8 @@
<template> <template>
<div class="rolemanagement"> <div class="menumanagement">
<div class="deviceBox"> <div class="deviceBox">
<div class="deviceBtnGroup"> <div class="deviceBtnGroup">
<h4>角色管理</h4> <h4>菜单功能管理</h4>
<el-button type="primary" icon="el-icon-plus" @click="handleAdddevice()" <el-button type="primary" icon="el-icon-plus" @click="handleAdddevice()"
>新增</el-button >新增</el-button
> >
@ -10,7 +10,7 @@
<div class="deviceTable"> <div class="deviceTable">
<el-table <el-table
ref="multipleTable" ref="multipleTable"
:data="roleTableData" :data="menuTableData"
stripe stripe
tooltip-effect="dark" tooltip-effect="dark"
style="width: 100%" style="width: 100%"
@ -26,11 +26,15 @@
prop="id" prop="id"
></el-table-column> ></el-table-column>
<el-table-column <el-table-column
label="角色" label="key"
show-overflow-tooltip show-overflow-tooltip
prop="name" prop="key"
></el-table-column>
<el-table-column
label="desc"
show-overflow-tooltip
prop="desc"
></el-table-column> ></el-table-column>
<el-table-column <el-table-column
label="创建时间" label="创建时间"
show-overflow-tooltip show-overflow-tooltip
@ -57,38 +61,26 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- <div class="pageNation">
<el-pagination
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
:current-page="page"
:page-size="pageSize"
layout="sizes, prev, pager, next, jumper,total"
:total="total"
background
>
</el-pagination>
</div> -->
</div> </div>
</div> </div>
<!-- 新增 --> <!-- 新增 -->
<addRole :title="title" ref="adduserref"></addRole> <addMenu :title="title" ref="menuref"></addMenu>
</div> </div>
</template> </template>
<script> <script>
import addRole from "./components/addRole.vue"; import addMenu from "./components/addMenu.vue";
import { getRoleList, deleteRole } from "@/utils/api/index"; import { getMenuListApi, deleteResourceApi } from "@/utils/api/index";
export default { export default {
name: "roleManagement", name: "menuManagement",
components: { components: {
addRole, addMenu,
}, },
data() { data() {
return { return {
title: "", // title: "", //
roleTableData: [], menuTableData: [],
//multipleSelection: [], // //multipleSelection: [], //
page: 1, // page: 1, //
pageSize: 20, // pageSize: 20, //
@ -96,14 +88,14 @@ export default {
}; };
}, },
created() { created() {
this.roleListAll(); this.menuListAll();
}, },
methods: { methods: {
//线 //线
roleListAll() { menuListAll() {
getRoleList() getMenuListApi()
.then((res) => { .then((res) => {
this.roleTableData = res.data; this.menuTableData = res.data;
this.total = res.data.total; this.total = res.data.total;
}) })
.catch((err) => {}); .catch((err) => {});
@ -119,15 +111,15 @@ export default {
// //
handleAdddevice() { handleAdddevice() {
this.title = "新增"; this.title = "新增";
this.$refs.adduserref.display(); this.$refs.menuref.display();
this.$refs.adduserref.getdataform(null); this.$refs.menuref.getdataform(null);
}, },
// //
handleResive(data) { handleResive(data) {
this.title = "修改"; this.title = "修改";
this.$refs.adduserref.display(); this.$refs.menuref.display();
this.$refs.adduserref.getdataform(data); this.$refs.menuref.getdataform(data);
}, },
// //
@ -139,11 +131,11 @@ export default {
type: "warning", type: "warning",
}) })
.then(() => { .then(() => {
deleteRole({ id: data.id }).then((res) => { deleteResourceApi({ id: data.id }).then((res) => {
console.log(res.code); console.log(res.code);
if (res.code == 200) { if (res.code == 200) {
this.$message.success("删除成功"); this.$message.success("删除成功");
this.roleListAll(); // this.menuListAll(); //
} else if (res.code == 400) { } else if (res.code == 400) {
this.$message.error(res.msg); this.$message.error(res.msg);
} }
@ -161,18 +153,18 @@ export default {
// //
handleCurrentChange(val) { handleCurrentChange(val) {
this.page = val; this.page = val;
this.roleListAll(); this.menuListAll();
}, },
// //
handleSizeChange(val) { handleSizeChange(val) {
this.pageSize = val; this.pageSize = val;
this.roleListAll(); this.menuListAll();
}, },
}, },
}; };
</script> </script>
<style lang="less"> <style lang="less">
.rolemanagement { .menumanagement {
width: calc(100% - 24px); width: calc(100% - 24px);
height: calc(100% - 24px); height: calc(100% - 24px);
padding: 12px 12px; padding: 12px 12px;
@ -197,4 +189,4 @@ export default {
} }
} }
</style> </style>
../user/components/blindPermiss.vue ../user/components/blindPermiss.vue./components/addMenu.vue

@ -1,13 +1,22 @@
<template> <template>
<el-dialog <el-dialog
class="blindDialog" class="blindMenuDialog"
title="菜单功能绑定" title="菜单功能绑定"
:visible.sync="isShow" :visible.sync="isShow"
:close-on-click-modal="false" :close-on-click-modal="false"
width="470px" width="470px"
@close="handleclose" @close="handleclose"
> >
<div class="treeBoxList" v-loading="treeLoading"></div> <div class="treeBoxList" v-loading="treeLoading">
<el-checkbox-group v-model="checkedMenu">
<el-checkbox
v-for="item in menuCheckOption"
:label="item"
:key="item.id"
>{{ item.desc }}</el-checkbox
>
</el-checkbox-group>
</div>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button @click="isShow = false"> </el-button> <el-button @click="isShow = false"> </el-button>
<el-button type="primary" @click="submitForm()"> </el-button> <el-button type="primary" @click="submitForm()"> </el-button>
@ -16,9 +25,9 @@
</template> </template>
<script> <script>
import { import {
getPermissionTree, getMenuListApi,
getPermission, getRolePermissionApi,
changePermission, getRolechangePermissionApi,
} from "@/utils/api/index"; } from "@/utils/api/index";
export default { export default {
props: {}, props: {},
@ -26,24 +35,12 @@ export default {
return { return {
roleUser: "", roleUser: "",
isShow: false, isShow: false,
treeData: [],
defaultProps: {
//
children: "list",
label: "name",
key: "compositeKey", // 使 uniqueKey
},
treeLoading: false, treeLoading: false,
rowData: "", rowData: "",
premissData: [], menuList: [],
selectTreeNode: [], checkedMenu: [],
defaultExpandedArr: [], menuCheckOption: [],
rules: { checkedIds: [], //id
name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
},
xgrules: {
name: [{ required: true, message: "请输入用户名", trigger: "blur" }],
},
}; };
}, },
methods: { methods: {
@ -51,70 +48,27 @@ export default {
getdataform(val) { getdataform(val) {
this.rowData = JSON.parse(JSON.stringify(val)); this.rowData = JSON.parse(JSON.stringify(val));
}, },
// getMenuList() {
getPermissionList() { getMenuListApi()
this.treeLoading = true;
getPermissionTree()
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
console.log(res); console.log(res);
// this.treeLoading = false; this.menuCheckOption = res.data;
//this.treeData = res.data.list; this.getRolePermission();
this.treeData = this.processData(res.data);
console.log(this.treeData);
// this.treeData.forEach((item) => {
// this.defaultExpandedArr.push(item.id);
// });
this.defaultExpandedArr.push(this.treeData[0].compositeKey);
// 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) { getRolePermission() {
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() {
console.log(this.rowData); console.log(this.rowData);
getPermission({ id: this.rowData.uid }) getRolePermissionApi({ 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.checkedIds = res.data;
// let setCheckedKeysList = this.premissData.map(function (item) { console.log(this.checkedIds);
// 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);
this.$refs.tree.setCheckedKeys(setCheckedKeysList);
this.treeLoading = false;
// this.$nextTick(() => {
// this.$refs.tree.setCheckedKeys(setCheckedKeysList);
// this.treeLoading = false;
// });
} else { } else {
this.$message.error(res.msg); this.$message.error(res.msg);
} }
@ -123,42 +77,14 @@ export default {
}, },
// //
submitForm() { submitForm() {
// console.log(this.checkedMenu);
let originData = this.$refs.tree.store;
//
const checkedNodeIds = [];
//
const isAllChecked = function (node) {
const childNodes = node.root ? node.root.childNodes : node.childNodes;
childNodes.forEach((child) => {
if (child.checked) {
checkedNodeIds.push(child.data);
}
if (child.indeterminate) {
isAllChecked(child);
}
});
};
isAllChecked(originData);
console.log(checkedNodeIds);
//
let paramsList = []; let paramsList = [];
checkedNodeIds.forEach((node) => { this.checkedMenu.forEach((node) => {
if ("dyValue" in node) { paramsList.push({ resourceId: node.id });
console.log(node);
paramsList.push({ resourceType: 1, resourceId: node.id });
} else if ("bsManufacturer" in node) {
paramsList.push({ resourceType: 2, resourceId: node.id });
} else if ("lineid" in node) {
paramsList.push({ resourceType: 3, resourceId: node.id });
} else if ("towerid" in node) {
paramsList.push({ resourceType: 4, resourceId: node.id });
}
}); });
console.log(paramsList); getRolechangePermissionApi({
changePermission({
list: paramsList, list: paramsList,
userId: this.rowData.uid, roleId: this.rowData.id,
}) })
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
@ -176,27 +102,31 @@ export default {
}) })
.catch((err) => {}); .catch((err) => {});
}, },
display() { display() {
this.isShow = true; this.isShow = true;
this.getPermissionList(); this.getMenuList();
}, },
hide() { hide() {
this.isShow = false; this.isShow = false;
}, },
handleclose() { handleclose() {},
this.treeData = [];
},
}, },
mounted() {}, mounted() {},
}; };
</script> </script>
<style lang="less"> <style lang="less">
.blindDialog { .blindMenuDialog {
.treeBoxList { .treeBoxList {
height: 600px; height: 600px;
overflow: auto; overflow: auto;
.el-dialog__body { .el-checkbox-group {
overflow: auto; display: flex;
flex-direction: column;
.el-checkbox {
height: 32px;
line-height: 32px;
}
} }
} }
} }

@ -140,7 +140,7 @@ export default {
handleMenuBlind(row) { handleMenuBlind(row) {
console.log(row); console.log(row);
this.$refs.blindMenuPermissRef.display(); this.$refs.blindMenuPermissRef.display();
this.$refs.blindMenuPermissRef.getdataform(data); this.$refs.blindMenuPermissRef.getdataform(row);
}, },
// //

Loading…
Cancel
Save