e_menu.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package entity
  2. import (
  3. "context"
  4. "gorm.io/gorm"
  5. "yx-dataset-server/app/schema"
  6. )
  7. // GetMenuDB 获取Menu存储
  8. func GetMenuDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
  9. return getDBWithModel(ctx, defDB, Menu{})
  10. }
  11. // SchemaMenu Menu对象
  12. type SchemaMenu schema.Menu
  13. // ToMenu 转换为Menu实体
  14. func (a SchemaMenu) ToMenu() *Menu {
  15. item := &Menu{
  16. RecordID: a.RecordID,
  17. Name: a.Name,
  18. Path: a.Path,
  19. Component: a.Component,
  20. ParentId: a.ParentId,
  21. Icon: a.Meta.Icon,
  22. Title: a.Meta.Title,
  23. IsLink: a.Meta.IsLink,
  24. IsHide: a.Meta.IsHide,
  25. IsFull: a.Meta.IsFull,
  26. IsAffix: a.Meta.IsAffix,
  27. IsKeepAlive: a.Meta.IsKeepAlive,
  28. Sequence: &a.Sequence,
  29. CreatorId: a.CreatorId,
  30. }
  31. return item
  32. }
  33. // ToSchemaMenu 转换为Menu对象
  34. func (a Menu) ToSchemaMenu() *schema.Menu {
  35. item := &schema.Menu{
  36. RecordID: a.RecordID,
  37. Name: a.Name,
  38. Path: a.Path,
  39. Component: a.Component,
  40. ParentId: a.ParentId,
  41. Sequence: *a.Sequence,
  42. CreatorId: a.CreatorId,
  43. CreatedAt: a.CreatedAt,
  44. Meta: schema.MenuMeta{
  45. Icon: a.Icon,
  46. Title: a.Title,
  47. IsLink: a.IsLink,
  48. IsHide: a.IsHide,
  49. IsFull: a.IsFull,
  50. IsAffix: a.IsAffix,
  51. IsKeepAlive: a.IsKeepAlive,
  52. },
  53. }
  54. return item
  55. }
  56. // Menu Menu实体
  57. type Menu struct {
  58. gorm.Model
  59. RecordID string `gorm:"column:record_id;size:32;index;comment:'记录内码'"`
  60. Name string `gorm:"column:name;size:50;index;comment:'菜单名称'"`
  61. Path string `gorm:"column:path;size:50;"` // 路径
  62. Component string `gorm:"column:component;size:50;"` // 组件
  63. ParentId string `gorm:"column:parent_id;size:32;index;"` // 父级id
  64. Icon string `gorm:"column:icon;size:30;"` // 图标
  65. Title string `gorm:"column:title;size:50;"` // 标题
  66. IsLink string `gorm:"column:is_link;size:10;"` // 是否外链
  67. IsHide bool `gorm:"column:is_hide;"` // 是否隐藏
  68. IsFull bool `gorm:"column:is_full;"` // 是否全屏
  69. IsAffix bool `gorm:"column:is_affix;"` // 是否固定
  70. IsKeepAlive bool `gorm:"column:is_keep_alive;"` // 是否缓存
  71. Sequence *int `gorm:"column:sequence;auto_increment;"` // 排序值
  72. CreatorId string `gorm:"column:creator_id;size:32;"` // 创建人
  73. }
  74. // Menus Menu列表
  75. type Menus []*Menu
  76. // ToSchemaMenus 转换为Menu对象列表
  77. func (a Menus) ToSchemaMenus() []*schema.Menu {
  78. list := make([]*schema.Menu, len(a))
  79. for i, item := range a {
  80. list[i] = item.ToSchemaMenu()
  81. }
  82. return list
  83. }