sys_menu.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/middleware"
  6. "gin-vue-admin/model"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // @Tags authorityAndMenu
  10. // @Summary 获取用户动态路由
  11. // @Security ApiKeyAuth
  12. // @Produce application/json
  13. // @Param data body api.RegisterAndLoginStruct true "可以什么都不填"
  14. // @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
  15. // @Router /menu/getMenu [post]
  16. func GetMenu(c *gin.Context) {
  17. claims, _ := c.Get("claims")
  18. waitUse := claims.(*middleware.CustomClaims)
  19. err, menus := new(model.SysMenu).GetMenuTree(waitUse.AuthorityId)
  20. if err != nil {
  21. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取失败,%v", err), c)
  22. } else {
  23. response.Result(response.SUCCESS, gin.H{"menus": menus}, "获取成功", c)
  24. }
  25. }
  26. // @Tags menu
  27. // @Summary 分页获取基础menu列表
  28. // @Security ApiKeyAuth
  29. // @accept application/json
  30. // @Produce application/json
  31. // @Param data body model.PageInfo true "分页获取基础menu列表"
  32. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  33. // @Router /menu/getMenuList [post]
  34. func GetMenuList(c *gin.Context) {
  35. var pageInfo model.PageInfo
  36. _ = c.ShouldBindJSON(&pageInfo)
  37. err, menuList, total := new(model.SysBaseMenu).GetInfoList(pageInfo)
  38. if err != nil {
  39. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  40. } else {
  41. response.Result(response.SUCCESS, gin.H{
  42. "list": menuList,
  43. "total": total,
  44. "page": pageInfo.Page,
  45. "pageSize": pageInfo.PageSize,
  46. }, "获取数据成功", c)
  47. }
  48. }
  49. // @Tags menu
  50. // @Summary 新增菜单
  51. // @Security ApiKeyAuth
  52. // @accept application/json
  53. // @Produce application/json
  54. // @Param data body model.SysBaseMenu true "新增菜单"
  55. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  56. // @Router /menu/addBaseMenu [post]
  57. func AddBaseMenu(c *gin.Context) {
  58. var addMenu model.SysBaseMenu
  59. _ = c.ShouldBindJSON(&addMenu)
  60. err := addMenu.AddBaseMenu()
  61. if err != nil {
  62. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("添加失败,%v", err), c)
  63. } else {
  64. response.Result(response.SUCCESS, gin.H{}, "添加成功", c)
  65. }
  66. }
  67. // @Tags authorityAndMenu
  68. // @Summary 获取用户动态路由
  69. // @Security ApiKeyAuth
  70. // @Produce application/json
  71. // @Param data body api.RegisterAndLoginStruct true "可以什么都不填"
  72. // @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
  73. // @Router /menu/getBaseMenuTree [post]
  74. func GetBaseMenuTree(c *gin.Context) {
  75. err, menus := new(model.SysBaseMenu).GetBaseMenuTree()
  76. if err != nil {
  77. response.Result(response.ERROR, gin.H{"menus": menus}, fmt.Sprintf("获取失败,%v", err), c)
  78. } else {
  79. response.Result(response.SUCCESS, gin.H{"menus": menus}, "获取成功", c)
  80. }
  81. }
  82. // @Tags authorityAndMenu
  83. // @Summary 增加menu和角色关联关系
  84. // @Security ApiKeyAuth
  85. // @accept application/json
  86. // @Produce application/json
  87. // @Param data body model.AddMenuAuthorityInfo true "增加menu和角色关联关系"
  88. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  89. // @Router /menu/addMenuAuthority [post]
  90. func AddMenuAuthority(c *gin.Context) {
  91. var addMenuAuthorityInfo model.AddMenuAuthorityInfo
  92. _ = c.ShouldBindJSON(&addMenuAuthorityInfo)
  93. err := new(model.SysMenu).AddMenuAuthority(addMenuAuthorityInfo.Menus, addMenuAuthorityInfo.AuthorityId)
  94. if err != nil {
  95. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("添加失败,%v", err), c)
  96. } else {
  97. response.Result(response.SUCCESS, gin.H{}, "添加成功", c)
  98. }
  99. }
  100. // @Tags authorityAndMenu
  101. // @Summary 获取指定角色menu
  102. // @Security ApiKeyAuth
  103. // @accept application/json
  104. // @Produce application/json
  105. // @Param data body model.AuthorityIdInfo true "增加menu和角色关联关系"
  106. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  107. // @Router /menu/GetMenuAuthority [post]
  108. func GetMenuAuthority(c *gin.Context) {
  109. var authorityIdInfo model.AuthorityIdInfo
  110. _ = c.ShouldBindJSON(&authorityIdInfo)
  111. err, menus := new(model.SysMenu).GetMenuAuthority(authorityIdInfo.AuthorityId)
  112. if err != nil {
  113. response.Result(response.ERROR, gin.H{"menus": menus}, fmt.Sprintf("添加失败,%v", err), c)
  114. } else {
  115. response.Result(response.SUCCESS, gin.H{"menus": menus}, "获取成功", c)
  116. }
  117. }
  118. // @Tags menu
  119. // @Summary 删除菜单
  120. // @Security ApiKeyAuth
  121. // @accept application/json
  122. // @Produce application/json
  123. // @Param data body model.GetById true "删除菜单"
  124. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  125. // @Router /menu/deleteBaseMenu [post]
  126. func DeleteBaseMenu(c *gin.Context) {
  127. var idInfo model.GetById
  128. _ = c.ShouldBindJSON(&idInfo)
  129. err := new(model.SysBaseMenu).DeleteBaseMenu(idInfo.Id)
  130. if err != nil {
  131. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("删除失败:%v", err), c)
  132. } else {
  133. response.Result(response.SUCCESS, gin.H{}, "删除成功", c)
  134. }
  135. }
  136. // @Tags menu
  137. // @Summary 更新菜单
  138. // @Security ApiKeyAuth
  139. // @accept application/json
  140. // @Produce application/json
  141. // @Param data body model.SysBaseMenu true "更新菜单"
  142. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  143. // @Router /menu/updateBaseMenu [post]
  144. func UpdateBaseMenu(c *gin.Context) {
  145. var menu model.SysBaseMenu
  146. _ = c.ShouldBindJSON(&menu)
  147. err := menu.UpdateBaseMenu()
  148. if err != nil {
  149. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("修改失败:%v", err), c)
  150. } else {
  151. response.Result(response.SUCCESS, gin.H{}, "修改成功", c)
  152. }
  153. }
  154. // @Tags menu
  155. // @Summary 根据id获取菜单
  156. // @Security ApiKeyAuth
  157. // @accept application/json
  158. // @Produce application/json
  159. // @Param data body model.GetById true "根据id获取菜单"
  160. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  161. // @Router /menu/getBaseMenuById [post]
  162. func GetBaseMenuById(c *gin.Context) {
  163. var idInfo model.GetById
  164. _ = c.ShouldBindJSON(&idInfo)
  165. err, menu := new(model.SysBaseMenu).GetBaseMenuById(idInfo.Id)
  166. if err != nil {
  167. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("查询失败:%v", err), c)
  168. } else {
  169. response.Result(response.SUCCESS, gin.H{"menu": menu}, "查询成功", c)
  170. }
  171. }