diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java index 1dd7b93b5..b86cdaa05 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java @@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; @@ -143,6 +144,17 @@ public class SysMenuController extends BaseController return toAjax(menuService.updateMenu(menu)); } + /** + * 保存菜单排序 + */ + @PostMapping("/updateSort") + @ResponseBody + public AjaxResult updateSort(@RequestParam String[] menuIds, @RequestParam String[] orderNums) + { + menuService.updateMenuSort(menuIds, orderNums); + return success(); + } + /** * 选择菜单图标 */ diff --git a/ruoyi-admin/src/main/resources/templates/system/menu/menu.html b/ruoyi-admin/src/main/resources/templates/system/menu/menu.html index 45baba914..18093cff6 100644 --- a/ruoyi-admin/src/main/resources/templates/system/menu/menu.html +++ b/ruoyi-admin/src/main/resources/templates/system/menu/menu.html @@ -35,7 +35,10 @@ 修改 - + + 保存排序 + + 展开/折叠 @@ -52,6 +55,7 @@ var removeFlag = [[${@permission.hasPermi('system:menu:remove')}]]; var datas = [[${@dict.getType('sys_show_hide')}]]; var prefix = ctx + "system/menu"; + var originalOrders = {}; $(function() { var options = { @@ -87,14 +91,20 @@ title: '排序', width: '10', widthUnit: '%', - align: "left" + align: "center", + formatter: function(value, row, index) { + var menuIdText = $.common.sprintf("", row.menuId); + var orderNumText = $.common.sprintf("", row.orderNum); + originalOrders[row.menuId] = row.orderNum; + return menuIdText + orderNumText; + } }, { field: 'url', title: '请求地址', width: '15', widthUnit: '%', - align: "left", + align: "center", formatter: function(value, row, index) { return $.table.tooltip(value); } @@ -104,7 +114,7 @@ field: 'menuType', width: '10', widthUnit: '%', - align: "left", + align: "center", formatter: function(value, item, index) { if (item.menuType == 'M') { return '目录'; @@ -122,7 +132,7 @@ title: '可见', width: '10', widthUnit: '%', - align: "left", + align: "center", formatter: function(value, row, index) { if (row.menuType == 'F') { return '-'; @@ -135,7 +145,7 @@ title: '权限标识', width: '15', widthUnit: '%', - align: "left", + align: "center", formatter: function(value, row, index) { return $.table.tooltip(value); } @@ -144,7 +154,7 @@ title: '操作', width: '20', widthUnit: '%', - align: "left", + align: "center", formatter: function(value, row, index) { var actions = []; actions.push('编辑 '); @@ -156,6 +166,25 @@ }; $.treeTable.init(options); }); + + /* 保存排序-菜单 */ + function saveSort() { + var changedMenuIds = []; + var changedOrderNums = []; + $("input[name='menuIds']").each(function() { + var menuId = $(this).val(); + var currentOrder = $(this).next("input[name='orderNums']").val(); + if (originalOrders[menuId] !== currentOrder) { + changedMenuIds.push(menuId); + changedOrderNums.push(currentOrder); + } + }); + if (changedMenuIds.length === 0) { + $.modal.alertWarning("未检测到排序修改"); + return; + } + $.operate.post(prefix + "/updateSort", { "menuIds": changedMenuIds.join(","), "orderNums": changedOrderNums.join(",") }); + } \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java index 1b7d4bff6..dd7f19e7a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysMenuMapper.java @@ -121,6 +121,14 @@ public interface SysMenuMapper */ public int updateMenu(SysMenu menu); + /** + * 保存菜单排序 + * + * @param menuIds 菜单ID + * @param orderNums 排序ID + */ + public void updateMenuSort(SysMenu menu); + /** * 校验菜单名称是否唯一 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java index 58dfd689b..601a86cda 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysMenuService.java @@ -129,6 +129,14 @@ public interface ISysMenuService */ public int updateMenu(SysMenu menu); + /** + * 保存菜单排序 + * + * @param menuIds 菜单ID + * @param orderNums 排序ID + */ + public void updateMenuSort(String[] menuIds, String[] orderNums); + /** * 校验菜单名称是否唯一 * diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index 26020c2cd..17daddaf8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -11,11 +11,14 @@ import java.util.List; import java.util.Set; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.Ztree; import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.text.Convert; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.mapper.SysMenuMapper; import com.ruoyi.system.mapper.SysRoleMenuMapper; @@ -321,6 +324,31 @@ public class SysMenuServiceImpl implements ISysMenuService return menuMapper.updateMenu(menu); } + /** + * 保存菜单排序 + * + * @param menuIds 菜单ID + * @param orderNums 排序ID + */ + @Transactional + public void updateMenuSort(String[] menuIds, String[] orderNums) + { + try + { + for (int i = 0; i < menuIds.length; i++) + { + SysMenu menu = new SysMenu(); + menu.setMenuId(Convert.toLong(menuIds[i])); + menu.setOrderNum(orderNums[i]); + menuMapper.updateMenuSort(menu); + } + } + catch (Exception e) + { + throw new ServiceException("保存排序异常,请联系管理员"); + } + } + /** * 校验菜单名称是否唯一 * diff --git a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml index be4ef1a43..3d603921f 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml @@ -188,4 +188,10 @@ ) + + update sys_menu + set order_num = #{orderNum} + where menu_id = #{menuId} + + \ No newline at end of file