xiabx 5 rokov pred
rodič
commit
d637d97b16
3 zmenil súbory, kde vykonal 16 pridanie a 12 odobranie
  1. 12 9
      src/api/fly.js
  2. 2 2
      src/api/index.js
  3. 2 1
      src/views/Phone/index.ux

+ 12 - 9
src/api/fly.js

@@ -11,35 +11,38 @@ import apiConfig from "./config";
 import { getToken, clearToken } from "./utils";
 
 var fly = new Fly(fetch);
-
+var qs = require('qs');
 fly.config.baseURL = apiConfig.baseURL;
-fly.config.headers["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8";
+fly.config.headers["Content-Type"] =
+  "application/x-www-form-urlencoded;charset=utf-8";
 
-const filterNoToken = ["/login"]
+const filterNoToken = ["/login"];
 
 fly.interceptors.request.use(async config => {
   // 过滤一些不需要登录的路由
   if (filterNoToken.indexOf(config.url) === -1) {
-    console.log(config);
     let token = await getToken();
     if (config.headers) config.headers.Authorization = token;
     else config.headers = { Authorization: token };
+    if (config.method === "POST") {
+      config.body=qs.stringify(config.body);
+    } 
     return config;
   } else return config;
-})
+});
 
 fly.interceptors.response.use(
   res => {
     if (!res.data.code) {
-      return res.data.data
+      return res.data.data;
     } else if (res.data.code === 10023) {
       // token失效
       clearToken();
       return getToken().then(token => {
-        return r(res.config)
-      })
+        return r(res.config);
+      });
     } else {
-      return Promise.reject(res)
+      return Promise.reject(res);
     }
   },
   err => {

+ 2 - 2
src/api/index.js

@@ -82,8 +82,8 @@ export const getUserInfo = () => {
 };
 
 //发送短信
-export const sendCode = (phone) => {
-  return fly.post(`/user/sendCode`,{phone:phone});
+export const sendCode = (params) => {
+  return fly.post(`/user/sendCode`,params);
 };
 
 //用户绑定

+ 2 - 1
src/views/Phone/index.ux

@@ -31,7 +31,8 @@ export default {
   async sendMsg() {
     let result = validatePhone(this.mobile);
     if (result) {
-      let res = await sendCode(this.mobile);
+      let res = await sendCode({phone:this.mobile});
+      console.log(res)
       this.countDown();
     } else {
       prompt.showToast({