feat:新增菜单逻辑
新增菜单的上移和下移操作
This commit is contained in:
parent
f2f9cb308b
commit
ca3c5fd2c9
@ -47,6 +47,19 @@ public class MenuController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上移/下移菜单
|
||||||
|
*/
|
||||||
|
@PostMapping("/changeOrder")
|
||||||
|
public ResponseResult changeOrder(@RequestParam String menuId, @RequestParam String direction) {
|
||||||
|
boolean result = menuService.changeOrder(menuId, direction);
|
||||||
|
if (result) {
|
||||||
|
return ResponseResult.success();
|
||||||
|
} else {
|
||||||
|
return ResponseResult.error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************
|
/***********************************
|
||||||
* 用途说明:修改菜单及按钮根据ID
|
* 用途说明:修改菜单及按钮根据ID
|
||||||
* 参数说明
|
* 参数说明
|
||||||
|
@ -49,4 +49,7 @@ public interface IMenuService extends IService<Menu> {
|
|||||||
* 返回值说明: 菜单结构树集合
|
* 返回值说明: 菜单结构树集合
|
||||||
***********************************/
|
***********************************/
|
||||||
List<Map<String, Object>> permissionAssignment(String appId ,String roleId);
|
List<Map<String, Object>> permissionAssignment(String appId ,String roleId);
|
||||||
|
|
||||||
|
boolean changeOrder(String menuId, String direction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -214,6 +214,56 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
|||||||
return listTree;
|
return listTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean changeOrder(String menuId, String direction) {
|
||||||
|
Menu currentMenu = menuMapper.selectById(menuId);
|
||||||
|
if (currentMenu == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String parentId = currentMenu.getParentid();
|
||||||
|
|
||||||
|
QueryWrapper<Menu> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("parentid", parentId);
|
||||||
|
wrapper.orderByAsc("orderno");
|
||||||
|
|
||||||
|
List<Menu> siblings = menuMapper.selectList(wrapper);
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
|
for (int i = 0; i < siblings.size(); i++) {
|
||||||
|
if (siblings.get(i).getId().equals(menuId)) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("up".equals(direction)) {
|
||||||
|
if (index > 0) {
|
||||||
|
swapOrder(siblings.get(index), siblings.get(index - 1));
|
||||||
|
} else {
|
||||||
|
return false; // 已是第一个,无法上移
|
||||||
|
}
|
||||||
|
} else if ("down".equals(direction)) {
|
||||||
|
if (index < siblings.size() - 1) {
|
||||||
|
swapOrder(siblings.get(index), siblings.get(index + 1));
|
||||||
|
} else {
|
||||||
|
return false; // 已是最后一个,无法下移
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false; // 方向错误
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void swapOrder(Menu m1, Menu m2) {
|
||||||
|
Integer temp = m1.getOrderno();
|
||||||
|
m1.setOrderno(m2.getOrderno());
|
||||||
|
m2.setOrderno(temp);
|
||||||
|
|
||||||
|
menuMapper.updateById(m1);
|
||||||
|
menuMapper.updateById(m2);
|
||||||
|
}
|
||||||
|
|
||||||
/**********************************
|
/**********************************
|
||||||
* 用途说明: 生成权菜单权限树
|
* 用途说明: 生成权菜单权限树
|
||||||
* 参数说明 sysMenus
|
* 参数说明 sysMenus
|
||||||
|
Loading…
Reference in New Issue
Block a user