菜单更新
This commit is contained in:
@@ -18,6 +18,7 @@ package org.nl.modules.system.rest;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -106,13 +107,12 @@ public class MenuController {
|
||||
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@SaCheckPermission("menu:list")
|
||||
public ResponseEntity<Object> getSuperior(@RequestBody List<String> ids) {
|
||||
public ResponseEntity<Object> getSuperior(@RequestBody JSONObject param) {
|
||||
Set<MenuDto> menuDtos = new LinkedHashSet<>();
|
||||
if (CollectionUtil.isNotEmpty(ids)) {
|
||||
for (String id : ids) {
|
||||
String id=param.getString("ids");
|
||||
if (StrUtil.isNotEmpty(id)) {
|
||||
MenuDto menuDto = menuService.findById(id);
|
||||
menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>()));
|
||||
}
|
||||
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menuDtos)), HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(menuService.getMenus(null), HttpStatus.OK);
|
||||
|
||||
@@ -7,10 +7,9 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.*;
|
||||
import org.nl.modules.common.utils.RedisUtils;
|
||||
import org.nl.modules.common.utils.SecurityUtils;
|
||||
import org.nl.modules.system.domain.Menu;
|
||||
import org.nl.modules.system.domain.Role;
|
||||
import org.nl.modules.system.domain.User;
|
||||
import org.nl.modules.system.domain.vo.MenuMetaVo;
|
||||
import org.nl.modules.system.domain.vo.MenuVo;
|
||||
import org.nl.modules.system.repository.UserRepository;
|
||||
@@ -109,7 +108,6 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public MenuDto menuJsonToMenuDto(JSONObject json) {
|
||||
MenuDto menuDto = new MenuDto();
|
||||
menuDto.setName(json.getString("title"));
|
||||
menuDto.setMenu_id(json.getString("menu_id"));
|
||||
menuDto.setType(json.getInteger("type"));
|
||||
menuDto.setPermission(json.getString("permission"));
|
||||
@@ -117,12 +115,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
menuDto.setMenu_sort(json.getInteger("menu_sort"));
|
||||
menuDto.setPath(json.getString("path"));
|
||||
menuDto.setComponent(json.getString("component"));
|
||||
|
||||
if (StrUtil.isNotEmpty(json.getString("pid"))) {
|
||||
menuDto.setPid(json.getString("pid"));
|
||||
} else {
|
||||
menuDto.setPid(null);
|
||||
}
|
||||
menuDto.setPid(json.getString("pid"));
|
||||
|
||||
menuDto.setSub_count(json.getInteger("sub_count"));
|
||||
menuDto.setI_frame("1".equals(json.getString("i_frame")));
|
||||
@@ -237,7 +230,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
// 菜单表【sys_menu】
|
||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||
JSONArray menus;
|
||||
if (pid != null && !pid.equals(0L)) {
|
||||
if (pid != null && !pid.equals("0")) {
|
||||
menus = menuTab.query("menu_id = '" + pid + "'").getResultJSONArray(0);
|
||||
} else {
|
||||
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
|
||||
@@ -255,7 +248,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public List<MenuDto> getSuperior(MenuDto menuDto, List<MenuDto> menus) {
|
||||
WQLObject menuTab = WQLObject.getWQLObject("sys_menu");
|
||||
if (menuDto.getPid() == null) {
|
||||
if (StrUtil.isEmpty(menuDto.getPid())) {
|
||||
JSONArray arr = menuTab.query("pid is null").getResultJSONArray(0);
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
JSONObject json = arr.getJSONObject(i);
|
||||
@@ -277,7 +270,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
List<MenuDto> trees = new ArrayList<>();
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (MenuDto menuDTO : menuDtos) {
|
||||
if (menuDTO.getPid() == null) {
|
||||
if (ObjectUtil.isEmpty(menuDTO.getPid())) {
|
||||
trees.add(menuDTO);
|
||||
}
|
||||
for (MenuDto it : menuDtos) {
|
||||
@@ -305,13 +298,13 @@ public class MenuServiceImpl implements MenuService {
|
||||
MenuVo menuVo = new MenuVo();
|
||||
menuVo.setName(ObjectUtil.isNotEmpty(menuDTO.getComponent_name()) ? menuDTO.getComponent_name() : menuDTO.getTitle());
|
||||
// 一级目录需要加斜杠,不然会报警告
|
||||
menuVo.setPath(menuDTO.getPid() == null ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||
menuVo.setPath(StrUtil.isEmpty(menuDTO.getPid()) ? "/" + menuDTO.getPath() : menuDTO.getPath());
|
||||
menuVo.setHidden(menuDTO.getHidden());
|
||||
// 如果不是外链
|
||||
if (!menuDTO.getI_frame()) {
|
||||
if (menuDTO.getPid() == null) {
|
||||
if (StrUtil.isEmpty(menuDTO.getPid()) ) {
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "Layout" : menuDTO.getComponent());
|
||||
} else if (menuDTO.getPid() != null && menuDTO.getType() == 0) {
|
||||
} else if (!StrUtil.isEmpty(menuDTO.getPid()) && menuDTO.getType() == 0) {
|
||||
menuVo.setComponent(StrUtil.isEmpty(menuDTO.getComponent()) ? "ParentView" : menuDTO.getComponent());
|
||||
|
||||
} else if (!StrUtil.isEmpty(menuDTO.getComponent())) {
|
||||
@@ -324,7 +317,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
menuVo.setRedirect("noredirect");
|
||||
menuVo.setChildren(buildMenus(menuDtoList));
|
||||
// 处理是一级菜单并且没有子菜单的情况
|
||||
} else if (menuDTO.getPid() == null) {
|
||||
} else if (StrUtil.isEmpty(menuDTO.getPid())) {
|
||||
MenuVo menuVo1 = new MenuVo();
|
||||
menuVo1.setMeta(menuVo.getMeta());
|
||||
// 非外链
|
||||
|
||||
@@ -31,7 +31,10 @@ export function getSelectList() {
|
||||
}
|
||||
|
||||
export function getMenuSuperior(ids) {
|
||||
const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
|
||||
// const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
|
||||
const data = {
|
||||
'ids': ids
|
||||
}
|
||||
return request({
|
||||
url: 'api/menus/superior',
|
||||
method: 'post',
|
||||
|
||||
@@ -277,7 +277,7 @@ export default {
|
||||
[CRUD.HOOK.afterToCU](crud, form) {
|
||||
this.menus = []
|
||||
if (form.menu_id) { // 修改
|
||||
if (form.pid === null) { // 一级菜单,一级的父级菜单的pid为0.
|
||||
if (!form.pid) { // 一级菜单,一级的父级菜单的pid为0.
|
||||
form.pid = 0
|
||||
}
|
||||
this.getSupDepts(form.menu_id)
|
||||
|
||||
Reference in New Issue
Block a user