实战 9 权限菜单管理

目录

1、权限菜单后端接口

2、查询权限菜单列表

2.1 设计效果图

2.2 menuList.vue

3、 新增权限菜单

3.1 新增权限菜单窗口代码

3.2 选择所属菜单代码

3.3 封装图标选择器

3.4 新增、编辑和删除权限菜单


1、权限菜单后端接口

package com.cizhu.service;import com.cizhu.entity.Permission;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cizhu.vo.query.PermissionQueryVo;import java.util.List;/*** <p>*  服务类* </p>** @author cizhu* @since 2023-12-14*/
public interface IPermissionService extends IService<Permission> {/*** 根据用户ID查询菜单列表* @param userId* @return*/List<Permission> findPermissionListByUserId(Long userId);List<Permission> findPermissionList(PermissionQueryVo permissionQueryVo);boolean hasChildrenOfPermission(Long id);List<Permission> findParentPermissionList();
}
package com.cizhu.service.impl;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cizhu.entity.Permission;
import com.cizhu.mapper.PermissionMapper;
import com.cizhu.service.IPermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cizhu.utils.MenuTree;
import com.cizhu.vo.query.PermissionQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.util.Arrays;
import java.util.List;/*** <p>*  服务实现类* </p>** @author cizhu* @since 2023-12-14*/
@Service
@Transactional
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements IPermissionService {@Overridepublic List<Permission> findPermissionListByUserId(Long userId) {return baseMapper.findPermissionListByUserId(userId);}@Overridepublic List<Permission> findPermissionList(PermissionQueryVo permissionQueryVo) {//创建条件构造器对象QueryWrapper<Permission> queryWrapper = new QueryWrapper<Permission>();//排序queryWrapper.orderByAsc("order_num");//调用查询菜单列表的方法List<Permission> permissionList = baseMapper.selectList(queryWrapper);//生成菜单树List<Permission> menuTree = MenuTree.makeMenuTree(permissionList, 0L);//返回数据return menuTree;}@Overridepublic boolean hasChildrenOfPermission(Long id) {return false;}@Overridepublic List<Permission> findParentPermissionList() {QueryWrapper<Permission> queryWrapper = new QueryWrapper<Permission>();//只查询type为目录和菜单的数据(type=0或type=1)queryWrapper.in("type", Arrays.asList(0,1));//排序queryWrapper.orderByAsc("order_num");//查询菜单数据List<Permission> permissionList = baseMapper.selectList(queryWrapper);//构造顶级菜单信息,如果数据库中的菜单表没有数据,选择上级菜单时则显示顶级菜单Permission permission = new Permission();permission.setId(0L);permission.setParentId(-1L);permission.setLabel("顶级菜单");permissionList.add(permission);//将顶级菜单添加到集合//生成菜单数据List<Permission> menuTree = MenuTree.makeMenuTree(permissionList, -1L);//返回数据return menuTree;}}
package com.cizhu.controller;import com.cizhu.entity.Permission;
import com.cizhu.service.IPermissionService;
import com.cizhu.utils.Result;
import com.cizhu.vo.query.PermissionQueryVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;
import java.util.List;/*** <p>*  前端控制器* </p>** @author cizhu* @since 2023-12-14*/
@RestController
@RequestMapping("/api/permission")
public class PermissionController {@Resourceprivate IPermissionService permissionService;/*** 查询菜单列表* @param permissionQueryVo* @return*/@GetMapping("/getPermissionList")@PreAuthorize("hasAuthority('sys:menu:select')")public Result getPermissionList(PermissionQueryVo permissionQueryVo){List<Permission> resultPermissionList = permissionService.findPermissionList(permissionQueryVo);return Result.ok(resultPermissionList);}/*** 查询上级菜单列表* @return*/@GetMapping("/parent/list")public Result getParentPermissionList(){List<Permission> parentPermissionList = permissionService.findParentPermissionList();return Result.ok(parentPermissionList);}/*** 根据id查询菜单信息* @param id* @return*/@GetMapping("/{id}")public Result getMenuById(@PathVariable Long id){return Result.ok(permissionService.getById(id));}/*** 添加菜单* @param permission* @return*/@PostMapping("/addPermission")@PreAuthorize("hasAuthority('sys:menu:add')")public Result addPermission(@RequestBody Permission permission){if (permissionService.save(permission)) return Result.ok().message("菜单新增成功!");return Result.error().message("菜单新增失败!");}/*** 修改菜单* @param permission* @return*/@PutMapping("/editPermission")@PreAuthorize("hasAuthority('sys:menu:edit')")public Result editPermission(@RequestBody Permission permission){if(permissionService.updateById(permission)) return Result.ok().message("修改菜单成功!");return Result.error().message("修改菜单失败!");}/*** 根据id删除菜单* @param id* @return*/@DeleteMapping("/delete/{id}")@PreAuthorize("hasAuthority('sys:menu:delete')")public Result deletePermissionById(@PathVariable Long id){if (permissionService.removeById(id)) return Result.ok().message("删除菜单成功!");return Result.ok().message("删除菜单失败!");}/*** 检查菜单是否有子菜单* @param id* @return*/@GetMapping("/check/{id}")public Result hasChildrenOfPermission(@PathVariable Long id){if (permissionService.hasChildrenOfPermission(id)) {return Result.exist().message("该菜单下有子菜单,不能删除!");}return Result.ok();}}
package com.cizhu.entity;import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;/*** <p>* * </p>** @author cizhu* @since 2023-12-14*/
@Getter
@Setter
@TableName("sys_role_permission")
@ApiModel(value = "RolePermission对象", description = "")
public class RolePermission implements Serializable {private static final long serialVersionUID = 1L;@ApiModelProperty("角色ID")private Long roleId;@ApiModelProperty("权限ID")private Long permissionId;}
package com.cizhu.vo.query;import com.cizhu.entity.Permission;
import lombok.Data;@Data
public class PermissionQueryVo extends Permission {
}
package com.cizhu.entity;import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;/*** <p>* * </p>** @author cizhu* @since 2023-12-14*/
@Getter
@Setter
@TableName("sys_permission")
@ApiModel(value = "Permission对象", description = "")
public class Permission implements Serializable {/*** 子菜单列表*/@JsonInclude(JsonInclude.Include.NON_NULL) //属性值为null不进行序列化操作@TableField(exist = false)private List<Permission> children = new ArrayList<Permission>();/*** 用于前端判断是菜单、目录或按钮*/@TableField(exist = false)private String value;/*** 是否展开*/@TableField(exist = false)private Boolean open;private static final long serialVersionUID = 1L;@ApiModelProperty("权限编号")@TableId(value = "id", type = IdType.AUTO)private Long id;@ApiModelProperty("权限名称")private String label;@ApiModelProperty("父权限ID")private Long parentId;@ApiModelProperty("父权限名称")private String parentName;@ApiModelProperty("授权标识符")private String code;@ApiModelProperty("路由地址")private String path;@ApiModelProperty("路由名称")private String name;@ApiModelProperty("授权路径")private String url;@ApiModelProperty("权限类型(0-目录 1-菜单 2-按钮)")private Integer type;@ApiModelProperty("图标")private String icon;@ApiModelProperty("创建时间")private Date createTime;@ApiModelProperty("修改时间")private Date updateTime;@ApiModelProperty("备注")private String remark;@ApiModelProperty("排序")private Integer orderNum;@ApiModelProperty("是否删除(0-未删除,1-已删除)")private Integer isDelete;}

2、查询权限菜单列表

2.1 设计效果图

2.2 menuList.vue

列表页面原型代码,编写前端api脚本和页面组件代码

<template><el-main><!-- 新增按钮 --><el-button type="success" size="small" @click="openAddWindow()" icon="el-icon-plus">新增</el-button><!-- 数据表格 --><el-table style="margin-top: 10px" :height="tableHeight" :data="menuList" row-key="id"default-expand-all :tree-props="{ children: 'children' }" :border="true" stripe><el-table-column prop="label" label="菜单名称"></el-table-column><el-table-column prop="type" label="菜单类型" align="center"><template slot-scope="scope"><el-tag v-if="scope.row.type == '0'" size="normal">目录</el-tag><el-tag type="success" v-else-if="scope.row.type == '1'" size="normal">菜单</el-tag><el-tag type="warning" v-else-if="scope.row.type == '2'" size="normal">按钮</el-tag></template></el-table-column><el-table-column prop="icon" label="图标" align="center"><template slot-scope="scope"><i :class="scope.row.icon" v-if="scope.row.icon.includes('el-icon')" ></i><svg-icon v-else :icon-class="scope.row.icon"></svg-icon></template></el-table-column><el-table-column prop="name" label="路由名称"></el-table-column><el-table-column prop="path" label="路由地址"></el-table-column><el-table-column prop="url" label="组件路径"></el-table-column><el-table-column label="操作" align="center"><template slot-scope="scope"><el-button type="primary" icon="el-icon-edit" size="small" @click="editMenu(scope.row)">编辑</el-button><el-button type="danger" size="small" icon="el-icon-delete" @click="deleteMenu(scope.row)">删除</el-button></template></el-table-column></el-table></el-main>
</template><style lang="scss" scoped></style>

 menu.js

import http from '@/utils/request'export default {/*** 查询权限菜单列表* @param params*/async getMenuList(params){return await http.get("/api/permission/list",params);},/*** 获取上级菜单* @returns*/async getParentMenuList(params) {return await http.get("/api/permission/parent/list", params)},/*** 添加菜单* @returns*/async addMenu(params){return await http.post("/api/permission/add",params)},/*** 修改菜单* @returns*/async updateMenu(params) {return await http.put("/api/permission/update", params);},/*** 检查菜单下是否存在子菜单*/async checkPermission(param){return await http.getRestApi("/api/permission/check",param);},/*** 删除菜单* @returns*/async deleteById(params) {return await http.delete("/api/permission/delete", params);}
}

1) 菜单类型,图标

2)滚动条样式

public/index.html

 ::-webkit-scrollbar{width: 5px;height: 5px;background-color: #F5F5F5;}::-webkit-scrollbar-track {box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);border-radius: 8px;background-color: #F5F5F5;}::-webkit-scrollbar-thumb{border-radius: 8px;box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, .1);background-color: #c8c8c8;}

3、 新增权限菜单

3.1 新增权限菜单窗口代码

 <!-- 新增或编辑弹框 --><system-dialog:title="menuDialog.title":width="menuDialog.width":height="menuDialog.height":visible="menuDialog.visible"@onClose="onClose"@onConfirm="onConfirm"><div slot="content"><el-form :model="menu" ref="menuForm" :rules="rules" label-width="80px" :inline="true" size="small"><el-col :span="24"><el-form-item label="菜单类型" prop="type"><el-radio-group v-model="menu.type"><el-radio :label="0">目录</el-radio><el-radio :label="1">菜单</el-radio><el-radio :label="2">按钮</el-radio></el-radio-group></el-form-item></el-col><el-form-item label="所属菜单" size="small" prop="parentName"><el-input v-model="menu.parentName" :readonly="true" @click.native="selectParentMenu()" /></el-form-item><el-form-item label="菜单名称" size="small" prop="label"><el-input v-model="menu.label"></el-input></el-form-item><el-form-item label="路由名称" size="small" prop="name" v-if="menu.type == 1"><el-input v-model="menu.name"></el-input></el-form-item><el-form-item label="路由地址" size="small" prop="path" v-if="menu.type != 2"><el-input v-model="menu.path"></el-input></el-form-item><el-form-item label="组件路径" size="small" prop="url" v-if="menu.type == 1"><el-input v-model="menu.url"></el-input></el-form-item><el-form-item label="权限字段" size="small" prop="code"><el-input v-model="menu.code"></el-input></el-form-item><el-form-item label="菜单图标" size="small" ><my-icon @selecticon="setIcon" ref="child"></my-icon></el-form-item><el-form-item label="菜单序号" size="small"><el-input v-model="menu.orderNum"></el-input></el-form-item></el-form></div></system-dialog>

3.2 选择所属菜单代码

<!-- 选择所属菜单弹框 --><system-dialog:title="parentDialog.title":width="parentDialog.width":height="parentDialog.height":visible="parentDialog.visible"@onClose="onParentClose"@onConfirm="onParentConfirm"><div slot="content"><el-treestyle="font-size: 14px"ref="parentTree":data="parentMenuList"node-key="id":props="defaultProps"empty-text="暂无数据":show-checkbox="false"default-expand-all:highlight-current="true":expand-on-click-node="false"@node-click="handleNodeClick"><div class="customer-tree-node" slot-scope="{ node, data }"><!-- 长度为0说明没有下级 --><span v-if="data.children.length == 0"><i class="el-icon-document" style="color: #8c8c8c; font-size: 18px"/></span><span v-else @click.stop="changeIcon(data)"><svg-icon v-if="data.open" icon-class="add-s"/><svg-icon v-else icon-class="sub-s"/></span><span style="margin-left: 3px">{{ node.label }}</span></div></el-tree></div></system-dialog>

3.3 封装图标选择器

utils/icons.js

export const elementIcons = ["platform-eleme", "eleme", "delete-solid", "delete",
"s-tools", "setting", "user-solid", "user", "phone", "phone-outline", "more",
"more-outline", "star-on", "star-off", "s-goods", "goods", "warning", "warningoutline", "question", "info", "remove", "circle-plus", "success", "error", "zoomin", "zoom-out", "remove-outline", "circle-plus-outline", "circle-check", "circleclose", "s-help", "help", "minus", "plus", "check", "close", "picture", "pictureoutline", "picture-outline-round", "upload", "upload2", "download", "camerasolid", "camera", "video-camera-solid", "video-camera", "message-solid", "bell",
"s-cooperation", "s-order", "s-platform", "s-fold", "s-unfold", "s-operation", "spromotion", "s-home", "s-release", "s-ticket", "s-management", "s-open", "s-shop",
"s-marketing", "s-flag", "s-comment", "s-finance", "s-claim", "s-custom", "sopportunity", "s-data", "s-check", "s-grid", "menu", "share", "d-caret", "caretleft", "caret-right", "caret-bottom", "caret-top", "bottom-left", "bottom-right",
"back", "right", "bottom", "top", "top-left", "top-right", "arrow-left", "arrowright", "arrow-down", "arrow-up", "d-arrow-left", "d-arrow-right", "video-pause",
"video-play", "refresh", "refresh-right", "refresh-left", "finished", "sort",
"sort-up", "sort-down", "rank", "loading", "view", "c-scale-to-original", "date",
"edit", "edit-outline", "folder", "folder-opened", "folder-add", "folder-remove",
"folder-delete", "folder-checked", "tickets", "document-remove", "documentdelete", "document-copy", "document-checked", "document", "document-add",
"printer", "paperclip", "takeaway-box", "search", "monitor", "attract", "mobile",
"scissors", "umbrella", "headset", "brush", "mouse", "coordinate", "magic-stick",
"reading", "data-line", "data-board", "pie-chart", "data-analysis", "collectiontag", "film", "suitcase", "suitcase-1", "receiving", "collection", "files",
"notebook-1", "notebook-2", "toilet-paper", "office-building", "school", "tablelamp", "house", "no-smoking", "smoking", "shopping-cart-full", "shopping-cart-1",
"shopping-cart-2", "shopping-bag-1", "shopping-bag-2", "sold-out", "sell",
"present", "box", "bank-card", "money", "coin", "wallet", "discount", "price-tag",
"news", "guide", "male", "female", "thumb", "cpu", "link", "connection", "open",
"turn-off", "set-up", "chat-round", "chat-line-round", "chat-square", "chat-dotround", "chat-dot-square", "chat-line-square", "message", "postcard", "position",
"turn-off-microphone", "microphone", "close-notification", "bangzhu", "time",
"odometer", "crop", "aim", "switch-button", "full-screen", "copy-document", "mic",
"stopwatch", "medal-1", "medal", "trophy", "trophy-1", "first-aid-kit",
"discover", "place", "location", "location-outline", "location-information", "addlocation", "delete-location", "map-location", "alarm-clock", "timer", "watch-1",
"watch", "lock", "unlock", "key", "service", "mobile-phone", "bicycle", "truck",
"ship", "basketball", "football", "soccer", "baseball", "wind-power", "lightrain", "lightning", "heavy-rain", "sunrise", "sunrise-1", "sunset", "sunny",
"cloudy", "partly-cloudy", "cloudy-and-sunny", "moon", "moon-night", "dish",
"dish-1", "food", "chicken", "fork-spoon", "knife-fork", "burger", "tableware",
"sugar", "dessert", "ice-cream", "hot-water", "water-cup", "coffee-cup", "colddrink", "goblet", "goblet-full", "goblet-square", "goblet-square-full",
"refrigerator", "grape", "watermelon", "cherry", "apple", "pear", "orange",
"coffee", "ice-tea", "ice-drink", "milk-tea", "potato-strips", "lollipop", "icecream-square", "ice-cream-round"].map(s => "el-icon-" + s);
    /*** 切换图标* @param data*/changeIcon(data) {data.ope = !data.openthis.$refs.parentTree.store.nodesMap[data.id].expanded = !data.open},//给icon绑定的点击事件setIcon(icon) {this.menu.icon = icon;},

 

<template><div class="chooseIcons"><el-popover placement="bottom" width="450" trigger="click"><span slot="reference" style="display: inline-block;width: 200px;height: 33px;line-height: 33px;"><i :class="userChooseIcon"></i>{{ userChooseIcon }}</span><div class="iconList"><i v-for="item in iconList" :key="item" :class="item" @click="setIcon(item)" style="font-size: 20px"></i></div></el-popover></div>
</template>
<script>
//导入自定义的icon图标库
import { elementIcons } from "@/utils/icons";export default {name: 'MyIcon',data(){return{userChooseIcon:"",//用户选中的图标iconList:[],//图标列表}},created() {//获取图标列表this.getIconList();},methods:{/*** 获取图标列表*/getIconList(){this.iconList = elementIcons;},//给icon绑定的点击事件setIcon(icon) {//将i的样式设为选中的样式el-icon-xxxthis.userChooseIcon = icon;//将选中的图标传递给父组件this.$emit("selecticon",icon)},}
}
</script><style scoped lang="scss">
.iconList {width: 400px;height: 300px;overflow-y: scroll;overflow-x: hidden;display: flex;justify-content: space-around;flex-wrap: wrap;i {display: inline-block;width: 60px;height: 45px;color: #000000;font-size: 20px;border: 1px solid #e6e6e6;border-radius: 4px;cursor: pointer;text-align: center;line-height: 45px;margin: 5px;&:hover {color: orange;border-color:orange;}}
}.chooseIcons{width: 175px;background-color: #FFFFFF;background-image: none;border-radius: 4px;border: 1px solid #DCDFE6;box-sizing: border-box;color: #606266;display: inline-block;font-size: inherit;height: 33px;line-height: 25px;outline: none;padding: 0 15px;transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}
</style>

3.4 新增、编辑和删除权限菜单

<template><el-main><!-- 新增按钮 --><el-button type="success" size="small" @click="openAddWindow()" icon="el-icon-plus">新增</el-button><!-- 数据表格 --><el-table style="margin-top: 10px" :height="tableHeight" :data="menuList" row-key="id"default-expand-all :tree-props="{ children: 'children' }" :border="true" stripe><el-table-column prop="label" label="菜单名称"></el-table-column><el-table-column prop="type" label="菜单类型" align="center"><template slot-scope="scope"><el-tag v-if="scope.row.type == '0'" size="normal">目录</el-tag><el-tag type="success" v-else-if="scope.row.type == '1'" size="normal">菜单</el-tag><el-tag type="warning" v-else-if="scope.row.type == '2'" size="normal">按钮</el-tag></template></el-table-column><el-table-column prop="icon" label="图标" align="center"><template slot-scope="scope"><i :class="scope.row.icon" v-if="scope.row.icon.includes('el-icon')" ></i><svg-icon v-else :icon-class="scope.row.icon"></svg-icon></template></el-table-column><el-table-column prop="name" label="路由名称"></el-table-column><el-table-column prop="path" label="路由地址"></el-table-column><el-table-column prop="url" label="组件路径"></el-table-column><el-table-column label="操作" align="center"><template slot-scope="scope"><el-button type="primary" icon="el-icon-edit" size="small" @click="editMenu(scope.row)">编辑</el-button><el-button type="danger" size="small" icon="el-icon-delete" @click="deleteMenu(scope.row)">删除</el-button></template></el-table-column></el-table><!-- 新增或编辑弹框 --><system-dialog:title="menuDialog.title":width="menuDialog.width":height="menuDialog.height":visible="menuDialog.visible"@onClose="onClose"@onConfirm="onConfirm"><div slot="content"><el-form :model="menu" ref="menuForm" :rules="rules" label-width="80px" :inline="true" size="small"><el-col :span="24"><el-form-item label="菜单类型" prop="type"><el-radio-group v-model="menu.type"><el-radio :label="0">目录</el-radio><el-radio :label="1">菜单</el-radio><el-radio :label="2">按钮</el-radio></el-radio-group></el-form-item></el-col><el-form-item label="所属菜单" size="small" prop="parentName"><el-input v-model="menu.parentName" :readonly="true" @click.native="selectParentMenu()" /></el-form-item><el-form-item label="菜单名称" size="small" prop="label"><el-input v-model="menu.label"></el-input></el-form-item><el-form-item label="路由名称" size="small" prop="name" v-if="menu.type == 1"><el-input v-model="menu.name"></el-input></el-form-item><el-form-item label="路由地址" size="small" prop="path" v-if="menu.type != 2"><el-input v-model="menu.path"></el-input></el-form-item><el-form-item label="组件路径" size="small" prop="url" v-if="menu.type == 1"><el-input v-model="menu.url"></el-input></el-form-item><el-form-item label="权限字段" size="small" prop="code"><el-input v-model="menu.code"></el-input></el-form-item><el-form-item label="菜单图标" size="small" ><my-icon @selecticon="setIcon" ref="child"></my-icon></el-form-item><el-form-item label="菜单序号" size="small"><el-input v-model="menu.orderNum"></el-input></el-form-item></el-form></div></system-dialog><!-- 选择所属菜单弹框 --><system-dialog:title="parentDialog.title":width="parentDialog.width":height="parentDialog.height":visible="parentDialog.visible"@onClose="onParentClose"@onConfirm="onParentConfirm"><div slot="content"><el-treestyle="font-size: 14px"ref="parentTree":data="parentMenuList"node-key="id":props="defaultProps"empty-text="暂无数据":show-checkbox="false"default-expand-all:highlight-current="true":expand-on-click-node="false"@node-click="handleNodeClick"><div class="customer-tree-node" slot-scope="{ node, data }"><!-- 长度为0说明没有下级 --><span v-if="data.children.length == 0"><i class="el-icon-document" style="color: #8c8c8c; font-size: 18px"/></span><span v-else @click.stop="changeIcon(data)"><svg-icon v-if="data.open" icon-class="add-s"/><svg-icon v-else icon-class="sub-s"/></span><span style="margin-left: 3px">{{ node.label }}</span></div></el-tree></div></system-dialog></el-main>
</template><script>
// 导入menu脚本文件
import menuApi from '@/api/menu'
//导入自定义图标组件
import MyIcon from '@/components/system/MyIcon.vue'
// 导入对话框组件
import SystemDialog from '@/components/system/SystemDialog.vue'export default {name: 'menuList',//注册组件components:{ SystemDialog, MyIcon },data() {return {//新增或编辑弹框属性menuDialog: {title: "",width: 630,height: 270,visible: false,},//菜单属性menu: {id: "",type: "",parentId: "",parentName: "",label: "",icon: "",name: "",path: "",url: "",code: "",orderNum: "",},rules: {type: [{ required: true, trigger: "change", message: "请选择菜单类型" }],parentName: [{ required: true, trigger: "change", message: "请选择所属菜单"}],label: [{ required: true, trigger: "blur", message: "请输入菜单名称" }],name: [{ required: true, trigger: "blur", message: "请输入路由名称" }],path: [{ required: true, trigger: "blur", message: "请输入路由路径" }],url: [{ required: true, trigger: "blur", message: "请输入组件路径" }],code: [{ required: true, trigger: "blur", message: "请输入权限字段" }],},parentDialog: {title: '选择所属菜单',width: 280,height: 450,visible: false},//树属性定义defaultProps: {children: 'children',label: 'label'},menuList: [],       //菜单列表tableHeight: 0,     //表格高度parentMenuList: [], //所属菜单列表}},mounted() {this.$nextTick(() => {this.tableHeight = window.innerHeight - 180})},//初始化时调用created(){//调用查询菜单列表的方法this.search()},mounted() {this.$nextTick(() => {this.tableHeight = window.innerHeight - 180})},methods:{/*** 选择所属菜单*/async selectParentMenu() {//显示窗口this.parentDialog.visible = true;//发送查询请求let res = await menuApi.getParentMenuList();//判断是否成功if (res.success) {//赋值this.parentMenuList = res.data;}},/*** 查询菜单列表*/async search() {//发送查询请求let res = await menuApi.getMenuList();//判断是否成功if(res.success){//赋值this.menuList = res.data;}},/*** 编辑菜单* @param row*/editMenu(row){//把当前要编辑的数据复制到数据域,给表单回显this.$objCopy(row, this.menu);//设置弹框属性this.menuDialog.title = "编辑菜单";this.menuDialog.visible = true;this.$nextTick(() => {this.$refs["child"].userChooseIcon = row.icon;//菜单图标回显})},/*** 删除菜单* @param row*/async deleteMenu(row){//判断是否存在子菜单let result = await menuApi.checkPermission({ id: row.id });//判断是否可以删除if (!result.success) {//提示不能删除this.$message.warning(result.message);} else {//确认是否删除let confirm =await this.$myconfirm("确定要删除该数据吗?");if (confirm) {//发送删除请求let res = await menuApi.deleteById({ id: row.id });//判断是否成功if (res.success) {//成功提示this.$message.success(res.message);//刷新this.search();} else {//失败提示this.$message.error(res.message);}}}},/*** 打开新增窗口*/openAddWindow(){this.$resetForm("menuForm", this.menu) //清空表单数据this.menuDialog.title = "新增菜单"      //设置窗口标题this.menuDialog.visible = true         //显示窗口this.$nextTick(() => {this.$refs['child'].userChooseIcon = '' // 清空菜单图标 })},/*** 选择所属菜单取消事件*/onParentClose() {this.parentDialog.visible = false //关闭窗口},/*** 选择所属菜单确认事件*/onParentConfirm() {this.parentDialog.visible = false //关闭窗口},/*** 添加和修改菜单窗口关闭事件*/onClose() {this.menuDialog.visible = false; //关闭窗口},/*** 添加和修改菜单窗口确认事件*/onConfirm() {//表单验证this.$refs.menuForm.validate(async (valid) => {if (valid) {let res = null;//判断菜单ID是否为空if (this.menu.id === "") {//发送添加请求res = await menuApi.addMenu(this.menu);} else {//发送修改请求res = await menuApi.updateMenu(this.menu);}//判断是否成功if (res.success) {this.$message.success(res.message);//刷新//this.search();window.location.reload();//关闭窗口this.menuDialog.visible = false;} else {this.$message.error(res.message);}this.menuDialog.visible = false; //关闭窗口}});},/*** 所属菜单节点点击事件*/handleNodeClick(data) {//所属父级菜单IDthis.menu.parentId = data.id;//所属父级菜单名称this.menu.parentName = data.label;},/*** 切换图标* @param data*/changeIcon(data) {data.open = !data.openthis.$refs.parentTree.store.nodesMap[data.id].expanded = !data.open},//给icon绑定的点击事件setIcon(icon) {this.menu.icon = icon;},}
}
</script>
<style lang="scss" scoped>
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/225083.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[SWPUCTF 2021 新生赛]hardrce

[SWPUCTF 2021 新生赛]hardrce wp 参考博客&#xff1a;https://www.cnblogs.com/bkofyZ/p/17644820.html 代码审计 题目的代码如下&#xff1a; <?php header("Content-Type:text/html;charsetutf-8"); error_reporting(0); highlight_file(__FILE__); if(is…

【MATLAB库函数系列】线性调频Z(Chirp-Z,CZT)的MATLAB源码和C语言实现

在上一篇博客 【数字信号处理】线性调频Z(Chirp-Z,CZT)算法详解 已经详细介绍了CZT变换的应用背景和原理,先回顾一下: 回顾CZT算法 采用 FFT 算法可以很快计算出全部 N N N点 DFT 值,即Z变换 X ( z ) X(z) <

JVM初识-----01章

一.虚拟机与java虚拟机的区别以及共同点 1.虚拟机&#xff08;Virtual Machine&#xff0c;简称VM&#xff09; 是一种能够在物理计算机上模拟一台完整的计算机系统的软件。它运行在宿主操作系统之上&#xff0c;可以提供一个独立的运行环境&#xff0c;使得在不同的操作系统上…

Vue实现响应式布局

前提准备&#xff1a;响应式布局有两种方法&#xff0c;看自己想要哪种。 方法一&#xff1a;百分比 用百分比去写元素的宽度&#xff0c;然后让子元素撑起父元素的高度 .parent {width: 50%; }.child {width:100%;height:100px; } 方法二&#xff1a;vh、vw vw、vh是基于视…

如何使用kali来进行一次ddos攻击

本文章用于记录自己的学习路线&#xff0c;不用于其他任何途径! ! ! 哈喽啊&#xff01;又是好久不见&#xff0c;本博主在之前发过一个ddos攻击的介绍。 emm…虽然那篇文章也提到了ddos攻击的方式&#xff0c;但太过于简陋&#xff0c;好像也没有什么用&#xff0c;so&#…

Docker实用篇

文章目录 Docker实用篇0.学习目标1.初识Docker1.1.什么是Docker1.1.1.应用部署的环境问题1.1.2.Docker解决依赖兼容问题1.1.3.Docker解决操作系统环境差异1.1.4.小结 1.2.Docker和虚拟机的区别1.3.Docker架构1.3.1.镜像和容器1.3.2.DockerHub1.3.3.Docker架构1.3.4.小结 1.4.安…

mac电脑系统性能检测:Geekbench 6最新 for mac

Geekbench 6是一款跨平台的性能测试软件&#xff0c;旨在全面衡量电脑在不同任务和应用程序中的性能。它适用于Windows、macOS、Linux等操作系统&#xff0c;以及移动设备如Android和iOS。 Geekbench 6主要特点包括&#xff1a; 全面覆盖各种性能测试领域&#xff0c;包括CPU…

构建外卖系统:从技术到实战

在当今高度数字化的社会中&#xff0c;外卖系统的开发变得愈发重要。本文将从技术角度出发&#xff0c;带领读者一步步构建一个基础的外卖系统&#xff0c;并涵盖关键技术和实际代码。 1. 技术选型 1.1 后端开发 选择Node.js和Express框架进行后端开发&#xff0c;搭建一个灵…

ModuleNotFoundError: No module named ‘tensorflow‘

直接运行pip install tensorflow安装成功之后&#xff0c;发现版本是tensorflow2.15.0 python的版本是3.9版本 导入包&#xff1a;import tensorflow 打包xxx.exe,调用之后提示错误 ModuleNotFoundError: No module named tensorflow 最后发现特定的python的版本对应特定的t…

ioDraw AI:思维导图、流程图、序列图、类图、饼图,一应俱全

前言 在信息爆炸的时代&#xff0c;我们每天接收着大量的信息&#xff0c;如何高效地整理和呈现这些信息成为了一项重要的挑战。思维导图作为一种可视化思维工具&#xff0c;能够帮助我们快速构建和整理复杂的信息结构&#xff0c;便于我们理解和记忆。ioDraw AI绘图工具正是基…

【集合】Vector与CopyOnWriteArrayList

前言&#xff1a; 此篇博客着重于&#xff1a;在多线程并发执行读、写操作的场景下&#xff0c;Vector集合、CopyOnWriteArrayList集合是否能保证线程安全&#xff1f;它们是通过什么方式保证线程安全的&#xff1f; Vector&#xff1a; &#xff08;1&#xff09;add(E e)方法…

Android笔记(二十一):Room组件实现Android应用的持久化处理

一、Room组件概述 Room是Android JetPack架构组件之一&#xff0c;是一个持久处理的库。Room提供了在SQLite数据库上提供抽象层&#xff0c;使之实现数据访问。 &#xff08;1&#xff09;实体类&#xff08;Entity&#xff09;&#xff1a;映射并封装了数据库对应的数据表中…

【力扣】199.二叉树的右视图

看到这个题目的一瞬间&#xff0c;我想递归&#xff0c;必须用递归。最近被递归折磨的有点狠&#xff0c;但是我感觉我快要打败它了&#xff0c;就是现在稍稍有点处于劣势。不过没关系&#xff0c;来日方长不是。 法一&#xff1a;递归 题解&#xff1a; 之前想的就是先递归&…

漏洞复现-泛微OA xmlrpcServlet接口任意文件读取漏洞(附漏洞检测脚本)

免责声明 文章中涉及的漏洞均已修复&#xff0c;敏感信息均已做打码处理&#xff0c;文章仅做经验分享用途&#xff0c;切勿当真&#xff0c;未授权的攻击属于非法行为&#xff01;文章中敏感信息均已做多层打马处理。传播、利用本文章所提供的信息而造成的任何直接或者间接的…

Vue 封装echarts柱状图(Bar)组件

目的&#xff1a;减少重复代码&#xff0c;便于维护 显示效果 组件代码 <template><div class"ldw-data-content-box"><div class"ldw-chilren-box"><div class"title" v-if"title">{{ title }}</div>…

聊聊CLI:一个比NPS更全面、客观的体验指标

说起NPS&#xff08;Net Promoter Score&#xff0c;净推荐值&#xff09;大家一定不会感到陌生&#xff0c;它被誉为客户体验管理&#xff08;CEM&#xff09;领域的黄金指标&#xff0c;以“衡量客户忠诚度”而受到大家的认可和追捧。 然而&#xff0c;随着时间的推移和各行业…

Day72力扣打卡

打卡记录 参加考试的最大学生数&#xff08;压缩状态DP&#xff09; 链接 class Solution:def maxStudents(self, seats: List[List[str]]) -> int:m, n len(seats), len(seats[0])# a[i] 是第 i 排可用椅子的下标集合a [sum((c .) << j for j, c in enumerate(s…

C++学习实践(一)高频面试问题总结(附详细答案)

文章目录 一、基础常见面试题1、数组和链表区别2、深拷贝和浅拷贝相关问题的区别3、a和a区别4、c内存模型5、四种强制转换和应用场景 二、指针相关1、指针和引用的区别2、函数指针和指针函数3、传指针、引用和值4、常量指针和指针常量5、野指针6、智能指针的用法 三、关键字作用…

基于5G智能网关的智慧塔吊监测方案

塔吊是建筑施工中必不可少的设施&#xff0c;由于塔吊工作重心高、起重载荷大、人工视距/视角受限等因素&#xff0c;也使得塔吊在工作过程中着较多的危险因素。对此&#xff0c;可以部署基于工业5G智能网关搭建智慧塔吊安全监测系统&#xff0c;实现对塔吊运行的全局精细监测感…

web3风险投资公司之Electric Capital

文章目录 什么是 Electric CapitalElectric团队 Electric Capital 开发者报告参考 什么是 Electric Capital 官网&#xff1a;https://www.electriccapital.com/ 官方github&#xff1a;https://github.com/electric-capital Electric Capital 是一家投资于加密货币、区块链企…