fix: 菜单同父级下唯一

This commit is contained in:
TsMask
2023-10-20 18:28:38 +08:00
parent 62b1601718
commit 84010a6693
3 changed files with 6 additions and 5 deletions

View File

@@ -79,7 +79,7 @@ func (s *SysMenuController) Add(c *gin.Context) {
// 目录和菜单检查地址唯一
if menu.TYPE_DIR == body.MenuType || menu.TYPE_MENU == body.MenuType {
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, "")
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, "")
if !uniqueNenuPath {
msg := fmt.Sprintf("菜单新增【%s】失败菜单路由地址已存在", body.MenuName)
c.JSON(200, result.ErrMsg(msg))
@@ -151,7 +151,7 @@ func (s *SysMenuController) Edit(c *gin.Context) {
// 目录和菜单检查地址唯一
if menu.TYPE_DIR == body.MenuType || menu.TYPE_MENU == body.MenuType {
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.MenuID)
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, body.MenuID)
if !uniqueNenuPath {
msg := fmt.Sprintf("菜单修改【%s】失败菜单路由地址已存在", body.MenuName)
c.JSON(200, result.ErrMsg(msg))

View File

@@ -44,7 +44,7 @@ type ISysMenu interface {
CheckUniqueMenuName(menuName, parentId, menuId string) bool
// CheckUniqueMenuPath 校验路由地址是否唯一(针对目录和菜单)
CheckUniqueMenuPath(path, menuId string) bool
CheckUniqueMenuPath(path, parentId, menuId string) bool
// BuildRouteMenus 构建前端路由所需要的菜单
BuildRouteMenus(sysMenus []model.SysMenu, prefix string) []vo.Router

View File

@@ -124,9 +124,10 @@ func (r *SysMenuImpl) CheckUniqueMenuName(menuName, parentId, menuId string) boo
}
// CheckUniqueMenuPath 校验路由地址是否唯一(针对目录和菜单)
func (r *SysMenuImpl) CheckUniqueMenuPath(path, menuId string) bool {
func (r *SysMenuImpl) CheckUniqueMenuPath(path, parentId, menuId string) bool {
uniqueId := r.sysMenuRepository.CheckUniqueMenu(model.SysMenu{
Path: path,
Path: path,
ParentID: parentId,
})
if uniqueId == menuId {
return true