存在菜单子节点数量与状态

This commit is contained in:
TsMask
2023-09-01 13:10:52 +08:00
parent 95591c1753
commit 35826d6f34
3 changed files with 30 additions and 7 deletions

View File

@@ -223,6 +223,11 @@ func (s *SysMenuApi) Edit(w http.ResponseWriter, r *http.Request) {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问菜单数据"))
return
}
// 禁用菜单时检查父菜单是否使用
if body.Status == "1" && menuParent.Status == "0" {
ctx.JSON(w, 200, result.ErrMsg("父菜单未启用!"))
return
}
}
// 目录和菜单检查地址唯一
@@ -250,6 +255,16 @@ func (s *SysMenuApi) Edit(w http.ResponseWriter, r *http.Request) {
return
}
// 禁用菜单时检查子菜单是否使用
if body.Status == "0" {
hasStatus := s.sysMenuService.HasChildByMenuIdAndStatus(body.MenuID, "1")
if hasStatus > 0 {
msg := fmt.Sprintf("不允许禁用,存在使用子菜单数:%d", hasStatus)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
}
body.UpdateBy = ctx.LoginUserToUserName(r)
rows := s.sysMenuService.UpdateMenu(body)
if rows > 0 {
@@ -277,7 +292,7 @@ func (s *SysMenuApi) Remove(w http.ResponseWriter, r *http.Request) {
}
// 检查是否存在子菜单
hasChild := s.sysMenuService.HasChildByMenuId(menuId)
hasChild := s.sysMenuService.HasChildByMenuIdAndStatus(menuId, "")
if hasChild > 0 {
msg := fmt.Sprintf("不允许删除,存在子菜单数:%d", hasChild)
ctx.JSON(w, 200, result.ErrMsg(msg))