system_menu.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package model
  2. import (
  3. "time"
  4. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  5. operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
  6. )
  7. type SystemMenu struct {
  8. Id int64 `json:"id"`
  9. Name string `json:"name"`
  10. Title string `json:"title"`
  11. Path string `json:"path"`
  12. Icon string `json:"icon"`
  13. Component string `json:"component"`
  14. Redirect string `json:"redirect"`
  15. Auths string `json:"auths"`
  16. MenuType pasturePb.MenuType_Kind `json:"menu_type"`
  17. ParentId int64 `json:"parent_id"`
  18. Rank int32 `json:"rank"`
  19. ExtraIcon string `json:"extra_icon"`
  20. EnterTransition string `json:"enter_transition"`
  21. ActivePath string `json:"active_path"`
  22. FrameSrc string `json:"frame_src"`
  23. FrameLoading pasturePb.IsShow_Kind `json:"frame_loading"`
  24. Keepalive pasturePb.IsShow_Kind `json:"keepalive"`
  25. HiddenTag pasturePb.IsShow_Kind `json:"hidden_tag"`
  26. ShowLink pasturePb.IsShow_Kind `json:"show_link"`
  27. ShowParent pasturePb.IsShow_Kind `json:"show_parent"`
  28. IsShow pasturePb.IsShow_Kind `json:"is_show"`
  29. IsDelete pasturePb.IsShow_Kind `json:"is_delete"`
  30. CreatedAt int64 `json:"created_at"`
  31. UpdatedAt int64 `json:"updated_at"`
  32. }
  33. func (s *SystemMenu) TableName() string {
  34. return "system_menu"
  35. }
  36. func NewSystemMenu(req *operationPb.AddMenuRequest) *SystemMenu {
  37. return &SystemMenu{
  38. Name: req.Name,
  39. Title: req.Title,
  40. Path: req.Path,
  41. Component: req.Component,
  42. Icon: req.Icon,
  43. Redirect: req.Redirect,
  44. ParentId: int64(req.ParentId),
  45. IsShow: pasturePb.IsShow_Ok,
  46. IsDelete: pasturePb.IsShow_Ok,
  47. }
  48. }
  49. type SystemMenuSlice []*SystemMenu
  50. func (s SystemMenuSlice) ToPB() []*pasturePb.SearchMenuRequest {
  51. res := make([]*pasturePb.SearchMenuRequest, len(s))
  52. for i, menu := range s {
  53. var frameLoading, keepalive, hiddenTag, showLink, showParent bool
  54. if menu.FrameLoading == pasturePb.IsShow_Ok {
  55. frameLoading = true
  56. }
  57. if menu.Keepalive == pasturePb.IsShow_Ok {
  58. keepalive = true
  59. }
  60. if menu.HiddenTag == pasturePb.IsShow_Ok {
  61. hiddenTag = true
  62. }
  63. if menu.ShowLink == pasturePb.IsShow_Ok {
  64. showLink = true
  65. }
  66. if menu.ShowParent == pasturePb.IsShow_Ok {
  67. showParent = true
  68. }
  69. res[i] = &pasturePb.SearchMenuRequest{
  70. Id: int32(menu.Id),
  71. Name: menu.Name,
  72. ParentId: int32(menu.ParentId),
  73. MenuType: menu.MenuType,
  74. Title: menu.Title,
  75. Path: menu.Path,
  76. IsShow: menu.IsShow,
  77. Component: menu.Component,
  78. Icon: menu.Icon,
  79. Redirect: menu.Redirect,
  80. Auths: menu.Auths,
  81. Rank: menu.Rank,
  82. ExtraIcon: menu.ExtraIcon,
  83. EnterTransition: menu.EnterTransition,
  84. ActivePath: menu.ActivePath,
  85. FrameSrc: menu.FrameSrc,
  86. FrameLoading: frameLoading,
  87. Keepalive: keepalive,
  88. HiddenTag: hiddenTag,
  89. ShowLink: showLink,
  90. ShowParent: showParent,
  91. CreatedAtFormat: time.Unix(menu.CreatedAt, 0).Format(LayoutTime),
  92. UpdatedAtFormat: time.Unix(menu.UpdatedAt, 0).Format(LayoutTime),
  93. }
  94. }
  95. return res
  96. }
  97. func BooleanToIsShow(isShow bool) pasturePb.IsShow_Kind {
  98. showKind := pasturePb.IsShow_No
  99. if isShow {
  100. showKind = pasturePb.IsShow_Ok
  101. }
  102. return showKind
  103. }