sys_menu_button.go 1.3 KB

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