marge: 合并代码
This commit is contained in:
@@ -55,7 +55,7 @@ func (s *SysMenuController) List(c *gin.Context) {
|
||||
func (s *SysMenuController) Info(c *gin.Context) {
|
||||
menuId := c.Param("menuId")
|
||||
if menuId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
data := s.sysMenuService.SelectMenuById(menuId)
|
||||
@@ -73,7 +73,7 @@ func (s *SysMenuController) Add(c *gin.Context) {
|
||||
var body model.SysMenu
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.MenuID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ func (s *SysMenuController) Add(c *gin.Context) {
|
||||
if menu.TYPE_DIR == body.MenuType || menu.TYPE_MENU == body.MenuType {
|
||||
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, "")
|
||||
if !uniqueNenuPath {
|
||||
msg := fmt.Sprintf("菜单新增【%s】失败,菜单路由地址已存在", body.MenuName)
|
||||
// 菜单新增【%s】失败,菜单路由地址已存在
|
||||
msg := fmt.Sprintf("Menu add [%s] failed, menu routing address already exists", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -90,14 +91,16 @@ func (s *SysMenuController) Add(c *gin.Context) {
|
||||
// 检查名称唯一
|
||||
uniqueNenuName := s.sysMenuService.CheckUniqueMenuName(body.MenuName, body.ParentID, "")
|
||||
if !uniqueNenuName {
|
||||
msg := fmt.Sprintf("菜单新增【%s】失败,菜单名称已存在", body.MenuName)
|
||||
// 菜单新增【%s】失败,菜单名称已存在
|
||||
msg := fmt.Sprintf("Menu add [%s] failed, menu name already exists", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 外链菜单需要符合网站http(s)开头
|
||||
if body.IsFrame == common.STATUS_NO && !regular.ValidHttp(body.Path) {
|
||||
msg := fmt.Sprintf("菜单新增【%s】失败,非内部地址必须以http(s)://开头", body.MenuName)
|
||||
// 菜单新增【%s】失败,非内部地址必须以http(s)://开头
|
||||
msg := fmt.Sprintf("Menu adds [%s] failure, non-internal addresses must start with http(s)://", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -118,13 +121,14 @@ func (s *SysMenuController) Edit(c *gin.Context) {
|
||||
var body model.SysMenu
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.MenuID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 上级菜单不能选自己
|
||||
if body.MenuID == body.ParentID {
|
||||
msg := fmt.Sprintf("菜单修改【%s】失败,上级菜单不能选择自己", body.MenuName)
|
||||
// 菜单修改【%s】失败,上级菜单不能选择自己
|
||||
msg := fmt.Sprintf("Menu modification [%s] fails, the parent menu cannot select itself", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -132,19 +136,21 @@ func (s *SysMenuController) Edit(c *gin.Context) {
|
||||
// 检查数据是否存在
|
||||
menuInfo := s.sysMenuService.SelectMenuById(body.MenuID)
|
||||
if menuInfo.MenuID != body.MenuID {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问菜单数据"))
|
||||
// 没有可访问菜单数据
|
||||
c.JSON(200, result.ErrMsg("No accessible menu data"))
|
||||
return
|
||||
}
|
||||
// 父级ID不为0是要检查
|
||||
if body.ParentID != "0" {
|
||||
menuParent := s.sysMenuService.SelectMenuById(body.ParentID)
|
||||
if menuParent.MenuID != body.ParentID {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问菜单数据"))
|
||||
c.JSON(200, result.ErrMsg("No accessible menu data"))
|
||||
return
|
||||
}
|
||||
// 禁用菜单时检查父菜单是否使用
|
||||
if body.Status == common.STATUS_YES && menuParent.Status == common.STATUS_NO {
|
||||
c.JSON(200, result.ErrMsg("上级菜单未启用!"))
|
||||
// 上级菜单未启用!
|
||||
c.JSON(200, result.ErrMsg("The parent menu is not enabled!"))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -153,7 +159,8 @@ 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.ParentID, body.MenuID)
|
||||
if !uniqueNenuPath {
|
||||
msg := fmt.Sprintf("菜单修改【%s】失败,菜单路由地址已存在", body.MenuName)
|
||||
// 菜单修改【%s】失败,菜单路由地址已存在
|
||||
msg := fmt.Sprintf("Menu modification [%s] failed, menu routing address already exists", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -162,14 +169,16 @@ func (s *SysMenuController) Edit(c *gin.Context) {
|
||||
// 检查名称唯一
|
||||
uniqueNenuName := s.sysMenuService.CheckUniqueMenuName(body.MenuName, body.ParentID, body.MenuID)
|
||||
if !uniqueNenuName {
|
||||
msg := fmt.Sprintf("菜单修改【%s】失败,菜单名称已存在", body.MenuName)
|
||||
// 菜单修改【%s】失败,菜单名称已存在
|
||||
msg := fmt.Sprintf("Menu modification [%s] failed, menu name already exists", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 外链菜单需要符合网站http(s)开头
|
||||
if body.IsFrame == common.STATUS_NO && !regular.ValidHttp(body.Path) {
|
||||
msg := fmt.Sprintf("菜单修改【%s】失败,非内部地址必须以http(s)://开头", body.MenuName)
|
||||
// 菜单修改【%s】失败,非内部地址必须以http(s)://开头
|
||||
msg := fmt.Sprintf("Menu change [%s] failed, non-internal address must start with http(s)://", body.MenuName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -178,7 +187,8 @@ func (s *SysMenuController) Edit(c *gin.Context) {
|
||||
if body.Status == common.STATUS_NO {
|
||||
hasStatus := s.sysMenuService.HasChildByMenuIdAndStatus(body.MenuID, common.STATUS_YES)
|
||||
if hasStatus > 0 {
|
||||
msg := fmt.Sprintf("不允许禁用,存在使用子菜单数:%d", hasStatus)
|
||||
// 不允许禁用,存在使用子菜单数:%d
|
||||
msg := fmt.Sprintf("Disabling is not allowed, number of submenus present for use: %d", hasStatus)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -199,21 +209,23 @@ func (s *SysMenuController) Edit(c *gin.Context) {
|
||||
func (s *SysMenuController) Remove(c *gin.Context) {
|
||||
menuId := c.Param("menuId")
|
||||
if menuId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查数据是否存在
|
||||
menu := s.sysMenuService.SelectMenuById(menuId)
|
||||
if menu.MenuID != menuId {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问菜单数据!"))
|
||||
// 没有可访问菜单数据!
|
||||
c.JSON(200, result.ErrMsg("There is no accessible menu data!"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在子菜单
|
||||
hasChild := s.sysMenuService.HasChildByMenuIdAndStatus(menuId, "")
|
||||
if hasChild > 0 {
|
||||
msg := fmt.Sprintf("不允许删除,存在子菜单数:%d", hasChild)
|
||||
// 不允许删除,存在子菜单数:%d
|
||||
msg := fmt.Sprintf("Deletion not allowed, number of submenus present: %d", hasChild)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -221,14 +233,15 @@ func (s *SysMenuController) Remove(c *gin.Context) {
|
||||
// 检查是否分配给角色
|
||||
existRole := s.sysMenuService.CheckMenuExistRole(menuId)
|
||||
if existRole > 0 {
|
||||
msg := fmt.Sprintf("不允许删除,菜单已分配给角色数:%d", existRole)
|
||||
// 不允许删除,菜单已分配给角色数:%d
|
||||
msg := fmt.Sprintf("Deletion not allowed, number of roles assigned to the menu: %d", existRole)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
rows := s.sysMenuService.DeleteMenuById(menuId)
|
||||
if rows > 0 {
|
||||
msg := fmt.Sprintf("删除成功:%d", rows)
|
||||
msg := fmt.Sprintf("Deleted successfully: %d", rows)
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -262,7 +275,7 @@ func (s *SysMenuController) TreeSelect(c *gin.Context) {
|
||||
func (s *SysMenuController) RoleMenuTreeSelect(c *gin.Context) {
|
||||
roleId := c.Param("roleId")
|
||||
if roleId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user