user.js 2.6 KB

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