feat(system): 更新权限标识符并优化菜单类型枚举
This commit is contained in:
@@ -36,7 +36,7 @@ public class ConfigController {
|
||||
|
||||
@Operation(summary = "系统配置分页列表")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@ss.hasPerm('sys:config:query')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:config:list')")
|
||||
@Log( value = "系统配置分页列表",module = LogModuleEnum.SETTING)
|
||||
public PageResult<ConfigVO> page(@ParameterObject ConfigPageQuery configPageQuery) {
|
||||
IPage<ConfigVO> result = configService.page(configPageQuery);
|
||||
@@ -45,7 +45,7 @@ public class ConfigController {
|
||||
|
||||
@Operation(summary = "新增系统配置")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:config:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:config:create')")
|
||||
@Log( value = "新增系统配置",module = LogModuleEnum.SETTING)
|
||||
public Result<?> save(@RequestBody @Valid ConfigForm configForm) {
|
||||
return Result.judge(configService.save(configForm));
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DeptController {
|
||||
|
||||
@Operation(summary = "新增部门")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:dept:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dept:create')")
|
||||
@RepeatSubmit
|
||||
public Result<?> saveDept(
|
||||
@Valid @RequestBody DeptForm formData
|
||||
@@ -72,7 +72,7 @@ public class DeptController {
|
||||
|
||||
@Operation(summary = "修改部门")
|
||||
@PutMapping(value = "/{deptId}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dept:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dept:update')")
|
||||
public Result<?> updateDept(
|
||||
@PathVariable Long deptId,
|
||||
@Valid @RequestBody DeptForm formData
|
||||
|
||||
@@ -77,7 +77,7 @@ public class DictController {
|
||||
|
||||
@Operation(summary = "新增字典")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict:create')")
|
||||
@RepeatSubmit
|
||||
public Result<?> saveDict(@Valid @RequestBody DictForm formData) {
|
||||
boolean result = dictService.saveDict(formData);
|
||||
@@ -90,7 +90,7 @@ public class DictController {
|
||||
|
||||
@Operation(summary = "修改字典")
|
||||
@PutMapping("/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict:update')")
|
||||
public Result<?> updateDict(
|
||||
@PathVariable Long id,
|
||||
@RequestBody DictForm dictForm
|
||||
@@ -148,7 +148,7 @@ public class DictController {
|
||||
|
||||
@Operation(summary = "新增字典项")
|
||||
@PostMapping("/{dictCode}/items")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict-item:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict-item:create')")
|
||||
@RepeatSubmit
|
||||
public Result<Void> saveDictItem(
|
||||
@PathVariable String dictCode,
|
||||
@@ -177,7 +177,7 @@ public class DictController {
|
||||
|
||||
@Operation(summary = "修改字典项")
|
||||
@PutMapping("/{dictCode}/items/{itemId}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict-item:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:dict-item:update')")
|
||||
@RepeatSubmit
|
||||
public Result<?> updateDictItem(
|
||||
@PathVariable String dictCode,
|
||||
|
||||
@@ -62,7 +62,7 @@ public class MenuController {
|
||||
|
||||
@Operation(summary = "菜单表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:update')")
|
||||
public Result<MenuForm> getMenuForm(
|
||||
@Parameter(description = "菜单ID") @PathVariable Long id
|
||||
) {
|
||||
@@ -72,7 +72,7 @@ public class MenuController {
|
||||
|
||||
@Operation(summary = "新增菜单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:create')")
|
||||
@RepeatSubmit
|
||||
public Result<?> addMenu(@RequestBody MenuForm menuForm) {
|
||||
boolean result = menuService.saveMenu(menuForm);
|
||||
@@ -81,7 +81,7 @@ public class MenuController {
|
||||
|
||||
@Operation(summary = "修改菜单")
|
||||
@PutMapping(value = "/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:update')")
|
||||
public Result<?> updateMenu(
|
||||
@RequestBody MenuForm menuForm
|
||||
) {
|
||||
@@ -101,7 +101,7 @@ public class MenuController {
|
||||
|
||||
@Operation(summary = "修改菜单显示状态")
|
||||
@PatchMapping("/{menuId}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:menu:update')")
|
||||
public Result<?> updateMenuVisible(
|
||||
@Parameter(description = "菜单ID") @PathVariable Long menuId,
|
||||
@Parameter(description = "显示状态(1:显示;0:隐藏)") Integer visible
|
||||
|
||||
@@ -37,7 +37,7 @@ public class NoticeController {
|
||||
|
||||
@Operation(summary = "通知公告分页列表")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:query')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:list')")
|
||||
public PageResult<NoticePageVO> getNoticePage(NoticePageQuery queryParams) {
|
||||
IPage<NoticePageVO> result = noticeService.getNoticePage(queryParams);
|
||||
return PageResult.success(result);
|
||||
@@ -45,7 +45,7 @@ public class NoticeController {
|
||||
|
||||
@Operation(summary = "新增通知公告")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:create')")
|
||||
public Result<?> saveNotice(@RequestBody @Valid NoticeForm formData) {
|
||||
boolean result = noticeService.saveNotice(formData);
|
||||
return Result.judge(result);
|
||||
@@ -53,7 +53,7 @@ public class NoticeController {
|
||||
|
||||
@Operation(summary = "获取通知公告表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:update')")
|
||||
public Result<NoticeForm> getNoticeForm(
|
||||
@Parameter(description = "通知公告ID") @PathVariable Long id
|
||||
) {
|
||||
@@ -72,7 +72,7 @@ public class NoticeController {
|
||||
|
||||
@Operation(summary = "修改通知公告")
|
||||
@PutMapping(value = "/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:notice:update')")
|
||||
public Result<Void> updateNotice(
|
||||
@Parameter(description = "通知公告ID") @PathVariable Long id,
|
||||
@RequestBody @Validated NoticeForm formData
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "新增角色")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:create')")
|
||||
@RepeatSubmit
|
||||
public Result<?> addRole(@Valid @RequestBody RoleForm roleForm) {
|
||||
boolean result = roleService.saveRole(roleForm);
|
||||
@@ -64,7 +64,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "获取角色表单数据")
|
||||
@GetMapping("/{roleId}/form")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:update')")
|
||||
public Result<RoleForm> getRoleForm(
|
||||
@Parameter(description = "角色ID") @PathVariable Long roleId
|
||||
) {
|
||||
@@ -74,7 +74,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "修改角色")
|
||||
@PutMapping(value = "/{id}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:update')")
|
||||
public Result<?> updateRole(@Valid @RequestBody RoleForm roleForm) {
|
||||
boolean result = roleService.saveRole(roleForm);
|
||||
return Result.judge(result);
|
||||
@@ -92,7 +92,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "修改角色状态")
|
||||
@PutMapping(value = "/{roleId}/status")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:update')")
|
||||
public Result<?> updateRoleStatus(
|
||||
@Parameter(description = "角色ID") @PathVariable Long roleId,
|
||||
@Parameter(description = "状态(1:启用;0:禁用)") @RequestParam Integer status
|
||||
@@ -112,6 +112,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "角色分配菜单权限")
|
||||
@PutMapping("/{roleId}/menus")
|
||||
@PreAuthorize("@ss.hasPerm('sys:role:assign')")
|
||||
public Result<Void> assignMenusToRole(
|
||||
@PathVariable Long roleId,
|
||||
@RequestBody List<Long> menuIds
|
||||
|
||||
@@ -68,7 +68,7 @@ public class UserController {
|
||||
|
||||
@Operation(summary = "新增用户")
|
||||
@PostMapping
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:add')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:create')")
|
||||
@RepeatSubmit
|
||||
@Log(value = "新增用户", module = LogModuleEnum.USER)
|
||||
public Result<?> saveUser(
|
||||
@@ -80,7 +80,7 @@ public class UserController {
|
||||
|
||||
@Operation(summary = "获取用户表单数据")
|
||||
@GetMapping("/{userId}/form")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:update')")
|
||||
@Log(value = "用户表单数据", module = LogModuleEnum.USER)
|
||||
public Result<UserForm> getUserForm(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId
|
||||
@@ -91,7 +91,7 @@ public class UserController {
|
||||
|
||||
@Operation(summary = "修改用户")
|
||||
@PutMapping(value = "/{userId}")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:update')")
|
||||
@Log(value = "修改用户", module = LogModuleEnum.USER)
|
||||
public Result<Void> updateUser(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||
@@ -114,7 +114,7 @@ public class UserController {
|
||||
|
||||
@Operation(summary = "修改用户状态")
|
||||
@PatchMapping(value = "/{userId}/status")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:edit')")
|
||||
@PreAuthorize("@ss.hasPerm('sys:user:update')")
|
||||
@Log(value = "修改用户状态", module = LogModuleEnum.USER)
|
||||
public Result<Void> updateUserStatus(
|
||||
@Parameter(description = "用户ID") @PathVariable Long userId,
|
||||
|
||||
@@ -5,28 +5,31 @@ import com.youlai.boot.common.base.IBaseEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 菜单类型枚举
|
||||
* 菜单类型枚举(char)
|
||||
*
|
||||
* @author Ray.Hao
|
||||
* @since 2022/4/23 9:36
|
||||
* C:目录
|
||||
* M:菜单
|
||||
* B:按钮
|
||||
*/
|
||||
@Getter
|
||||
public enum MenuTypeEnum implements IBaseEnum<Integer> {
|
||||
public enum MenuTypeEnum implements IBaseEnum<String> {
|
||||
|
||||
NULL(0, null),
|
||||
MENU(1, "菜单"),
|
||||
CATALOG(2, "目录"),
|
||||
EXTLINK(3, "外链"),
|
||||
BUTTON(4, "按钮");
|
||||
CATALOG("C", "目录"),
|
||||
MENU("M", "菜单"),
|
||||
BUTTON("B", "按钮");
|
||||
|
||||
// Mybatis-Plus 提供注解表示插入数据库时插入该值
|
||||
/**
|
||||
* 数据库存储值
|
||||
*/
|
||||
@EnumValue
|
||||
private final Integer value;
|
||||
private final String value;
|
||||
|
||||
// @JsonValue // 表示对枚举序列化时返回此字段
|
||||
/**
|
||||
* 友好名称
|
||||
*/
|
||||
private final String label;
|
||||
|
||||
MenuTypeEnum(Integer value, String label) {
|
||||
MenuTypeEnum(String value, String label) {
|
||||
this.value = value;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ public class Menu {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 菜单类型(1-菜单;2-目录;3-外链;4-按钮权限)
|
||||
* 菜单类型(C-目录 M-菜单 B-按钮)
|
||||
*/
|
||||
private Integer type;
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 路由名称(Vue Router 中定义的路由名称)
|
||||
|
||||
@@ -26,8 +26,8 @@ public class MenuForm {
|
||||
@Schema(description = "菜单名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "菜单类型(1-菜单 2-目录 3-外链 4-按钮)")
|
||||
private Integer type;
|
||||
@Schema(description = "菜单类型(C-目录 M-菜单 B-按钮)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "路由名称")
|
||||
private String routeName;
|
||||
|
||||
@@ -19,8 +19,8 @@ public class MenuVO {
|
||||
@Schema(description = "菜单名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description="菜单类型")
|
||||
private Integer type;
|
||||
@Schema(description="菜单类型(C-目录 M-菜单 B-按钮)")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "路由名称")
|
||||
private String routeName;
|
||||
|
||||
@@ -205,19 +205,25 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
*/
|
||||
private RouteVO toRouteVo(Menu menu) {
|
||||
RouteVO routeVO = new RouteVO();
|
||||
String routePath = menu.getRoutePath();
|
||||
boolean externalLink = StrUtil.startWithAny(routePath, "http://", "https://");
|
||||
|
||||
// 获取路由名称
|
||||
String routeName = menu.getRouteName();
|
||||
if (StrUtil.isBlank(routeName)) {
|
||||
// 路由 name 需要驼峰,首字母大写
|
||||
routeName = StringUtils.capitalize(StrUtil.toCamelCase(menu.getRoutePath(), '-'));
|
||||
// 外链不做驼峰转换,使用唯一占位,避免 http:// 被解析异常
|
||||
routeName = externalLink
|
||||
? "ext-" + menu.getId()
|
||||
: StringUtils.capitalize(StrUtil.toCamelCase(routePath, '-'));
|
||||
}
|
||||
// 根据name路由跳转 this.$router.push({name:xxx})
|
||||
routeVO.setName(routeName);
|
||||
|
||||
// 根据path路由跳转 this.$router.push({path:xxx})
|
||||
routeVO.setPath(menu.getRoutePath());
|
||||
routeVO.setPath(routePath);
|
||||
routeVO.setRedirect(menu.getRedirect());
|
||||
routeVO.setComponent(menu.getComponent());
|
||||
// 外链无组件
|
||||
routeVO.setComponent(externalLink ? null : menu.getComponent());
|
||||
|
||||
RouteVO.Meta meta = new RouteVO.Meta();
|
||||
meta.setTitle(menu.getName());
|
||||
@@ -253,7 +259,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
||||
public boolean saveMenu(MenuForm menuForm) {
|
||||
|
||||
Integer menuType = menuForm.getType();
|
||||
String menuType = menuForm.getType();
|
||||
boolean isExternalLink = MenuTypeEnum.MENU.getValue().equals(menuType)
|
||||
&& StrUtil.startWithAny(menuForm.getRoutePath(), "http://", "https://");
|
||||
|
||||
if (MenuTypeEnum.CATALOG.getValue().equals(menuType)) { // 如果是目录
|
||||
String path = menuForm.getRoutePath();
|
||||
@@ -261,8 +269,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
menuForm.setRoutePath("/" + path); // 一级目录需以 / 开头
|
||||
}
|
||||
menuForm.setComponent("Layout");
|
||||
} else if (MenuTypeEnum.EXTLINK.getValue().equals(menuType)) {
|
||||
// 外链菜单组件设置为 null
|
||||
} else if (isExternalLink) {
|
||||
// 外链菜单组件设置为 null,通过 routePath 判断外链
|
||||
menuForm.setComponent(null);
|
||||
}
|
||||
if (Objects.equals(menuForm.getParentId(), menuForm.getId())) {
|
||||
@@ -281,7 +289,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
entity.setParams(null);
|
||||
}
|
||||
// 新增类型为菜单时候 路由名称唯一
|
||||
if (MenuTypeEnum.MENU.getValue().equals(menuType)) {
|
||||
if (MenuTypeEnum.MENU.getValue().equals(menuType) && !isExternalLink) {
|
||||
Assert.isFalse(this.exists(new LambdaQueryWrapper<Menu>()
|
||||
.eq(Menu::getRouteName, entity.getRouteName())
|
||||
.ne(menuForm.getId() != null, Menu::getId, menuForm.getId())
|
||||
@@ -463,8 +471,8 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
||||
|
||||
// 生成CURD按钮权限
|
||||
String permPrefix = genConfig.getModuleName() + ":" + genConfig.getTableName().replace("_", "-") + ":";
|
||||
String[] actions = {"查询", "新增", "编辑", "删除"};
|
||||
String[] perms = {"query", "add", "edit", "delete"};
|
||||
String[] actions = {"查询", "新增", "修改", "删除"};
|
||||
String[] perms = {"list", "create", "update", "delete"};
|
||||
|
||||
for (int i = 0; i < actions.length; i++) {
|
||||
Menu button = new Menu();
|
||||
|
||||
Reference in New Issue
Block a user