Z1hgq 7 лет назад
Родитель
Сommit
b52f156649
5 измененных файлов с 122 добавлено и 78 удалено
  1. 113 72
      Gkzs/index/index.js
  2. 1 0
      Gkzs/index/index.json
  3. 6 5
      Gkzs/index/index.wxml
  4. 1 0
      Gkzs/index/index.wxss
  5. 1 1
      Gkzs/index/info/info.js

+ 113 - 72
Gkzs/index/index.js

xqd xqd xqd
@@ -19,34 +19,34 @@ Page({
     // this.userLogin()
     this.getInfo()
     var that = this
-    try{
-      wx.getStorage({
-        key: 'logDate',
-        success: function (res) {
-          console.log('prelogDate:' + res.data)
-          var nowDate = new Date()
-          if (nowDate - res.data < 30 * 60 * 1000) {
-            console.log(nowDate - res.data)
-            wx.getStorage({
-              key: 'userid',
-              success: function (res) {
-                wx.showLoading({
-                  title: '正在自动登录',
-                })
-                var app = getApp()
-                app.userinfo.userid = res.data
-                console.log(getApp().userinfo.userid)
-                wx.redirectTo({
-                  url: "info/info",
-                })
-              },
-            })
-          }
-        },
-      })
-    }catch(e){
-
-    }
+    // try{
+    //   wx.getStorage({
+    //     key: 'logDate',
+    //     success: function (res) {
+    //       console.log('prelogDate:' + res.data)
+    //       var nowDate = new Date()
+    //       if (nowDate - res.data < 30 * 60 * 1000) {
+    //         console.log(nowDate - res.data)
+    //         wx.getStorage({
+    //           key: 'userid',
+    //           success: function (res) {
+    //             wx.showLoading({
+    //               title: '正在自动登录',
+    //             })
+    //             var app = getApp()
+    //             app.userinfo.userid = res.data
+    //             console.log(getApp().userinfo.userid)
+    //             wx.redirectTo({
+    //               url: "info/info",
+    //             })
+    //           },
+    //         })
+    //       }
+    //     },
+    //   })
+    // }catch(e){
+
+    // }
   },
 
   /**
@@ -143,7 +143,7 @@ Page({
       },  //这里是可以填写服务器需要的参数    
       method: 'GET', // 声明GET请求    
       // header: {}, // 设置请求的 header,GET请求可以不填    
-      complete: function (res) {
+      success: function (res) {
         let test = JSON.stringify(res.data)
         let tet = JSON.parse(test)
         that.setData({
@@ -155,51 +155,92 @@ Page({
       }
     });
   },
-  userLogin: function () {
-    wx.showLoading({
-      title: '登录中',
-    })
+  userLogin: function (e) {
+    console.log(e.detail)
+    var un = JSON.parse(e.detail.rawData)
     var that = this
-    try {
-      wx.login({
-        success: function (res) {
-          let code = res.code
-          console.log(code)
-          var c = getApp()
-          c.userinfo.usercode = res.code
-          wx.getUserInfo({
-            success: function (res) {
-              //let encrypted_data = res.encryptedData
-              let tx = res.userInfo.avatarUrl
-              let nn = res.userInfo.nickName
-              wx.request({
-                url: 'https://t10.9026.com/api/home/login',
-                method: 'POST',
-                data: {
-                  code: code,
-                  avatar: tx,
-                  nickName: nn,
-                },
-                success: function (res) {
-                  that.setData({
-                    userid: res.data.data.userinfo.id
-                  })
-                  var app = getApp()
-                  app.userinfo.userid = that.data.userid
-                  console.log(getApp().userinfo.userid)
-                  if (res.data.data.userinfo.has_agreed == 1) {
-                    wx.redirectTo({
-                      url: 'info/info'
+    if(that.data.isAgree == false){
+    }else{
+      wx.showLoading({
+        title: '登录中',
+      })
+      try {
+        wx.login({
+          success: function (res) {
+            let code = res.code
+            console.log(code)
+                let tx = un.avatarUrl
+                let nn = un.nickName
+                wx.request({
+                  url: 'https://t10.9026.com/api/home/login',
+                  method: 'POST',
+                  data: {
+                    code: code,
+                    avatar: tx,
+                    nickName: nn,
+                  },
+                  success: function (res) {
+                    that.setData({
+                      userid: res.data.data.userinfo.id
                     })
-                  } else {
-                    that.showTopTips()
+                    var app = getApp()
+                    app.userinfo.userid = that.data.userid
+                    console.log(getApp().userinfo.userid)
+                    if (res.data.data.userinfo.has_agreed == 1) {
+                      wx.hideLoading();
+                      wx.showToast({
+                        title: '登录成功',
+                        icon: 'success',
+                        duration: 1000,
+                      })
+                      wx.redirectTo({
+                        url: 'info/info'
+                      })
+                    } else {
+                      that.showTopTips()
+                    }
                   }
-                }
-              })
-            }
-          })
-        }
-      })
-    } catch (e) { }
+                })
+          }
+        })
+      } catch (e) { }
+    }
+  },
+  handleUserInfo(e) {
+    var that = this
+    let msg = e.detail.errMsg;
+    if (msg === 'getUserInfo:ok') {
+      that.setData({
+        user: e.detail.userInfo
+      });
+      that.login(that.data.user)
+    } else {
+    }
   },
+//  login:function(userInfo) { 
+//     wx.login({
+//       success: res => {
+//         // 发送 res.code 到后台换取 openId, sessionKey, unionId
+//         if (res.code) {
+//           //存用户信息
+//           wx.setStorageSync('UserInFo', userInfo)
+//           // 扫面二维码进入
+//           let Scene = wx.getStorageSync('scene')
+//           let userInfoStr = JSON.stringify(userInfo);
+//           wx.request({
+//             url: api.WxUnionId,
+//             data: {
+              
+//             },
+//             method: 'POST',
+//             header: {
+//               'content-type': 'application/x-www-form-urlencoded'
+//             },
+//             success: callback
+//           })
+//         } else {
+
+//         }
+//       }
+//     })    
 })

+ 1 - 0
Gkzs/index/index.json

xqd
@@ -0,0 +1 @@
+{}

+ 6 - 5
Gkzs/index/index.wxml

xqd xqd
@@ -3,12 +3,12 @@
   <view class="page__hd">
     <view class="page__title">{{title}}</view>
     <view class="page__desc">
-      <import src = "../wxParse/wxParse.wxml"/>
-      <template is="wxParse" data="{{wxParseData:article.nodes}}"/>
+      <import src="../wxParse/wxParse.wxml" />
+      <template is="wxParse" data="{{wxParseData:article.nodes}}" />
     </view>
   </view>
   <view class='page__bd'>
-  <view class="weui-toptips weui-toptips_warn" wx:if="{{showTopTips}}">未同意使用协议</view>
+    <view class="weui-toptips weui-toptips_warn" wx:if="{{showTopTips}}">未同意使用协议</view>
     <checkbox-group bindchange="bindAgreeChange">
       <label class="weui-agree" for="weuiAgree">
         <view class="weui-agree__text">
@@ -16,12 +16,13 @@
           <view class="weui-agree__checkbox-icon">
             <icon class="weui-agree__checkbox-icon-check" type="success_no_circle" size="9" wx:if="{{isAgree}}"></icon>
           </view>
-          本人已阅读使用说明,同意<navigator url="terms/terms" class="weui-agree__link">《使用协议》</navigator>
+          本人已阅读使用说明,同意
+          <navigator url="terms/terms" class="weui-agree__link">《使用协议》</navigator>
         </view>
       </label>
     </checkbox-group>
     <view class="weui-btn-area">
-            <button open-type='getUserInfo' class="weui-btn" type="primary" bindtap="userLogin">进入高考志愿助手</button>
+      <button open-type="getUserInfo" bindgetuserinfo='userLogin' class="weui-btn" type="primary">进入高考志愿助手</button>
     </view>
   </view>
 </view>

+ 1 - 0
Gkzs/index/index.wxss

xqd
@@ -0,0 +1 @@
+/* index/index.wxss */

+ 1 - 1
Gkzs/index/info/info.js

xqd
@@ -51,7 +51,7 @@ Page({
       },  //这里是可以填写服务器需要的参数    
       method: 'POST', // 声明GET请求    
       // header: {}, // 设置请求的 header,GET请求可以不填    
-      complete: function (res) {
+      success: function (res) {
         let test = JSON.stringify(res.data)
         let tet = JSON.parse(test)
         console.log(res.data)