You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.9 KiB

  1. package api
  2. import (
  3. "fmt"
  4. "gin-vue-admin/controller/servers"
  5. "gin-vue-admin/model/modelInterface"
  6. "gin-vue-admin/model/sysModel"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // @Tags authority
  10. // @Summary 创建角色
  11. // @Security ApiKeyAuth
  12. // @accept application/json
  13. // @Produce application/json
  14. // @Param data body sysModel.SysAuthority true "创建角色"
  15. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  16. // @Router /authority/createAuthority [post]
  17. func CreateAuthority(c *gin.Context) {
  18. var auth sysModel.SysAuthority
  19. _ = c.ShouldBindJSON(&auth)
  20. err, authBack := auth.CreateAuthority()
  21. if err != nil {
  22. servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{
  23. "authority": authBack,
  24. })
  25. } else {
  26. servers.ReportFormat(c, true, "创建成功", gin.H{
  27. "authority": authBack,
  28. })
  29. }
  30. }
  31. // @Tags authority
  32. // @Summary 删除角色
  33. // @Security ApiKeyAuth
  34. // @accept application/json
  35. // @Produce application/json
  36. // @Param data body sysModel.SysAuthority true "删除角色"
  37. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  38. // @Router /authority/deleteAuthority [post]
  39. func DeleteAuthority(c *gin.Context) {
  40. var a sysModel.SysAuthority
  41. _ = c.ShouldBindJSON(&a)
  42. //删除角色之前需要判断是否有用户正在使用此角色
  43. err := a.DeleteAuthority()
  44. if err != nil {
  45. servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
  46. } else {
  47. servers.ReportFormat(c, true, "删除成功", gin.H{})
  48. }
  49. }
  50. // @Tags authority
  51. // @Summary 分页获取角色列表
  52. // @Security ApiKeyAuth
  53. // @accept application/json
  54. // @Produce application/json
  55. // @Param data body modelInterface.PageInfo true "分页获取用户列表"
  56. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  57. // @Router /authority/getAuthorityList [post]
  58. func GetAuthorityList(c *gin.Context) {
  59. var pageInfo modelInterface.PageInfo
  60. _ = c.ShouldBindJSON(&pageInfo)
  61. err, list, total := new(sysModel.SysAuthority).GetInfoList(pageInfo)
  62. if err != nil {
  63. servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
  64. } else {
  65. servers.ReportFormat(c, true, "获取数据成功", gin.H{
  66. "list": list,
  67. "total": total,
  68. "page": pageInfo.Page,
  69. "pageSize": pageInfo.PageSize,
  70. })
  71. }
  72. }
  73. // @Tags authority
  74. // @Summary 设置角色资源权限
  75. // @Security ApiKeyAuth
  76. // @accept application/json
  77. // @Produce application/json
  78. // @Param data body sysModel.SysAuthority true "设置角色资源权限"
  79. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  80. // @Router /authority/setDataAuthority [post]
  81. func SetDataAuthority(c *gin.Context) {
  82. var auth sysModel.SysAuthority
  83. _ = c.ShouldBindJSON(&auth)
  84. err := auth.SetDataAuthority()
  85. if err != nil {
  86. servers.ReportFormat(c, false, fmt.Sprintf("设置关联失败,%v", err), gin.H{})
  87. } else {
  88. servers.ReportFormat(c, true, "设置关联成功", gin.H{})
  89. }
  90. }