Browse Source

'更新用户信息调试'

Rorschach 6 years ago
parent
commit
e8a11b082c
3 changed files with 53 additions and 9 deletions
  1. 4 1
      pages/components/PersonalInfo.js
  2. 1 1
      pages/services/user.js
  3. 48 7
      pages/utils/request.js

+ 4 - 1
pages/components/PersonalInfo.js

@@ -684,9 +684,12 @@ export default class PersonalInfo extends BasePage {
   }
 
   updateUserInfo(formData) {
+    console.log(formData)
     let opts = {
       method: "PUT", //请求方法
-      body: formData //请求体
+      body: {
+        nickName: '测试测试'
+      }
     };
     user.update_UserInfo(opts).then(res => {
       console.log(res);

+ 1 - 1
pages/services/user.js

@@ -4,7 +4,7 @@ import request from "../utils/request";
 
 export default class user {
   static update_UserInfo(opts) {
-    console.log(opts);
+    console.log('opts',opts);
     return request(APIConfig.getUserUrl(``), opts);
   }
 }

+ 48 - 7
pages/utils/request.js

@@ -2,6 +2,7 @@
  * 检查HTTP请求状态
  */
 function checkStatus(response) {
+    console.log('res1',response)
     if (response.status >= 200 && response.status < 300) {
         return response;
     }
@@ -29,8 +30,9 @@ function checkAPIDatas(data) {
 }
 
 function checkAPIError(err) {
-    const code = err.response.code;
-    const status = err.response.status;
+    console.log('err',err)
+    // const code = err.response.code;
+    // const status = err.response.status;
     // const { url, type, oStatus, statusText } = err.response;
     // Message.error(`地址:${url} 类型:${type} 状态:${oStatus} 信息:${statusText}`, 10);
     return {
@@ -47,17 +49,55 @@ function checkAPIError(err) {
  * @return {object}           An object containing either "data" or "err"
  */
 
-const request = async (url, options,callBack) => {
+const request = async (url, options) => {
+    // global.storage.save({
+    //     key:'token',
+    //     data: '123123123123',
+    //     expires: null
+    // });
     if (options) {
         const method = options.method.toUpperCase();
+        // switch(method){
+        //     case 'POST':
+        //             options.headers = {
+        //                 'Accept': 'application/json',
+        //                 'Content-Type': '"Content-Type": "application/json',
+        //                 "uid": 'c2e13090a563447c8744a8c03171d1db',
+        //                 'token': await storage.load({
+        //                     key: 'token'
+        //                 })
+        //             };
+        //         break;
+        //     case 'PUT':
+        //             options.headers = {
+        //                 'Accept': 'application/json',
+        //                 'Content-Type': 'application/x-www-form-urlencoded',
+        //                 "uid": 'c2e13090a563447c8744a8c03171d1db',
+        //                 // 'token': await storage.load({
+        //                 //     key: 'token'
+        //                 // })
+        //             };
+        //         break;
+        //         default:
+        //                 options.headers = {
+        //                     'token': await storage.load({
+        //                         key: 'token'
+        //                     })
+        //                 };
+        //             break;
+        // }
+        const token = await storage.load({
+            key: 'token'
+        });
         if (method === 'POST' || method === 'PATCH' || method === 'DELETE' || method === 'PUT') {
             options.headers = {
+                'Accept': 'application/json',
                 'Content-Type': 'application/json',
-                'token': await storage.load({
-                    key: 'token'
-                })
+                "uid": 'c2e13090a563447c8744a8c03171d1db',
+                'token': token?  token : null
             };
-        } else {
+            options.body = JSON.stringify(options.body)
+        }else {
             options.headers = {
                 'token': await storage.load({
                     key: 'token'
@@ -65,6 +105,7 @@ const request = async (url, options,callBack) => {
             };
         }
     }
+    console.log('options',options)
     return fetch(url, options)
         .then(checkStatus)
         .then(parseJSON)