菜单管理支持批量保存排序
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -129,6 +130,19 @@ public class SysMenuController extends BaseController
|
||||
return toAjax(menuService.updateMenu(menu));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存菜单排序
|
||||
*/
|
||||
@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,11 +12,14 @@ 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.constant.Constants;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
import com.ruoyi.common.core.domain.entity.SysMenu;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.text.Convert;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.vo.MetaVo;
|
||||
@@ -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("保存排序异常,请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜单管理信息
|
||||
*
|
||||
|
||||
@@ -203,7 +203,11 @@
|
||||
sysdate()
|
||||
)
|
||||
</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() {
|
||||
|
||||
Reference in New Issue
Block a user