存在菜单子节点数量与状态
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -222,10 +222,18 @@ func (r *RepoSysMenu) SelectMenuByIds(menuIds []string) []model.SysMenu {
|
||||
return r.convertResultRows(results)
|
||||
}
|
||||
|
||||
// HasChildByMenuId 存在菜单子节点数量
|
||||
func (r *RepoSysMenu) HasChildByMenuId(menuId string) int64 {
|
||||
// HasChildByMenuIdAndStatus 存在菜单子节点数量与状态
|
||||
func (r *RepoSysMenu) HasChildByMenuIdAndStatus(menuId, status string) int64 {
|
||||
querySql := "select count(1) as 'total' from sys_menu where parent_id = ?"
|
||||
results, err := datasource.RawDB("", querySql, []any{menuId})
|
||||
params := []any{menuId}
|
||||
|
||||
// 菜单状态
|
||||
if status != "" {
|
||||
querySql += " and status = ?"
|
||||
params = append(params, status)
|
||||
}
|
||||
|
||||
results, err := datasource.RawDB("", querySql, params)
|
||||
if err != nil {
|
||||
log.Errorf("query err => %v", err)
|
||||
return 0
|
||||
|
||||
@@ -102,9 +102,9 @@ func (r *ServiceSysMenu) SelectMenuById(menuId string) model.SysMenu {
|
||||
return model.SysMenu{}
|
||||
}
|
||||
|
||||
// HasChildByMenuId 存在菜单子节点数量
|
||||
func (r *ServiceSysMenu) HasChildByMenuId(menuId string) int64 {
|
||||
return r.sysMenuRepository.HasChildByMenuId(menuId)
|
||||
// HasChildByMenuIdAndStatus 存在菜单子节点数量与状态
|
||||
func (r *ServiceSysMenu) HasChildByMenuIdAndStatus(menuId, status string) int64 {
|
||||
return r.sysMenuRepository.HasChildByMenuIdAndStatus(menuId, status)
|
||||
}
|
||||
|
||||
// CheckMenuExistRole 查询菜单是否存在角色
|
||||
|
||||
Reference in New Issue
Block a user