菜单管理支持批量保存排序

springboot3
RuoYi 7 days ago
parent 4681d299d7
commit c363bf88f5

@ -1,6 +1,7 @@
package com.ruoyi.system.controller;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
@ -133,6 +134,20 @@ public class SysMenuController extends BaseController
return toAjax(menuService.updateMenu(menu));
}
/**
*
*/
@RequiresPermissions("system:menu:edit")
@Log(title = "保存菜单排序", businessType = BusinessType.UPDATE)
@PutMapping("/updateSort")
public AjaxResult updateSort(@RequestBody Map<String, String> params)
{
String[] menuIds = params.get("menuIds").split(",");
String[] orderNums = params.get("orderNums").split(",");
menuService.updateMenuSort(menuIds, orderNums);
return success();
}
/**
*
*/

@ -106,6 +106,13 @@ public interface SysMenuMapper
*/
public int updateMenu(SysMenu menu);
/**
*
*
* @param menu
*/
public void updateMenuSort(SysMenu menu);
/**
*
*

@ -126,6 +126,14 @@ public interface ISysMenuService
*/
public int updateMenu(SysMenu menu);
/**
*
*
* @param menuIds ID
* @param orderNums ID
*/
public void updateMenuSort(String[] menuIds, String[] orderNums);
/**
*
*

@ -12,8 +12,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysRole;
@ -321,6 +324,32 @@ public class SysMenuServiceImpl implements ISysMenuService
return menuMapper.updateMenu(menu);
}
/**
*
*
* @param menuIds ID
* @param orderNums ID
*/
@Override
@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(Convert.toInt(orderNums[i]));
menuMapper.updateMenuSort(menu);
}
}
catch (Exception e)
{
throw new ServiceException("保存排序异常,请联系管理员");
}
}
/**
*
*

@ -204,6 +204,10 @@
)
</insert>
<update id="updateMenuSort" parameterType="SysMenu">
update sys_menu set order_num = #{orderNum} where menu_id = #{menuId}
</update>
<delete id="deleteMenuById" parameterType="Long">
delete from sys_menu where menu_id = #{menuId}
</delete>

@ -51,6 +51,15 @@ export function updateMenu(data) {
})
}
// 保存菜单排序
export function updateMenuSort(data) {
return request({
url: '/system/menu/updateSort',
method: 'put',
data: data
})
}
// 删除菜单
export function delMenu(menuId) {
return request({

@ -36,6 +36,16 @@
v-hasPermi="['system:menu:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-check"
size="mini"
@click="handleSaveSort"
v-hasPermi="['system:menu:edit']"
>保存排序</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="info"
@ -62,7 +72,11 @@
<svg-icon :icon-class="scope.row.icon" />
</template>
</el-table-column>
<el-table-column prop="orderNum" label="排序" width="60"></el-table-column>
<el-table-column prop="orderNum" label="排序" width="200">
<template slot-scope="scope">
<el-input-number v-model="scope.row.orderNum" controls-position="right" :min="0" size="mini" style="width: 88px" />
</template>
</el-table-column>
<el-table-column prop="perms" label="权限标识" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="component" label="组件路径" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="status" label="状态" width="80">
@ -299,7 +313,7 @@
</template>
<script>
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu"
import { listMenu, getMenu, delMenu, addMenu, updateMenu, updateMenuSort } from "@/api/system/menu"
import Treeselect from "@riophae/vue-treeselect"
import "@riophae/vue-treeselect/dist/vue-treeselect.css"
import IconSelect from "@/components/IconSelect"
@ -326,6 +340,8 @@ export default {
isExpandAll: false,
//
refreshTable: true,
//
originalOrders: {},
//
queryParams: {
menuName: undefined,
@ -360,6 +376,8 @@ export default {
this.loading = true
listMenu(this.queryParams).then(response => {
this.menuList = this.handleTree(response.data, "menuId")
//
this.recordOriginalOrders(this.menuList)
this.loading = false
})
},
@ -463,6 +481,40 @@ export default {
}
})
},
/** 递归记录原始排序 */
recordOriginalOrders(list) {
list.forEach(item => {
this.originalOrders[item.menuId] = item.orderNum
if (item.children && item.children.length) {
this.recordOriginalOrders(item.children)
}
})
},
/** 保存排序 */
handleSaveSort() {
const changedMenuIds = []
const changedOrderNums = []
const collectChanged = (list) => {
list.forEach(item => {
if (String(this.originalOrders[item.menuId]) !== String(item.orderNum)) {
changedMenuIds.push(item.menuId)
changedOrderNums.push(item.orderNum)
}
if (item.children && item.children.length) {
collectChanged(item.children)
}
})
}
collectChanged(this.menuList)
if (changedMenuIds.length === 0) {
this.$modal.msgWarning("未检测到排序修改")
return
}
updateMenuSort({ menuIds: changedMenuIds.join(","), orderNums: changedOrderNums.join(",") }).then(() => {
this.$modal.msgSuccess("排序保存成功")
this.recordOriginalOrders(this.menuList)
})
},
/** 删除按钮操作 */
handleDelete(row) {
this.$modal.confirm('是否确认删除名称为"' + row.menuName + '"的数据项?').then(function() {

Loading…
Cancel
Save