user.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { request } from '@/utils/request'
  2. import { BASE_URL } from '@/utils/config'
  3. export function getInfo() {
  4. return request({
  5. url: '/system/user/getInfo',
  6. method: 'get'
  7. })
  8. }
  9. // 用户密码重置
  10. export function updateUserPwd(oldPassword, newPassword) {
  11. const data = {
  12. oldPassword,
  13. newPassword
  14. }
  15. return request({
  16. url: '/system/user/profile/updatePwd',
  17. method: 'put',
  18. data: data
  19. })
  20. }
  21. // 修改用户个人信息
  22. export function updateUserProfile(data) {
  23. return request({
  24. url: '/system/user/profile',
  25. method: 'put',
  26. data: data
  27. })
  28. }
  29. /**
  30. * 账号注销
  31. * @Author: Antigravity
  32. */
  33. export function cancelUser() {
  34. return request({
  35. url: '/system/user/cancel',
  36. method: 'delete'
  37. })
  38. }
  39. // 上传头像
  40. // @Author: Antigravity
  41. export function uploadAvatar(filePath) {
  42. return new Promise((resolve, reject) => {
  43. const token = uni.getStorageSync('token') || ''
  44. uni.uploadFile({
  45. url: BASE_URL + '/system/user/profile/avatar',
  46. filePath: filePath,
  47. name: 'avatarfile',
  48. header: {
  49. 'Authorization': token ? `Bearer ${token}` : '',
  50. 'clientid': 'fe63fea7be31b0200b496d08bc6b517d',
  51. 'X-Platform-Code': 'MfJkMNMW2JKXBuPcbP2rxkD3ynXmReAZZFm4fN7cAGwGJdKCmd'
  52. },
  53. success: (res) => {
  54. const resData = JSON.parse(res.data)
  55. if (resData.code === 200) {
  56. resolve(resData.data)
  57. } else {
  58. uni.showToast({ title: resData.msg || '上传失败', icon: 'none' })
  59. reject(resData.msg)
  60. }
  61. },
  62. fail: (err) => {
  63. uni.showToast({ title: '网络异常', icon: 'none' })
  64. reject(err)
  65. }
  66. })
  67. })
  68. }