user.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import APIConfig from './api.js';
  2. import efunRequest from '../utils/efunRequest';
  3. import request from '../utils/request';
  4. export default class user {
  5. // 个人中心
  6. static userMember() {
  7. return request(`http://ott80test-base.yifangjiaoyu.cn/mobile/user/member`, {
  8. method: 'get'
  9. });
  10. }
  11. //更新个人信息
  12. static update_UserInfo(opts) {
  13. return request(APIConfig.getUserUrl(``), opts);
  14. }
  15. /**
  16. * //上传头像
  17. * @return 返回Promise
  18. */
  19. static async uploadImage(photo_url) {
  20. const file_uid = await getuid();
  21. let formData = new FormData();
  22. formData.append('file', {
  23. uri: photo_url,
  24. name: file_uid + '.jpg',
  25. type: 'image/jpeg'
  26. });
  27. let options = {};
  28. options.body = formData;
  29. options.headers = { 'Content-Type': 'multipart/form-data', uid: file_uid };
  30. options.method = 'POST';
  31. return fetch(APIConfig.getUploadImg(), options)
  32. .then((response) => {
  33. console.log('res1', response);
  34. if (response.status >= 200 && response.status < 300) {
  35. return response;
  36. }
  37. const error = new Error(response.statusText);
  38. error.response = response;
  39. throw error;
  40. })
  41. .then((response) => {
  42. return response.json();
  43. })
  44. .then((data) => {
  45. console.log('data', data);
  46. if (!data.success) {
  47. const code = data;
  48. }
  49. return data;
  50. })
  51. .catch((err) => {
  52. console.log('err', err);
  53. return {
  54. err
  55. };
  56. });
  57. }
  58. //绑定微信
  59. static bind_wechat(opts) {
  60. return request(APIConfig.getUserUrl() + `/wechatBind`, opts);
  61. }
  62. //获取验证码
  63. static getVerificationCode(phone) {
  64. return request(APIConfig.getUserUrl() + `/sendCode?mobile=` + phone);
  65. }
  66. //绑定手机号
  67. static bind_phone(opts) {
  68. return request(APIConfig.getUserUrl() + `/mobileBind`, opts);
  69. }
  70. //手机号登陆注册
  71. static mobileLoginAndReg(opts) {
  72. return request(APIConfig.getUserUrl() + `/mobileLoginAndReg`, opts);
  73. }
  74. //微信登陆
  75. static wechatLogin(opts) {
  76. return request(APIConfig.getUserUrl(``), opts);
  77. }
  78. //跳过
  79. static jumpLogin(deviceCode, channel) {
  80. console.log('====================================');
  81. console.log('deviceCode', deviceCode);
  82. console.log('channel', channel);
  83. console.log('====================================');
  84. return request(APIConfig.getIsLogin() + `?deviceCode=` + deviceCode + '&channel=' + channel, { method: 'GET' });
  85. }
  86. }
  87. async function getuid() {
  88. const uid = await storage
  89. .load({
  90. key: 'userInfo'
  91. })
  92. .catch((error) => {
  93. return '';
  94. });
  95. if (uid === '') {
  96. return '';
  97. }
  98. return JSON.parse(uid).uid;
  99. }