show.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package show
  2. import (
  3. "go-common/app/interface/main/app-resource/model"
  4. "go-common/app/interface/main/app-resource/model/tab"
  5. resource "go-common/app/service/main/resource/model"
  6. "strconv"
  7. )
  8. type Tab struct {
  9. ID int64 `json:"id,omitempty"`
  10. Icon string `json:"icon,omitempty"`
  11. IconSelected string `json:"icon_selected,omitempty"`
  12. Name string `json:"name,omitempty"`
  13. URI string `json:"uri,omitempty"`
  14. TabID string `json:"tab_id,omitempty"`
  15. Color string `json:"color,omitempty"`
  16. Pos int `json:"pos,omitempty"`
  17. DefaultSelected int `json:"default_selected,omitempty"`
  18. Module int `json:"-"`
  19. ModuleStr string `json:"-"`
  20. Plat int8 `json:"-"`
  21. Group string `json:"-"`
  22. Language string `json:"-"`
  23. }
  24. type Limit struct {
  25. ID int64 `json:"-"`
  26. Build int `json:"-"`
  27. Condition string `json:"-"`
  28. }
  29. func (t *Tab) TabChange(rsb *resource.SideBar, abtest map[string]string, defaultTab map[string]*Tab) (ok bool) {
  30. var (
  31. _top = 10
  32. _tab = 8
  33. _bottom = 9
  34. )
  35. t.ID = rsb.ID
  36. t.Icon = rsb.Logo
  37. t.IconSelected = rsb.LogoSelected
  38. t.Name = rsb.Name
  39. t.URI = rsb.Param
  40. t.Module = rsb.Module
  41. t.Plat = rsb.Plat
  42. t.Language = rsb.Language
  43. switch t.Module {
  44. case _top:
  45. t.ModuleStr = "top"
  46. case _tab:
  47. t.ModuleStr = "tab"
  48. t.Icon = ""
  49. t.IconSelected = ""
  50. case _bottom:
  51. t.ModuleStr = "bottom"
  52. default:
  53. return false
  54. }
  55. if len(abtest) > 0 {
  56. if groups, ok := abtest[t.URI]; ok {
  57. t.Group = groups
  58. }
  59. }
  60. if len(defaultTab) > 0 {
  61. if dt, ok := defaultTab[t.URI]; ok && dt != nil {
  62. t.DefaultSelected = dt.DefaultSelected
  63. t.TabID = dt.TabID
  64. }
  65. if rsb.TabID != "" {
  66. t.TabID = rsb.TabID
  67. }
  68. }
  69. return true
  70. }
  71. func (t *Tab) TabMenuChange(m *tab.Menu) {
  72. t.TabID = strconv.FormatInt(m.TabID, 10)
  73. t.Name = m.Name
  74. t.Color = m.Color
  75. t.ID = m.ID
  76. t.ModuleStr = "tab"
  77. t.URI = model.FillURI(model.GotoPegasusTab, strconv.FormatInt(t.ID, 10), model.PegasusHandler(m))
  78. }