index.ts 4.3 KB

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