index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import { UserVO } from '@/api/system/user/types';
  2. import { UserQuery } from '@/api/system/user/types';
  3. import { AxiosPromise } from 'axios';
  4. import { RoleQuery, RoleVO, RoleDeptTree } from './types';
  5. import request from '@/utils/request';
  6. export const listRole = (query: RoleQuery): AxiosPromise<RoleVO[]> => {
  7. return request({
  8. url: '/system/role/list',
  9. method: 'get',
  10. params: query
  11. });
  12. };
  13. /**
  14. * 通过roleIds查询角色
  15. * @param roleIds
  16. */
  17. export const optionSelect = (roleIds: (number | string)[]): AxiosPromise<RoleVO[]> => {
  18. return request({
  19. url: '/system/role/optionselect?roleIds=' + roleIds,
  20. method: 'get'
  21. });
  22. };
  23. /**
  24. * 查询角色详细
  25. */
  26. export const getRole = (roleId: string | number): AxiosPromise<RoleVO> => {
  27. return request({
  28. url: '/system/role/' + roleId,
  29. method: 'get'
  30. });
  31. };
  32. /**
  33. * 新增角色
  34. */
  35. export const addRole = (data: any) => {
  36. return request({
  37. url: '/system/role',
  38. method: 'post',
  39. data: data
  40. });
  41. };
  42. /**
  43. * 修改角色
  44. * @param data
  45. */
  46. export const updateRole = (data: any) => {
  47. return request({
  48. url: '/system/role',
  49. method: 'put',
  50. data: data
  51. });
  52. };
  53. /**
  54. * 角色数据权限
  55. */
  56. export const dataScope = (data: any) => {
  57. return request({
  58. url: '/system/role/dataScope',
  59. method: 'put',
  60. data: data
  61. });
  62. };
  63. /**
  64. * 角色状态修改
  65. */
  66. export const changeRoleStatus = (roleId: string | number, status: string) => {
  67. const data = {
  68. roleId,
  69. status
  70. };
  71. return request({
  72. url: '/system/role/changeStatus',
  73. method: 'put',
  74. data: data
  75. });
  76. };
  77. /**
  78. * 删除角色
  79. */
  80. export const delRole = (roleId: Array<string | number> | string | number) => {
  81. return request({
  82. url: '/system/role/' + roleId,
  83. method: 'delete'
  84. });
  85. };
  86. /**
  87. * 查询角色已授权用户列表
  88. */
  89. export const allocatedUserList = (query: UserQuery): AxiosPromise<UserVO[]> => {
  90. return request({
  91. url: '/system/role/authUser/allocatedList',
  92. method: 'get',
  93. params: query
  94. });
  95. };
  96. /**
  97. * 查询角色未授权用户列表
  98. */
  99. export const unallocatedUserList = (query: UserQuery): AxiosPromise<UserVO[]> => {
  100. return request({
  101. url: '/system/role/authUser/unallocatedList',
  102. method: 'get',
  103. params: query
  104. });
  105. };
  106. /**
  107. * 取消用户授权角色
  108. */
  109. export const authUserCancel = (data: any) => {
  110. return request({
  111. url: '/system/role/authUser/cancel',
  112. method: 'put',
  113. data: data
  114. });
  115. };
  116. /**
  117. * 批量取消用户授权角色
  118. */
  119. export const authUserCancelAll = (data: any) => {
  120. return request({
  121. url: '/system/role/authUser/cancelAll',
  122. method: 'put',
  123. params: data
  124. });
  125. };
  126. /**
  127. * 授权用户选择
  128. */
  129. export const authUserSelectAll = (data: any) => {
  130. return request({
  131. url: '/system/role/authUser/selectAll',
  132. method: 'put',
  133. params: data
  134. });
  135. };
  136. // 根据角色ID查询部门树结构
  137. export const deptTreeSelect = (roleId: string | number): AxiosPromise<RoleDeptTree> => {
  138. return request({
  139. url: '/system/role/deptTree/' + roleId,
  140. method: 'get'
  141. });
  142. };
  143. export default {
  144. optionSelect,
  145. listRole
  146. };