当前位置:网站首页>角色授权---通过添加和删除一级菜单,完成二级菜单的添加和删除
角色授权---通过添加和删除一级菜单,完成二级菜单的添加和删除
2022-07-15 14:36:00 【꧁এ悲宸๓₯㎕】
目的:
点击一级菜单,完成添加一级菜单,同时,二级菜单也能够同步完成勾选并添加,再次点击完成删除。点击二级菜单,完成添加或删除
详细代码
1,RoleFunctionsController
@RestController
public class RoleFunctionsController {
@Autowired
private IRoleFunService roleFunService;
/** * 添加角色权限 * @param roleFun * @return */
@PostMapping("/role-functions")
public JsonResult addRoleFunctions(@RequestBody RoleFun roleFun){
roleFunService.save(roleFun);
return new JsonResult(1,roleFun);
}
/** * 删除角色权限 * @param roleId * @param functionsId * @return */
@DeleteMapping("/role-functions/{roleId}/{functionsId}")
public JsonResult deleteRoleFunctions(@PathVariable String roleId,@PathVariable String functionsId){
roleFunService.remove(new QueryWrapper<RoleFun>().lambda()
.eq(RoleFun::getRoleId,roleId)
.eq(RoleFun::getFunId,functionsId));
//考虑上级权限的情况
return new JsonResult(1,null);
}
}
2,role-list.html
这里我只列出了HTML的部分代码
<el-dialog title="角色授权" :visible.sync="dialogTreeVisible">
<el-tree :data="functions" show-checkbox default-expand-all node-key="id" ref="tree" highlight-current @check="checkTreeNode" :props="defaultProps">
</el-tree>
</el-dialog>
<script> new Vue({
el:"#app", data() {
return {
roles:null, rolefunctionslist:null, //权限树 current:null, dialogTreeVisible:false,//显示权限树对话框 functions:null, //权限数据 defaultProps:{
//修改树属性的名称 children:'subFunctions', label:'name' } } }, methods:{
//列表点击一行 changeCurrent(row){
this.current = row; //取消所有的选择效果 this.$refs.roleTable.clearSelection(); //选中当前的行 this.$refs.roleTable.toggleRowSelection(row); }, //单选某一行,data是当前行的数据,row是当前行的对象 selectOne(data,row){
//取消所有的选择效果 this.$refs.roleTable.clearSelection(); //选中当前的行 this.$refs.roleTable.toggleRowSelection(row); }, //取消全选角色 selectAll(){
this.$refs.roleTable.clearSelection(); }, //显示授权树 showTreeDialog(){
if (this.current){
this.dialogTreeVisible = true; //查询角色相关的权限 axios.get("/functions/role/"+this.current.id).then(value => {
if (value.data.code == 1){
this.rolefunctionslist = value.data.data; this.$refs.tree.setCheckedKeys(value.data.data); } }) }else{
this.$message("请选择角色"); } }, //添加树上的权限节点 checkTreeNode(arg1,arg2){
console.log(arg1) console.log(arg2) //判断当前的权限id是够在选中的key中 if (arg1.subFunctions != null){
if (arg2.checkedKeys.length > this.rolefunctionslist.length){
//添加选择的一级菜单以及以下的二级菜单 //添加一级菜单 axios.post("/role-functions", {
roleId:this.current.id,funId:arg1.id}).then(value => {
if (value.data.code == 1){
this.$message("添加权限成功"); } }) //遍历添加二级菜单 for (let i = 0; i < arg1.subFunctions.length ; i++) {
axios.post("/role-functions", {
roleId:this.current.id,funId:arg1.subFunctions[i].id}) .then(value => {
if (value.data.code == 1){
this.$message("添加权限成功"); } }) } }else if (arg2.checkedKeys.length <= this.rolefunctionslist.length){
//删除选择的一级菜单以及以下的二级菜单 //删除一级菜单 axios.delete("/role-functions/"+this.current.id+"/"+arg1.id) .then(value => {
if (value.data.code == 1){
this.$message("删除权限成功"); } }); //遍历删除二级菜单 for (let i = 0; i < arg1.subFunctions.length; i++) {
axios.delete("/role-functions/"+this.current.id+"/"+arg1.subFunctions[i].id) .then(value => {
if (value.data.code == 1){
this.$message("删除权限成功"); } }); } } }else {
//单个添加二级菜单 if (arg2.checkedKeys.indexOf(arg1.id) != -1){
axios.post("/role-functions", {
roleId:this.current.id,funId:arg1.id}) .then(value => {
if (value.data.code == 1){
this.$message("添加权限成功"); } }) }else {
axios.delete("/role-functions/"+this.current.id+"/"+arg1.id) //传过去当前角色的id和当前权限的id .then(value => {
if (value.data.code == 1){
this.$message("删除权限成功"); } }) } } }, }, mounted(){
//钩子函数 //加载所有的权限 axios.get("/functions").then(value => {
if (value.data.code == 1){
this.functions = value.data.data; } }) } }); </script>
边栏推荐
- 笔记本电脑能连接WiFi但浏览器无法打开网页的解决办法
- PAT 甲级 A1094 The Largest Generation
- The practice of opengauss database on CentOS, configuration
- Solve the problem of mongodb error attempted to create a lock file on a read only directory: /data/db
- 组合数学--排列组合
- 2021-11-15 how to splice thymeleaf href \src
- 每日刷题记录 (二十四)
- 把一个数组封装成类
- nvidia-smi命令无法正常使用的解决方案
- 解决运行Mongodb报错 Attempted to create a lock file on a read-only directory: /data/db
猜你喜欢

zabbix 监控服务 (三) 配置管理图形和窗口

CodeBlocks download installation tutorial (complete and detailed)

Machine learning exercise 4 - neural networks

【DAY_4-回顾,对象,数组基本概念——1】

使用 Terraform 在阿里云上快速部署 MQTT 集群

Write it down once Net analysis of memory leakage in web system of a power plant

VS2017#include 'xxx.h'

Socke编程简介

工业交换机如何进入web管理界面?

DPU — 完全可编程网络
随机推荐
Dynamic loudspeaker overload process
Pat grade a 1090 highest price in supply chain
同花顺周末能开户吗 开户安全吗
个人炒股应该使用什么app更安全,交易速度更快
nvidia-smi命令无法正常使用的解决方案
VirtualBox:SSH连接
Pat grade a a1079 total sales of supply chain
开源数据质量解决方案——Apache Griffin入门宝典
DPU — 完全可编程网络
Properties and traversal of binary trees
Machine learning exercise 4 - neural networks
Migrate MySQL database to Kingbase database (other databases are similar)
巴比特 | 元宇宙每日必读:腾讯新闻暂停数字藏品的售卖服务,用户留言要求“退款”,幻核也陷入“滞销”困境,这释放了什么信息?...
1035. 不相交的线
送你的代码上太空,与华为云一起开发“最伟大的作品”
工业交换机的价格为什么有高低之分?
Notes tree traversal
Fungible DPU
组合数学--排列组合
高性能算力中心 — RDMA — NVIDIA SHARP