|
@@ -19,6 +19,50 @@ export default class user {
|
|
|
return request(APIConfig.getUserUrl(``), opts);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * //上传头像
|
|
|
+ * @return 返回Promise
|
|
|
+ */
|
|
|
+ static async uploadImage(photo_url) {
|
|
|
+ const file_uid = await getuid();
|
|
|
+ let formData = new FormData();
|
|
|
+ formData.append('file', {
|
|
|
+ uri: photo_url,
|
|
|
+ name: file_uid + '.jpg',
|
|
|
+ type: 'image/jpeg'
|
|
|
+ });
|
|
|
+ let options = {};
|
|
|
+ options.body = formData;
|
|
|
+ options.headers = { 'Content-Type': 'multipart/form-data', uid: file_uid };
|
|
|
+ options.method = 'POST';
|
|
|
+ return fetch(APIConfig.getUploadImg(), options)
|
|
|
+ .then((response) => {
|
|
|
+ console.log('res1', response);
|
|
|
+ if (response.status >= 200 && response.status < 300) {
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ const error = new Error(response.statusText);
|
|
|
+ error.response = response;
|
|
|
+ throw error;
|
|
|
+ })
|
|
|
+ .then((response) => {
|
|
|
+ return response.json();
|
|
|
+ })
|
|
|
+ .then((data) => {
|
|
|
+ console.log('data', data);
|
|
|
+ if (!data.success) {
|
|
|
+ const code = data;
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log('err', err);
|
|
|
+ return {
|
|
|
+ err
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
//绑定微信
|
|
|
static bind_wechat(opts) {
|
|
|
return request(APIConfig.getUserUrl(`/wechatBind`), opts);
|
|
@@ -43,3 +87,17 @@ export default class user {
|
|
|
return request(APIConfig.getUserUrl(``), opts);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+async function getuid() {
|
|
|
+ const uid = await storage
|
|
|
+ .load({
|
|
|
+ key: 'userInfo'
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ return '';
|
|
|
+ });
|
|
|
+ if (uid === '') {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ return JSON.parse(uid).uid;
|
|
|
+}
|