user.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { request } from '@/utils/request'
  2. export function getInfo() {
  3. return request({
  4. url: '/system/user/getInfo',
  5. method: 'get'
  6. })
  7. }
  8. // 用户密码重置
  9. export function updateUserPwd(oldPassword, newPassword) {
  10. const data = {
  11. oldPassword,
  12. newPassword
  13. }
  14. return request({
  15. url: '/system/user/profile/updatePwd',
  16. method: 'put',
  17. data: data
  18. })
  19. }
  20. // 修改用户个人信息
  21. export function updateUserProfile(data) {
  22. return request({
  23. url: '/system/user/profile',
  24. method: 'put',
  25. data: data
  26. })
  27. }
  28. /**
  29. * 账号注销
  30. * @Author: Antigravity
  31. */
  32. export function cancelUser() {
  33. return request({
  34. url: '/system/user/cancel',
  35. method: 'delete'
  36. })
  37. }
  38. // 上传头像
  39. // @Author: Antigravity
  40. export function uploadAvatar(filePath) {
  41. return new Promise((resolve, reject) => {
  42. const token = uni.getStorageSync('token') || ''
  43. import('@/utils/config').then(({ BASE_URL }) => {
  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. })
  69. }