Z1hgq před 7 roky
rodič
revize
d7e01fb7ea
2 změnil soubory, kde provedl 62 přidání a 116 odebrání
  1. 61 110
      Gkzs/index/index.js
  2. 1 6
      Gkzs/index/info/info.js

+ 61 - 110
Gkzs/index/index.js

xqd xqd xqd xqd xqd
@@ -15,96 +15,76 @@ Page({
   /**
    * 生命周期函数--监听页面加载
    */
-  onLoad: function (options) {
+  onLoad: function(options) {
     // 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){
-
-    // }
+    if (wx.getStorageSync('uid')) {
+      var app = getApp()
+      app.userinfo.userid = wx.getStorageSync('uid')
+      console.log(getApp().userinfo.userid)
+      wx.redirectTo({
+        url: "info/info",
+      })
+    }
   },
 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
-  onReady: function () {
+  onReady: function() {
 
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow: function () {
+  onShow: function() {
 
   },
 
   /**
    * 生命周期函数--监听页面隐藏
    */
-  onHide: function () {
+  onHide: function() {
 
   },
 
   /**
    * 生命周期函数--监听页面卸载
    */
-  onUnload: function () {
+  onUnload: function() {
 
   },
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作
    */
-  onPullDownRefresh: function () {
+  onPullDownRefresh: function() {
 
   },
 
   /**
    * 页面上拉触底事件的处理函数
    */
-  onReachBottom: function () {
+  onReachBottom: function() {
 
   },
 
   /**
    * 用户点击右上角分享
    */
-  onShareAppMessage: function () {
+  onShareAppMessage: function() {
 
   },
-  showTopTips: function () {
+  showTopTips: function() {
     var that = this;
     if (!that.data.isAgree) {
       wx.hideLoading()
       this.setData({
         showTopTips: true
       });
-      setTimeout(function () {
+      setTimeout(function() {
         that.setData({
           showTopTips: false
         });
@@ -119,7 +99,7 @@ Page({
           userid: that.data.userid
         },
         method: 'POST',
-        success: function (res) {
+        success: function(res) {
           console.log(res.data)
         }
       })
@@ -129,21 +109,20 @@ Page({
 
     }
   },
-  bindAgreeChange: function (e) {
+  bindAgreeChange: function(e) {
     this.setData({
       isAgree: !!e.detail.value.length
     });
   },
-  getInfo: function () {
+  getInfo: function() {
     var that = this
     var WxParse = require('../wxParse/wxParse.js');
     wx.request({
-      url: 'https://t10.9026.com/api/home/getintroduction',  //这里''里面填写你的服务器API接口的路径    
-      data: {
-      },  //这里是可以填写服务器需要的参数    
+      url: 'https://t10.9026.com/api/home/getintroduction', //这里''里面填写你的服务器API接口的路径    
+      data: {}, //这里是可以填写服务器需要的参数    
       method: 'GET', // 声明GET请求    
       // header: {}, // 设置请求的 header,GET请求可以不填    
-      success: function (res) {
+      success: function(res) {
         let test = JSON.stringify(res.data)
         let tet = JSON.parse(test)
         that.setData({
@@ -151,59 +130,58 @@ Page({
         })
         var article = tet.data.list[0].content
         WxParse.wxParse('article', 'html', article, that, 5)
-        //callback(tet)
       }
     });
   },
-  userLogin: function (e) {
+  userLogin: function(e) {
     console.log(e.detail)
     var un = JSON.parse(e.detail.rawData)
     var that = this
-    if(that.data.isAgree == false){
-    }else{
+    if (that.data.isAgree == false) {} else {
       wx.showLoading({
         title: '登录中',
       })
       try {
         wx.login({
-          success: function (res) {
+          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
-                    })
-                    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()
-                    }
-                  }
+            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
                 })
+                var app = getApp()
+                app.userinfo.userid = that.data.userid
+                console.log(getApp().userinfo.userid)
+                wx.setStorageSync('uid', 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) {
@@ -214,33 +192,6 @@ Page({
         user: e.detail.userInfo
       });
       that.login(that.data.user)
-    } else {
-    }
+    } 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 - 6
Gkzs/index/info/info.js

xqd xqd
@@ -34,11 +34,6 @@ Page({
    */
   onLoad: function (options) {
     wx.hideLoading()
-    var date = new Date()
-    wx.setStorage({
-      key: 'logDate',
-      data: date,
-    })
     wx.setStorage({
       key: 'userid',
       data: getApp().userinfo.userid,
@@ -47,7 +42,7 @@ Page({
     wx.request({
       url: 'https://t10.9026.com/api/home/getbasedata',  //这里''里面填写你的服务器API接口的路径    
       data: {
-        userid: getApp().userinfo.userid
+        userid: wx.getStorageSync('uid')
       },  //这里是可以填写服务器需要的参数    
       method: 'POST', // 声明GET请求    
       // header: {}, // 设置请求的 header,GET请求可以不填