sys_menu_button.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/system"
  5. "eta/eta_api/utils"
  6. )
  7. type SysMenuButtonController struct {
  8. BaseAuthController
  9. }
  10. // SysMenuButtons
  11. // @Title 获取菜单全部按钮
  12. // @Description 获取菜单全部按钮接口
  13. // @Param RoleId query int true "角色ID"
  14. // @Success 200 {object} system.MenuButtonsResp
  15. // @router /menu/buttons [get]
  16. func (this *SysRoleController) SysMenuButtons() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. list, err := system.GetButtonMenu()
  23. if err != nil {
  24. br.Msg = "获取失败"
  25. br.ErrMsg = "获取失败,Err:" + err.Error()
  26. return
  27. }
  28. listLen := len(list)
  29. if listLen <= 0 {
  30. list = make([]*system.ButtonMenu, 0)
  31. }
  32. for i := 0; i < listLen; i++ {
  33. item := list[i]
  34. menus, err := system.GetSysMenuButtonItems(item.MenuId)
  35. if err != nil {
  36. br.Msg = "获取失败"
  37. br.ErrMsg = "获取失败,Err:" + err.Error()
  38. return
  39. }
  40. list[i].List = menus
  41. }
  42. roleId, _ := this.GetInt("RoleId")
  43. checkList := make([]*int, 0)
  44. cl, err := system.GetRoleButtonCheck(roleId)
  45. if err != nil && err.Error() != utils.ErrNoRow() {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取失败,Err:" + err.Error()
  48. return
  49. }
  50. for _, v := range cl {
  51. checkList = append(checkList, &v.MenuButtonId)
  52. }
  53. resp := new(system.MenuButtonsResp)
  54. resp.List = list
  55. resp.CheckList = checkList
  56. br.Ret = 200
  57. br.Success = true
  58. br.Msg = "获取成功"
  59. br.Data = resp
  60. }