index.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. data: data
  72. });
  73. };
  74. /**
  75. * 用户状态修改
  76. * @param userId 用户ID
  77. * @param status 用户状态
  78. */
  79. export const changeUserStatus = (userId: number | string, status: string) => {
  80. const data = {
  81. userId,
  82. status
  83. };
  84. return request({
  85. url: '/system/user/changeStatus',
  86. method: 'put',
  87. data: data
  88. });
  89. };
  90. /**
  91. * 查询用户个人信息
  92. */
  93. export const getUserProfile = (): AxiosPromise<UserInfoVO> => {
  94. return request({
  95. url: '/system/user/profile',
  96. method: 'get'
  97. });
  98. };
  99. /**
  100. * 修改用户个人信息
  101. * @param data 用户信息
  102. */
  103. export const updateUserProfile = (data: UserForm) => {
  104. return request({
  105. url: '/system/user/profile',
  106. method: 'put',
  107. data: data
  108. });
  109. };
  110. /**
  111. * 用户密码重置
  112. * @param oldPassword 旧密码
  113. * @param newPassword 新密码
  114. */
  115. export const updateUserPwd = (oldPassword: string, newPassword: string) => {
  116. const data = {
  117. oldPassword,
  118. newPassword
  119. };
  120. return request({
  121. url: '/system/user/profile/updatePwd',
  122. method: 'put',
  123. params: data
  124. });
  125. };
  126. /**
  127. * 用户头像上传
  128. * @param data 头像文件
  129. */
  130. export const uploadAvatar = (data: FormData) => {
  131. return request({
  132. url: '/system/user/profile/avatar',
  133. method: 'post',
  134. data: data
  135. });
  136. };
  137. /**
  138. * 查询授权角色
  139. * @param userId 用户ID
  140. */
  141. export const getAuthRole = (userId: string | number): AxiosPromise<{ user: UserVO; roles: RoleVO[] }> => {
  142. return request({
  143. url: '/system/user/authRole/' + userId,
  144. method: 'get'
  145. });
  146. };
  147. /**
  148. * 保存授权角色
  149. * @param data 用户ID
  150. */
  151. export const updateAuthRole = (data: { userId: string; roleIds: string }) => {
  152. return request({
  153. url: '/system/user/authRole',
  154. method: 'put',
  155. params: data
  156. });
  157. };
  158. /**
  159. * 查询当前部门的所有用户信息
  160. * @param deptId
  161. */
  162. export const listUserByDeptId = (deptId: string | number): AxiosPromise<UserVO[]> => {
  163. return request({
  164. url: '/system/user/list/dept/' + deptId,
  165. method: 'get'
  166. });
  167. };
  168. /**
  169. * 查询部门下拉树结构
  170. */
  171. export const deptTreeSelect = (): AxiosPromise<DeptVO[]> => {
  172. return request({
  173. url: '/system/user/deptTree',
  174. method: 'get'
  175. });
  176. };
  177. export default {
  178. listUser,
  179. getUser,
  180. addUser,
  181. updateUser,
  182. delUser,
  183. resetUserPwd,
  184. changeUserStatus,
  185. getUserProfile,
  186. updateUserProfile,
  187. updateUserPwd,
  188. uploadAvatar,
  189. getAuthRole,
  190. updateAuthRole,
  191. deptTreeSelect,
  192. listUserByDeptId
  193. };