当前位置:网站首页>Role authorization --- complete the addition and deletion of secondary menus by adding and deleting primary menus
Role authorization --- complete the addition and deletion of secondary menus by adding and deleting primary menus
2022-07-27 19:08:00 【It's too late】
Purpose :
Click on the first level menu , Finish adding the first level menu , meanwhile , The secondary menu can also be checked and added synchronously , Click Finish delete again . Click on the secondary menu , Finish adding or deleting
Detailed code
1,RoleFunctionsController
@RestController
public class RoleFunctionsController {
@Autowired
private IRoleFunService roleFunService;
/** * Add role permissions * @param roleFun * @return */
@PostMapping("/role-functions")
public JsonResult addRoleFunctions(@RequestBody RoleFun roleFun){
roleFunService.save(roleFun);
return new JsonResult(1,roleFun);
}
/** * Delete role permissions * @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));
// Consider the situation of superior authority
return new JsonResult(1,null);
}
}
2,role-list.html
Here I only list HTML Part of the code
<el-dialog title=" Role authorization " :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, // Permission tree current:null, dialogTreeVisible:false,// Display the permission tree dialog functions:null, // Authority data defaultProps:{
// Modify the name of the tree attribute children:'subFunctions', label:'name' } } }, methods:{
// Click a line in the list changeCurrent(row){
this.current = row; // Cancel all selection effects this.$refs.roleTable.clearSelection(); // Select the current row this.$refs.roleTable.toggleRowSelection(row); }, // Select a single line ,data Is the data of the current row ,row Is the object of the current line selectOne(data,row){
// Cancel all selection effects this.$refs.roleTable.clearSelection(); // Select the current row this.$refs.roleTable.toggleRowSelection(row); }, // Deselect all roles selectAll(){
this.$refs.roleTable.clearSelection(); }, // Show authorization tree showTreeDialog(){
if (this.current){
this.dialogTreeVisible = true; // Query permissions related to roles 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(" Please select a role "); } }, // Add the permission node on the tree checkTreeNode(arg1,arg2){
console.log(arg1) console.log(arg2) // Determine the current permission id It's enough to choose key in if (arg1.subFunctions != null){
if (arg2.checkedKeys.length > this.rolefunctionslist.length){
// Add the selected first level menu and the following second level menu // Add first level menu axios.post("/role-functions", {
roleId:this.current.id,funId:arg1.id}).then(value => {
if (value.data.code == 1){
this.$message(" Permission added successfully "); } }) // Traverse and add the secondary menu 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(" Permission added successfully "); } }) } }else if (arg2.checkedKeys.length <= this.rolefunctionslist.length){
// Delete the selected primary menu and the following secondary menu // Delete the first level menu axios.delete("/role-functions/"+this.current.id+"/"+arg1.id) .then(value => {
if (value.data.code == 1){
this.$message(" Permission deleted successfully "); } }); // Traverse and delete the secondary menu 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(" Permission deleted successfully "); } }); } } }else {
// Single add secondary menu 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(" Permission added successfully "); } }) }else {
axios.delete("/role-functions/"+this.current.id+"/"+arg1.id) // Pass on the current character id And current permissions id .then(value => {
if (value.data.code == 1){
this.$message(" Permission deleted successfully "); } }) } } }, }, mounted(){
// Hook function // Load all permissions axios.get("/functions").then(value => {
if (value.data.code == 1){
this.functions = value.data.data; } }) } }); </script>
边栏推荐
- C static method and non static method
- How to generate random numbers with standard distribution or Gaussian distribution
- Code interview of Amazon
- Ruiji takeout notes
- Unity learning notes (rigid body physics collider trigger)
- Performance analysis of continuous time systems (2) - second order system performance improvement methods PID, PR
- PHP string operation
- Word 2007+ tips
- Ridis command notes
- 图的遍历的定义以及深度优先搜索和广度优先搜索(二)
猜你喜欢

Led learning eye protection table lamp touch chip-dlt8t10s-jericho

Selenium自动化测试面试题全家桶

win10小技巧(1)——转移桌面位置

Leetcode brushes questions the next day

阿里云对象存储OSS的开通和使用

Performance analysis of continuous time system (1) - performance index and first and second order analysis of control system

MongoDB

Blog Garden beautification tutorial

连续时间系统的性能分析(1)-控制系统性能指标及一二阶分析

CMD 命令
随机推荐
Leetcode brushes questions the next day
【微信小程序】项目实战—抽签应用
自控原理学习笔记-系统稳定性分析(1)-BIBO稳定及Routh判据
贪心法,拟阵和亚模函数(refer)
Latex使用--subfigure竖排图形
The great idea of NS2
Selenium automated test interview questions family bucket
Low noise anion fan touch IC
NPM basic use
JDBC-MySql 01 JDBC操作MySql(增删改查)
WSN Journal indexed by SCI(转)
Usage of ref keyword
Collection of software design suggestions of "high cohesion and low coupling"
express
Latex使用-控制表格或者图形的显示位置
There is another example of repeater
Power control
微机原理学习笔记-常见寻址方式
PHP字符串操作
ref 关键字的用法