Browse Source

登陆时增加code参数

XWookey 1 year ago
parent
commit
0050d6c1fc
2 changed files with 101 additions and 87 deletions
  1. 52 43
      pages/login/phone_login/phone_login.js
  2. 49 44
      pages/login/username_login/username_login.js

+ 52 - 43
pages/login/phone_login/phone_login.js

@@ -227,51 +227,60 @@ Page({
       return;
       return;
     }
     }
     log.info('[登录]', '[登录]', '[请求]', { phone, vcode });
     log.info('[登录]', '[登录]', '[请求]', { phone, vcode });
-    wx.request({
-      url: getApp().globalData.postHeadAgreement +'/restapi/wechat/phoneLogin',
-      data: {
-        phonenumber: phone,
-        // ip:ip,
-        vcode
-      },
-      method: 'POST',
-      success(res) {
-        console.log(res);
-        log.info('[登录]', '[登录]', '[响应]', res.data);
-        if (res.data.code == 1) {
-          if(res.data.msg!=null && res.data.msg.startsWith("503")){
-            getApp().showNetworkError();
-            return;
-          }
-           that.setData({
-             vcode: null,
-             passwordFocus:true//,
-             //errorMsg: res.data.msg
-           });
-          wx.showModal({
-            title: '提示',
-            content:res.data.msg,
-            showCancel:false,
-            confirmColor:'#00AADD',
+    wx.login({
+        success(loginRes) {
+
+          wx.request({
+            url: getApp().globalData.postHeadAgreement +'/restapi/wechat/phoneLogin',
+            data: {
+              phonenumber: phone,
+              // ip:ip,
+              vcode,
+              code: loginRes.code
+            },
+            method: 'POST',
+            success(res) {
+              console.log(res);
+              log.info('[登录]', '[登录]', '[响应]', res.data);
+              if (res.data.code == 1) {
+                if(res.data.msg!=null && res.data.msg.startsWith("503")){
+                  getApp().showNetworkError();
+                  return;
+                }
+                 that.setData({
+                   vcode: null,
+                   passwordFocus:true//,
+                   //errorMsg: res.data.msg
+                 });
+                wx.showModal({
+                  title: '提示',
+                  content:res.data.msg,
+                  showCancel:false,
+                  confirmColor:'#00AADD',
+                });
+                log.info('[登录]', '[登录]', '[失败code==1]', res.data);
+              } else {
+                //返回该用户
+                //跳转到上一页
+                wx.setStorageSync("userInfo", res.data);
+                wx.setStorageSync("isLogin", true);
+                //let url = `/pages/ucenter/index/index`;
+                log.info('[登录]', '[登录]', '[成功返回上一个界面]', res.data);
+                wx.navigateBack();
+                //wx.redirectTo({
+                // url
+                //});
+              }
+            },
+            fail(e){
+              getApp().showNetworkError();
+            }
           });
           });
-          log.info('[登录]', '[登录]', '[失败code==1]', res.data);
-        } else {
-          //返回该用户
-          //跳转到上一页
-          wx.setStorageSync("userInfo", res.data);
-          wx.setStorageSync("isLogin", true);
-          //let url = `/pages/ucenter/index/index`;
-          log.info('[登录]', '[登录]', '[成功返回上一个界面]', res.data);
-          wx.navigateBack();
-          //wx.redirectTo({
-          // url
-          //});
+
+
+
         }
         }
-      },
-      fail(e){
-        getApp().showNetworkError();
-      }
-    });
+      });
   },
   },
   
   
 
 

+ 49 - 44
pages/login/username_login/username_login.js

@@ -64,52 +64,57 @@ Page({
     let { loginName, password } = that.data;
     let { loginName, password } = that.data;
     log.info('[登录]', '[登录]', '[请求]', { loginName, password });
     log.info('[登录]', '[登录]', '[请求]', { loginName, password });
     let ipp = ip;
     let ipp = ip;
-    wx.request({
-      url: getApp().globalData.postHeadAgreement +'/restapi/wechat/login',
-      data: {
-        loginName,
-        // ip:ipp,
-        password
-      },
-      method: 'POST',
-      success(res) {
-        //console.log(res1);
-        //console.log(res1.data.code == 1);
-        log.info('[登录]', '[登录]', '[响应]', res.data);
-        if (res.data.code == 1) {
-          if(res.data.msg!=null && res.data.msg.startsWith("503")){
-            getApp().showNetworkError();
-            return;
-          }
-           that.setData({
-             password: null,
-             passwordFocus:true//,
-             //errorMsg: res.data.msg
-           });
-          wx.showModal({
-            title: '提示',
-            content:res.data.msg,
-            showCancel:false,
-            confirmColor:'#00AADD',
+    wx.login({
+        success(loginRes) {
+          wx.request({
+            url: getApp().globalData.postHeadAgreement +'/restapi/wechat/login',
+            data: {
+              loginName,
+              // ip:ipp,
+              password,
+              code: loginRes.code
+            },
+            method: 'POST',
+            success(res) {
+              //console.log(res1);
+              //console.log(res1.data.code == 1);
+              log.info('[登录]', '[登录]', '[响应]', res.data);
+              if (res.data.code == 1) {
+                if(res.data.msg!=null && res.data.msg.startsWith("503")){
+                  getApp().showNetworkError();
+                  return;
+                }
+                 that.setData({
+                   password: null,
+                   passwordFocus:true//,
+                   //errorMsg: res.data.msg
+                 });
+                wx.showModal({
+                  title: '提示',
+                  content:res.data.msg,
+                  showCancel:false,
+                  confirmColor:'#00AADD',
+                });
+                log.info('[登录]', '[登录]', '[失败code==1]', res.data);
+              } else {
+                //返回该用户
+                //跳转到上一页
+                wx.setStorageSync("userInfo", res.data);
+                wx.setStorageSync("isLogin", true);
+                //let url = `/pages/ucenter/index/index`;
+                log.info('[登录]', '[登录]', '[成功返回上一个界面]', res.data);
+                wx.navigateBack();
+                //wx.redirectTo({
+                // url
+                //});
+              }
+            },
+            fail(e){
+              getApp().showNetworkError();
+            }
           });
           });
-          log.info('[登录]', '[登录]', '[失败code==1]', res.data);
-        } else {
-          //返回该用户
-          //跳转到上一页
-          wx.setStorageSync("userInfo", res.data);
-          wx.setStorageSync("isLogin", true);
-          //let url = `/pages/ucenter/index/index`;
-          log.info('[登录]', '[登录]', '[成功返回上一个界面]', res.data);
-          wx.navigateBack();
-          //wx.redirectTo({
-          // url
-          //});
         }
         }
-      },
-      fail(e){
-        getApp().showNetworkError();
-      }
-    });
+      });
   },
   },
   phoneCall(){
   phoneCall(){
     wx.makePhoneCall({
     wx.makePhoneCall({