首页 > 其他分享 >角色权限设置显示

角色权限设置显示

时间:2023-07-15 12:56:54浏览次数:37  
标签:角色 title menu menuList 设置 import 权限 id icon

1. 树形控件

点击查看代码
<el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick"></el-tree>

2. 角色信息编辑对话框

3. 定义menuProps

取的是表里的title字段

写一个查询

复制一个menuManage出来

点击查看代码
import request from '@/utils/request'

export default{
  getAllMenu(){
    return request({
      url: '/menu',
      method: 'get'
    });
  },
}

引用它

在钩子函数中调用

4. 菜单嵌套

我们用parent_id来进行嵌套,用is_leaf来判断是否是叶子节点

5.实体类

找到menu实体类在里面加上@Data(get,set方法就不要了)

为了让这个表体现出层级关系,需要加上两个属性。

点击查看代码
  @TableField(exist = false)
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<Menu> children;

    @TableField(exist = false)
    private Map<String,Object> meta;
    private Map<String,Object> getMeta(){
        meta = new HashMap<>();
        meta.put("title",title);
        meta.put("icon",icon);
        return meta;
    }

6. 控制器

点击查看代码
package com.example.sys.controller;

import com.example.common.vo.Result;
import com.example.sys.entity.Menu;
import com.example.sys.service.IMenuService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author CanisRufus
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/menu")

public class MenuController {
    @Autowired
    private IMenuService menuService;

    @ApiOperation("查询所有的菜单数据")
    @GetMapping
    public Result<List<Menu>> getAllMenu(){
        List<Menu> menuList = menuService.getAllMenu();
        return Result.success(menuList);
    }
}

7. x_menu表新增数据

点击查看代码
delete from x_menu;
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('1','Layout','/sys','/sys/user','sysManage','系统管理','userManage','0','N','0');
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('2','sys/user','user',NULL,'userList','用户列表','user','1','Y','0');
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('3','sys/role','role',NULL,'roleList','角色列表','roleManage','1','Y','0');
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('4','Layout','/test','/test/test1','test','功能测试','form','0','N','0');
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('5','test/test1','test1','','test1','测试点一','form','4','Y','0');
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('6','test/test2','test2','','test2','测试点二','form','4','Y','0');
insert into `x_menu` (`menu_id`, `component`, `path`, `redirect`, `name`, `title`, `icon`, `parent_id`, `is_leaf`, `hidden`) values('7','test/test3','test3','','test3','测试点三','form','4','Y','0');

8. MenuServiceImpl

点击查看代码
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {
    @Override
    public List<Menu> getAllMenu() {
        // 一级菜单
        LambdaQueryWrapper<Menu> wrapper = new LambdaQueryWrapper();
        wrapper.eq(Menu::getParentId,0);
        List<Menu> menuList = this.list(wrapper);
        // 填充子菜单
        setMenuChildren(menuList);
        return menuList;
    }

    private void setMenuChildren(List<Menu> menuList) {
        if(menuList != null) {
            for (Menu menu:menuList) {
                LambdaQueryWrapper<Menu> subWrapper = new LambdaQueryWrapper<>();
                subWrapper.eq(Menu::getParentId, menu.getMenuId());
                List<Menu> subMenuList = this.list(subWrapper);
                menu.setChildren(subMenuList);
                // 递归
                setMenuChildren(subMenuList);
            }
        }
    }

}

9. 重启看一下效果


怪事,底下怎么有个输入框,删了删了

默认展开菜单

标签:角色,title,menu,menuList,设置,import,权限,id,icon
From: https://www.cnblogs.com/dljx-springboot/p/17554613.html

相关文章

  • 关于为IAM用户添加KMS权限-可以完成对EC2开关机以及创建EBS时引用KMS的权限策略
    在AWS中,从创建磁盘,或者从快照中创建EBS磁盘时,都可以选择指定的KMS加密这样IAM用户就必须得有KMS相关的权限,可以在IAM中添加策略、也可以在KMS中进行策略的添加这里笔者主要讲述在KMS的policy中,如何添加,可以将如下的json写入到密钥策略中Statement字段中{"Sid":"Allowus......
  • 帝国cms 全站伪静态规则设置
    帝国cms因为目前来说是免费使用得,而且对于数据承载量以及其他栏目设置方面还是比较友好得,现在大部分网站已经采用帝国cms系统来做了。伪静态相对于静态来说会有更多得好处,今天就说下帝国cms伪静态规则设置方面得问题帝国CMS伪静态nginx版:rewrite^([^\.]*)/listinfo-(.+?)-(.+......
  • python将文件夹设置为当前工作目录
    将文件夹设置为当前工作目录作为一名经验丰富的开发者,我将向你介绍如何使用Python将文件夹设置为当前工作目录。这个过程非常简单,只需要几个简单的步骤就可以完成。下面是整个过程的流程图:步骤操作1导入必要的模块2获取要设置的文件夹3使用os模块设置工作目录......
  • mysql root权限恢复
    1.首先停止​​MySQL​​服务:servicemysqldstop2.加参数启动​​mysql​​:/usr/bin/mysqld_safe--skip-grant-tables& 然后就可以无任何限制的访问mysql了3.root用户登陆系统:mysql-uroot-pmysql4.切换​​数据库​​:usemysql5.显示所有的表:showtables;这里就可以访问表......
  • 修改系统注册表文件,完美设置 Windows10 透明任务栏
    无需安装各种乱七八糟的任务栏透明软件,直接操作系统注册表文件,完美设置Windows10透明任务栏的方法分享。Windows10是一款广受欢迎的操作系统,其任务栏是用户操作系统的重要界面之一。对于那些想要定制其任务栏的用户来说,许多人希望使用透明的任务栏。在本文中,我们将介绍如何设置......
  • 设置软件开机自启的小技巧
    虽然现在大部分软件都可以设置开机自启动,但是不知道有多少人知道这个小技巧,我个人觉得这个还是挺好用,分享给大家将你想要自启动的软件的快捷方式,放到以下目录中即可C:\ProgramData\Microsoft\Windows\StartMenu\Programs\StartUp该目录为公共的开始菜单,开机自动启动的软件,可以......
  • PyCharm设置背景主题
    File->Settings->Appearance&Behavior->AppearanceIntellij:白色Darcula:黑色Highcontrast:亮黑色(高对比度) 1. Intellij:白色2. Darcula:黑色3. Highcontrast:亮黑色(高对比度) ......
  • ubuntu网络防火墙设置
    sudoufwstatus 查看防火墙状态sudoufwenable 开启防火墙sudoufwdisable 关闭防火墙sudoufwdefaultdeny  禁止所有外部访问sudoufwallow80  允许访问80sudoufwdeleteallow80  禁止访问80sudoufwallowfrom192.168.1.1  ......
  • Pycharm设置字体大小
    File->Settings->Editor->Font如下图:字体大小由17->24  ......
  • 角色管理
    1.复制把user.vue的内容全部复制粘贴到role.vue2.修改查询条件没有电话,给它删了用户名改成角色名称结果列表改为rolelist观察数据库只有三个字段role.vue点击查看代码<template><div><!--搜索栏--><el-cardid="search"><el-row>......