菜单管理->修改、新增时路由地址唯一性检验

This commit is contained in:
2025-12-18 10:20:52 +08:00
parent 515f03a5cd
commit 1e6a5972b9
4 changed files with 46 additions and 8 deletions

View File

@@ -84,6 +84,14 @@ public interface SysMenuMapper {
*/ */
public SysMenu selectMenuById(Long menuId); public SysMenu selectMenuById(Long menuId);
/**
* 根据路径Path查询信息
*
* @param path 路径
* @return 菜单信息
*/
public SysMenu selectMenuByPath(String path);
/** /**
* 是否存在菜单子节点 * 是否存在菜单子节点
* *

View File

@@ -3,6 +3,7 @@ package com.core.system.service.impl;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.core.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -266,6 +267,11 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public int insertMenu(SysMenu menu) { public int insertMenu(SysMenu menu) {
//路径Path唯一性判断
SysMenu sysMenu = menuMapper.selectMenuByPath(menu.getPath());
if (sysMenu != null){
return -1;
}
return menuMapper.insertMenu(menu); return menuMapper.insertMenu(menu);
} }
@@ -277,6 +283,11 @@ public class SysMenuServiceImpl implements ISysMenuService {
*/ */
@Override @Override
public int updateMenu(SysMenu menu) { public int updateMenu(SysMenu menu) {
//路径Path唯一性判断
SysMenu sysMenu = menuMapper.selectMenuByPath(menu.getPath());
if (sysMenu != null){
return -1;
}
return menuMapper.updateMenu(menu); return menuMapper.updateMenu(menu);
} }

View File

@@ -174,6 +174,11 @@
and rm.role_id = #{roleId} and rm.role_id = #{roleId}
</select> </select>
<select id="selectMenuByPath" parameterType="String" resultMap="SysMenuResult">
<include refid="selectMenuVo"/>
where path = #{path}
</select>
<select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult"> <select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
<include refid="selectMenuVo"/> <include refid="selectMenuVo"/>
where menu_id = #{menuId} where menu_id = #{menuId}

View File

@@ -398,16 +398,30 @@ function submitForm() {
proxy.$refs["menuRef"].validate(valid => { proxy.$refs["menuRef"].validate(valid => {
if (valid) { if (valid) {
if (form.value.menuId != undefined) { if (form.value.menuId != undefined) {
updateMenu(form.value).then(response => { updateMenu(form.value).then(data => {
if (data === -1) {
proxy.$modal.msgError("路由地址已存在");
} else {
proxy.$modal.msgSuccess("修改成功"); proxy.$modal.msgSuccess("修改成功");
open.value = false; open.value = false;
getList(); getList();
}
}).catch(() => {
// 可以在这里添加自定义的错误处理,或者使用默认的错误提示
proxy.$modal.msgError("路由地址已存在");
}); });
} else { } else {
addMenu(form.value).then(response => { addMenu(form.value).then(data => {
if (data === -1) {
proxy.$modal.msgError("路由地址已存在");
} else {
proxy.$modal.msgSuccess("新增成功"); proxy.$modal.msgSuccess("新增成功");
open.value = false; open.value = false;
getList(); getList();
}
}).catch(() => {
// 可以在这里添加自定义的错误处理,或者使用默认的错误提示
proxy.$modal.msgError("路由地址已存在");
}); });
} }
} }