refactor: 移除菜单类型枚举编码转换逻辑,直接接受原始值(接口参数标准化)
This commit is contained in:
@@ -2,7 +2,6 @@ package com.youlai.boot.system.model.entity;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
|
||||||
import com.youlai.boot.system.enums.MenuTypeEnum;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ public class Menu {
|
|||||||
/**
|
/**
|
||||||
* 菜单类型(1-菜单;2-目录;3-外链;4-按钮权限)
|
* 菜单类型(1-菜单;2-目录;3-外链;4-按钮权限)
|
||||||
*/
|
*/
|
||||||
private MenuTypeEnum type;
|
private Integer type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路由名称(Vue Router 中定义的路由名称)
|
* 路由名称(Vue Router 中定义的路由名称)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.youlai.boot.system.model.form;
|
package com.youlai.boot.system.model.form;
|
||||||
|
|
||||||
import com.youlai.boot.system.enums.MenuTypeEnum;
|
|
||||||
import com.youlai.boot.common.model.KeyValue;
|
import com.youlai.boot.common.model.KeyValue;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -11,7 +10,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 菜单表单对象
|
* 菜单表单对象
|
||||||
*
|
*
|
||||||
* @author Ray
|
* @author Ray.Hao
|
||||||
* @since 2024/06/23
|
* @since 2024/06/23
|
||||||
*/
|
*/
|
||||||
@Schema(description = "菜单表单对象")
|
@Schema(description = "菜单表单对象")
|
||||||
@@ -28,7 +27,7 @@ public class MenuForm {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description = "菜单类型(1-菜单 2-目录 3-外链 4-按钮)")
|
@Schema(description = "菜单类型(1-菜单 2-目录 3-外链 4-按钮)")
|
||||||
private MenuTypeEnum type;
|
private Integer type;
|
||||||
|
|
||||||
@Schema(description = "路由名称")
|
@Schema(description = "路由名称")
|
||||||
private String routeName;
|
private String routeName;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.youlai.boot.system.model.vo;
|
package com.youlai.boot.system.model.vo;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.youlai.boot.system.enums.MenuTypeEnum;
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ public class MenuVO {
|
|||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Schema(description="菜单类型")
|
@Schema(description="菜单类型")
|
||||||
private MenuTypeEnum type;
|
private Integer type;
|
||||||
|
|
||||||
@Schema(description = "路由名称")
|
@Schema(description = "路由名称")
|
||||||
private String routeName;
|
private String routeName;
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
meta.setIcon(menu.getIcon());
|
meta.setIcon(menu.getIcon());
|
||||||
meta.setHidden(StatusEnum.DISABLE.getValue().equals(menu.getVisible()));
|
meta.setHidden(StatusEnum.DISABLE.getValue().equals(menu.getVisible()));
|
||||||
// 【菜单】是否开启页面缓存
|
// 【菜单】是否开启页面缓存
|
||||||
if (MenuTypeEnum.MENU.equals(menu.getType())
|
if (MenuTypeEnum.MENU.getValue().equals(menu.getType())
|
||||||
&& ObjectUtil.equals(menu.getKeepAlive(), 1)) {
|
&& ObjectUtil.equals(menu.getKeepAlive(), 1)) {
|
||||||
meta.setKeepAlive(true);
|
meta.setKeepAlive(true);
|
||||||
}
|
}
|
||||||
@@ -239,16 +239,16 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
@CacheEvict(cacheNames = "menu", key = "'routes'")
|
||||||
public boolean saveMenu(MenuForm menuForm) {
|
public boolean saveMenu(MenuForm menuForm) {
|
||||||
|
|
||||||
MenuTypeEnum menuType = menuForm.getType();
|
Integer menuType = menuForm.getType();
|
||||||
|
|
||||||
if (menuType == MenuTypeEnum.CATALOG) { // 如果是目录
|
if (MenuTypeEnum.CATALOG.getValue().equals(menuType)) { // 如果是目录
|
||||||
String path = menuForm.getRoutePath();
|
String path = menuForm.getRoutePath();
|
||||||
if (menuForm.getParentId() == 0 && !path.startsWith("/")) {
|
if (menuForm.getParentId() == 0 && !path.startsWith("/")) {
|
||||||
menuForm.setRoutePath("/" + path); // 一级目录需以 / 开头
|
menuForm.setRoutePath("/" + path); // 一级目录需以 / 开头
|
||||||
}
|
}
|
||||||
menuForm.setComponent("Layout");
|
menuForm.setComponent("Layout");
|
||||||
} else if (menuType == MenuTypeEnum.EXTLINK) { // 如果是外链
|
} else if (MenuTypeEnum.EXTLINK.getValue().equals(menuType)) {
|
||||||
|
// 外链菜单组件设置为 null
|
||||||
menuForm.setComponent(null);
|
menuForm.setComponent(null);
|
||||||
}
|
}
|
||||||
if (Objects.equals(menuForm.getParentId(), menuForm.getId())) {
|
if (Objects.equals(menuForm.getParentId(), menuForm.getId())) {
|
||||||
@@ -267,7 +267,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
entity.setParams(null);
|
entity.setParams(null);
|
||||||
}
|
}
|
||||||
// 新增类型为菜单时候 路由名称唯一
|
// 新增类型为菜单时候 路由名称唯一
|
||||||
if (MenuTypeEnum.MENU.equals(menuType)) {
|
if (MenuTypeEnum.MENU.getValue().equals(menuType)) {
|
||||||
Assert.isFalse(this.exists(new LambdaQueryWrapper<Menu>()
|
Assert.isFalse(this.exists(new LambdaQueryWrapper<Menu>()
|
||||||
.eq(Menu::getRouteName, entity.getRouteName())
|
.eq(Menu::getRouteName, entity.getRouteName())
|
||||||
.ne(menuForm.getId() != null, Menu::getId, menuForm.getId())
|
.ne(menuForm.getId() != null, Menu::getId, menuForm.getId())
|
||||||
@@ -436,7 +436,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
menu.setRouteName(entityName);
|
menu.setRouteName(entityName);
|
||||||
menu.setRoutePath(StrUtil.toSymbolCase(entityName, '-'));
|
menu.setRoutePath(StrUtil.toSymbolCase(entityName, '-'));
|
||||||
menu.setComponent(genConfig.getModuleName() + "/" + StrUtil.toSymbolCase(entityName, '-') + "/index");
|
menu.setComponent(genConfig.getModuleName() + "/" + StrUtil.toSymbolCase(entityName, '-') + "/index");
|
||||||
menu.setType(MenuTypeEnum.MENU);
|
menu.setType(MenuTypeEnum.MENU.getValue());
|
||||||
menu.setSort(sort);
|
menu.setSort(sort);
|
||||||
menu.setVisible(1);
|
menu.setVisible(1);
|
||||||
boolean result = this.save(menu);
|
boolean result = this.save(menu);
|
||||||
@@ -455,13 +455,13 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||||||
for (int i = 0; i < actions.length; i++) {
|
for (int i = 0; i < actions.length; i++) {
|
||||||
Menu button = new Menu();
|
Menu button = new Menu();
|
||||||
button.setParentId(menu.getId());
|
button.setParentId(menu.getId());
|
||||||
button.setType(MenuTypeEnum.BUTTON);
|
button.setType(MenuTypeEnum.BUTTON.getValue());
|
||||||
button.setName(actions[i]);
|
button.setName(actions[i]);
|
||||||
button.setPerm(permPrefix + perms[i]);
|
button.setPerm(permPrefix + perms[i]);
|
||||||
button.setSort(i + 1);
|
button.setSort(i + 1);
|
||||||
this.save(button);
|
this.save(button);
|
||||||
|
|
||||||
// 生成 treepath
|
// 生成treePath
|
||||||
button.setTreePath(treePath + "," + button.getId());
|
button.setTreePath(treePath + "," + button.getId());
|
||||||
this.updateById(button);
|
this.updateById(button);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user