index.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import { DeptVO } from './../dept/types';
  2. import { RoleVO } from '@/api/system/role/types';
  3. import request from '@/utils/request';
  4. import { AxiosPromise } from 'axios';
  5. import { UserForm, UserQuery, UserVO, UserInfoVO } from './types';
  6. import { parseStrEmpty } from '@/utils/ruoyi';
  7. /**
  8. * 查询用户列表
  9. * @param query
  10. */
  11. export const listUser = (query: UserQuery): AxiosPromise<UserVO[]> => {
  12. return request({
  13. url: '/system/user/list',
  14. method: 'get',
  15. params: query
  16. });
  17. };
  18. /**
  19. * 获取用户详情
  20. * @param userId
  21. */
  22. export const getUser = (userId?: string | number): AxiosPromise<UserInfoVO> => {
  23. return request({
  24. url: '/system/user/' + parseStrEmpty(userId),
  25. method: 'get'
  26. });
  27. };
  28. /**
  29. * 新增用户
  30. */
  31. export const addUser = (data: UserForm) => {
  32. return request({
  33. url: '/system/user',
  34. method: 'post',
  35. data: data
  36. });
  37. };
  38. /**
  39. * 修改用户
  40. */
  41. export const updateUser = (data: UserForm) => {
  42. return request({
  43. url: '/system/user',
  44. method: 'put',
  45. data: data
  46. });
  47. };
  48. /**
  49. * 删除用户
  50. * @param userId 用户ID
  51. */
  52. export const delUser = (userId: Array<string | number> | string | number) => {
  53. return request({
  54. url: '/system/user/' + userId,
  55. method: 'delete'
  56. });
  57. };
  58. /**
  59. * 用户密码重置
  60. * @param userId 用户ID
  61. * @param password 密码
  62. */
  63. export const resetUserPwd = (userId: string | number, password: string) => {
  64. const data = {
  65. userId,
  66. password
  67. };
  68. return request({
  69. url: '/system/user/resetPwd',
  70. method: 'put',
  71. headers: {
  72. isEncrypt: true
  73. },
  74. data: data
  75. });
  76. };
  77. /**
  78. * 用户状态修改
  79. * @param userId 用户ID
  80. * @param status 用户状态
  81. */
  82. export const changeUserStatus = (userId: number | string, status: string) => {
  83. const data = {
  84. userId,
  85. status
  86. };
  87. return request({
  88. url: '/system/user/changeStatus',
  89. method: 'put',
  90. data: data
  91. });
  92. };
  93. /**
  94. * 查询用户个人信息
  95. */
  96. export const getUserProfile = (): AxiosPromise<UserInfoVO> => {
  97. return request({
  98. url: '/system/user/profile',
  99. method: 'get'
  100. });
  101. };
  102. /**
  103. * 修改用户个人信息
  104. * @param data 用户信息
  105. */
  106. export const updateUserProfile = (data: UserForm) => {
  107. return request({
  108. url: '/system/user/profile',
  109. method: 'put',
  110. data: data
  111. });
  112. };
  113. /**
  114. * 用户密码重置
  115. * @param oldPassword 旧密码
  116. * @param newPassword 新密码
  117. */
  118. export const updateUserPwd = (oldPassword: string, newPassword: string) => {
  119. const data = {
  120. oldPassword,
  121. newPassword
  122. };
  123. return request({
  124. url: '/system/user/profile/updatePwd',
  125. method: 'put',
  126. headers: {
  127. isEncrypt: true
  128. },
  129. data: data
  130. });
  131. };
  132. /**
  133. * 用户头像上传
  134. * @param data 头像文件
  135. */
  136. export const uploadAvatar = (data: FormData) => {
  137. return request({
  138. url: '/system/user/profile/avatar',
  139. method: 'post',
  140. data: data
  141. });
  142. };
  143. /**
  144. * 查询授权角色
  145. * @param userId 用户ID
  146. */
  147. export const getAuthRole = (userId: string | number): AxiosPromise<{ user: UserVO; roles: RoleVO[] }> => {
  148. return request({
  149. url: '/system/user/authRole/' + userId,
  150. method: 'get'
  151. });
  152. };
  153. /**
  154. * 保存授权角色
  155. * @param data 用户ID
  156. */
  157. export const updateAuthRole = (data: { userId: string; roleIds: string }) => {
  158. return request({
  159. url: '/system/user/authRole',
  160. method: 'put',
  161. params: data
  162. });
  163. };
  164. /**
  165. * 查询当前部门的所有用户信息
  166. * @param deptId
  167. */
  168. export const listUserByDeptId = (deptId: string | number): AxiosPromise<UserVO[]> => {
  169. return request({
  170. url: '/system/user/list/dept/' + deptId,
  171. method: 'get'
  172. });
  173. };
  174. /**
  175. * 查询部门下拉树结构
  176. */
  177. export const deptTreeSelect = (): AxiosPromise<DeptVO[]> => {
  178. return request({
  179. url: '/system/user/deptTree',
  180. method: 'get'
  181. });
  182. };
  183. export default {
  184. listUser,
  185. getUser,
  186. addUser,
  187. updateUser,
  188. delUser,
  189. resetUserPwd,
  190. changeUserStatus,
  191. getUserProfile,
  192. updateUserProfile,
  193. updateUserPwd,
  194. uploadAvatar,
  195. getAuthRole,
  196. updateAuthRole,
  197. deptTreeSelect,
  198. listUserByDeptId
  199. };