sys_menu.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package dto
  2. import (
  3. "IotAdmin/app/system/models"
  4. "IotAdmin/common/dto"
  5. common "IotAdmin/common/models"
  6. "IotAdmin/core/tools/utils"
  7. )
  8. // SysMenuGetPageReq 列表或者搜索使用结构体
  9. type SysMenuGetPageReq struct {
  10. dto.Pagination `search:"-"`
  11. Title string `form:"title" search:"type:contains;column:title;table:sys_menu" comment:"菜单名称"` // 菜单名称
  12. IsHide int `form:"isHide" search:"type:exact;column:idHide;table:sys_menu" comment:"显示状态"` // 显示状态
  13. }
  14. func (m *SysMenuGetPageReq) GetNeedSearch() interface{} {
  15. return *m
  16. }
  17. type SysMenuInsertReq struct {
  18. MenuId int `uri:"id" comment:"编码"` // 编码
  19. Path string `form:"path" comment:"菜单path"` //菜单name
  20. MenuName string `form:"menuName" comment:"显示名称"` //显示名称
  21. Icon string `form:"icon" comment:"图标"` //图标
  22. //Path string `form:"path" comment:"路径"` //路径
  23. Paths string `form:"paths" comment:"id路径"` //id路径
  24. MenuType string `form:"menuType" comment:"菜单类型"` //菜单类型
  25. SysApi []models.SysApi `form:"sysApi"`
  26. Apis []int `form:"apis"`
  27. Action string `form:"action" comment:"请求方式"` //请求方式
  28. Permission string `form:"permission" comment:"权限编码"` //权限编码
  29. ParentId int `form:"parentId" comment:"上级菜单"` //上级菜单
  30. //Breadcrumb string `form:"breadcrumb" comment:"是否面包屑"` //是否面包屑
  31. Component string `form:"component" comment:"组件"` //组件
  32. BtnClass string `form:"btnClass" comment:"按钮样式"` //按钮样式
  33. BtnScript string `form:"btnScript" comment:"按钮脚本"` //按钮脚本
  34. Sort int `form:"sort" comment:"排序"` //排序
  35. NoCache string `form:"noCache" comment:"是否缓存"` //是否缓存
  36. IsHide string `form:"isHide" comment:"是否显示"` //是否显示
  37. IsFrame string `form:"isFrame" comment:"是否frame"` //是否frame
  38. common.ControlBy
  39. }
  40. func (s *SysMenuInsertReq) Generate(model *models.SysMenu) {
  41. if s.MenuId != 0 {
  42. model.MenuId = s.MenuId
  43. }
  44. model.MenuName = s.MenuName
  45. model.Path = s.Path
  46. model.Icon = s.Icon
  47. model.Paths = s.Paths
  48. model.MenuType = s.MenuType
  49. model.Action = s.Action
  50. model.SysApi = s.SysApi
  51. model.Permission = s.Permission
  52. model.ParentId = s.ParentId
  53. model.NoCache = s.NoCache == "1"
  54. //model.Breadcrumb = s.Breadcrumb
  55. model.Component = s.Component
  56. model.BtnClass = s.BtnClass
  57. model.BtnScript = s.BtnScript
  58. model.Sort = s.Sort
  59. model.IsHide = s.IsHide == "1"
  60. model.IsFrame = s.IsFrame == "1"
  61. if s.CreateBy != 0 {
  62. model.CreateBy = s.CreateBy
  63. }
  64. if s.UpdateBy != 0 {
  65. model.UpdateBy = s.UpdateBy
  66. }
  67. }
  68. func (s *SysMenuInsertReq) GetId() interface{} {
  69. return s.MenuId
  70. }
  71. type SysMenuUpdateReq struct {
  72. MenuId int `uri:"id" comment:"编码"` // 编码
  73. Path string `form:"path" comment:"菜单path"` //菜单Path
  74. MenuName string `form:"title" comment:"显示名称"` //显示名称
  75. Icon string `form:"icon" comment:"图标"` //图标
  76. Paths string `form:"paths" comment:"id路径"` //id路径
  77. MenuType string `form:"menuType" comment:"菜单类型"` //菜单类型
  78. SysApi []models.SysApi `form:"sysApi"`
  79. Apis []int `form:"apis"`
  80. Action string `form:"action" comment:"请求方式"` //请求方式
  81. Permission string `form:"permission" comment:"权限编码"` //权限编码
  82. ParentId int `form:"parentId" comment:"上级菜单"` //上级菜单
  83. //Breadcrumb string `form:"breadcrumb" comment:"是否面包屑"` //是否面包屑
  84. Component string `form:"component" comment:"组件"` //组件
  85. BtnClass string `form:"btnClass" comment:"按钮样式"` //按钮样式
  86. BtnScript string `form:"btnScript" comment:"按钮脚本"` //按钮脚本
  87. Sort int `form:"sort" comment:"排序"` //排序
  88. NoCache string `form:"noCache" comment:"是否缓存"` //是否缓存
  89. IsHide string `form:"isHide" comment:"是否显示"` //是否显示
  90. IsFrame string `form:"isFrame" comment:"是否frame"` //是否frame
  91. common.ControlBy
  92. }
  93. func (s *SysMenuUpdateReq) Generate(model *models.SysMenu) {
  94. if s.MenuId != 0 {
  95. model.MenuId = s.MenuId
  96. }
  97. model.Path = s.Path
  98. model.MenuName = s.MenuName
  99. model.Icon = s.Icon
  100. model.Paths = s.Paths
  101. model.MenuType = s.MenuType
  102. model.Action = s.Action
  103. model.SysApi = s.SysApi
  104. model.Permission = s.Permission
  105. model.ParentId = s.ParentId
  106. model.NoCache = s.NoCache == "1"
  107. //model.Breadcrumb = s.Breadcrumb
  108. model.Component = s.Component
  109. model.BtnClass = s.BtnClass
  110. model.BtnScript = s.BtnScript
  111. model.Sort = s.Sort
  112. model.IsHide = s.IsHide == "1"
  113. model.IsFrame = s.IsFrame == "1"
  114. if s.CreateBy != 0 {
  115. model.CreateBy = s.CreateBy
  116. }
  117. if s.UpdateBy != 0 {
  118. model.UpdateBy = s.UpdateBy
  119. }
  120. }
  121. func (s *SysMenuUpdateReq) GetId() interface{} {
  122. return s.MenuId
  123. }
  124. type SysMenuGetReq struct {
  125. Id int `uri:"id"`
  126. }
  127. func (s *SysMenuGetReq) GetId() interface{} {
  128. return s.Id
  129. }
  130. type SysMenuDeleteReq struct {
  131. Ids []int `json:"ids"`
  132. common.ControlBy
  133. }
  134. func (s *SysMenuDeleteReq) GetId() interface{} {
  135. return s.Ids
  136. }
  137. const (
  138. LAYOUT = "Layout"
  139. PARENT_VIEW = "ParentView"
  140. INNER_LINK = "InnerLink"
  141. )
  142. type SysRouterVo struct {
  143. Name string `json:"name"` // 路由名称
  144. Path string `json:"path"` // 路由地址
  145. Hidden bool `json:"hidden"` // 是否隐藏
  146. Redirect string `json:"redirect"` // 重定向地址,当设置noRedirect的时候该路由在面包屑导航中不可被点击
  147. Component string `json:"component"` // 组件
  148. Query string `json:"query"` // 路由query参数
  149. AlwaysShow bool `json:"alwaysShow"` // children 声明的路由大于1个时,自动会变成嵌套的模式--如组件页面
  150. Meta SysRouterMetaVo `json:"meta"`
  151. Children []SysRouterVo `json:"children"` // 子路由
  152. }
  153. type SysRouterMetaVo struct {
  154. Title string `json:"title"`
  155. Icon string `json:"icon"`
  156. Link string `json:"link"`
  157. NoCache bool `json:"noCache"` //设置为true,则不会被 <keep-alive>缓存
  158. }
  159. func (m *SysRouterVo) Generate(model *models.SysMenu) {
  160. m.Name = utils.FirstUpper(model.Path)
  161. m.Path = model.Path
  162. m.Hidden = model.IsHide
  163. m.Redirect = "noRedirect"
  164. m.Component = model.Component
  165. m.AlwaysShow = true
  166. m.Query = ""
  167. m.Meta = SysRouterMetaVo{
  168. Title: model.MenuName,
  169. Icon: model.Icon,
  170. NoCache: model.NoCache,
  171. }
  172. m.Children = []SysRouterVo{}
  173. }
  174. type MenuLabel struct {
  175. Id int `json:"id,omitempty" gorm:"-"`
  176. Label string `json:"label,omitempty" gorm:"-"`
  177. Children []MenuLabel `json:"children,omitempty" gorm:"-"`
  178. }
  179. type MenuRole struct {
  180. models.SysMenu
  181. IsSelect bool `json:"is_select" gorm:"-"`
  182. }
  183. type SelectRole struct {
  184. RoleId int `uri:"roleId"`
  185. }
  186. type SelectMenuBtnChildren struct {
  187. Permission string `uri:"permission"`
  188. }