Jelajahi Sumber

修改 授权 时间点

stanley-king 4 tahun lalu
induk
melakukan
2da32f26a6

+ 21 - 18
app.js

@@ -5,7 +5,7 @@ App({
     onLaunch: function() {
         let self = this;
         // 登录
-        this.mWxAuthor = new WxAuthor(self)
+        this.mWxAuthor = new WxAuthor(self,true)
         const dirs = ['addAddress','address','myhome','confirmOrder','confirmVOrder',
         'order_tabs','orderPaySn','person','postageDetail','postageManage','shopCart'];
 
@@ -20,7 +20,8 @@ App({
         fMinistart: false,
         userId: {
             openid: '',
-            unionid: ''
+            unionid: '',
+            timeStamp:0
         },
         userInfo: null,
         defaultAddress: null,
@@ -34,6 +35,7 @@ App({
         authPages: null,
         mWxAuthor:null,
         member_id:0,
+        hasmobile: false,
         relay_id:0
     },
 
@@ -71,33 +73,34 @@ App({
     },
     navigateto(page) 
     {
-        this.globalData.authPages.forEach(prefix => {
-            if(page.indexOf(prefix) == 0) {
-                if(!this.globalData.userInfo) {
+        if (!this.globalData.userInfo)
+        {
+            this.globalData.authPages.forEach(prefix => {
+                if (page.indexOf(prefix) == 0) {
                     wx.navigateTo({
                         url: '/pages/auth/auth',
                     })
                     return;
-                }                
-            }            
-        });
-        
+                }
+            });
+        }        
+      
         wx.navigateTo({
             url: page,
         })
     },
-    switchtab(page) {
-        this.globalData.authPages.forEach(prefix => {
-            if(page.indexOf(prefix) == 0) {
-                if(!this.globalData.userInfo) {
+    switchtab(page) {        
+        if (!this.globalData.userInfo) {
+            this.globalData.authPages.forEach(prefix => {
+                if(page.indexOf(prefix) == 0) {
                     wx.navigateTo({
                         url: '/pages/auth/auth',
                     })
                     return;
-                }                
-            }            
-        });
-        
+                }            
+            });
+        }
+
         wx.switchTab({
             url: page,
         })
@@ -107,7 +110,7 @@ App({
         return data.filter(val => val.card_type === key)[0] || {}
     },
     relogin() {
-        this.mWxAuthor.init();
+        this.mWxAuthor.init(true);
     },
     cardShareInfo() {
         console.log('index onShareAppMessage')

+ 20 - 3
pages/auth/auth.js

@@ -1,9 +1,16 @@
 // pages/auth.js
+
+import WxAuthor from '../../utils/WxAuthor'
+
+
+let app = getApp();
+
 Page({
   /**
    * 页面的初始数据
    */
   data: {
+    mWxAuthor: null,
     userInfo: {}
   },
 
@@ -11,7 +18,17 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    console.log('onLoad options:', options)
+    var timeStamp = new Date().getTime();
+    timeStamp = Math.floor(timeStamp);
+    
+    if (timeStamp > app.globalData.userId.timeStamp + 300) {
+      if(!app.globalData.userInfo) {
+        this.mWxAuthor = new WxAuthor(self, true);
+      } else {
+        this.mWxAuthor = new WxAuthor(self, false);
+      }
+    } 
   },
 
   getAuth(e) {
@@ -36,8 +53,8 @@ Page({
   /**
    * 生命周期函数--监听页面显示
    */
-  onShow: function () {
-
+  onShow: function (options) {
+    console.log('auth onShow:',options)
   },
 
   /**

+ 18 - 3
pages/components/auth/auth.js

@@ -1,6 +1,7 @@
 // pages/components/auth/auth.js
 const api = require('../../../config');
 const getReq = require('../../../config').getReq;
+
 let app = getApp();
 Component({
   /**
@@ -16,15 +17,27 @@ Component({
   data: {
     phone_iv: '',
     phone_encryptedData: '',
-    showAuthName:true,
-    showAuthPhone:false,
     userInfoE:{},
+    showAuthName: true,
+    showAuthPhone: false,
   },
 
+  lifetimes: {
+    attached: function () {
+      if (!app.globalData.hasmobile) {
+        this.setData({ showAuthName: false, showAuthPhone: true })
+      }      
+    },
+    detached: function () {
+    },
+  },
   /**
    * 组件的方法列表
    */
   methods: {
+    onLoad: function () {
+
+    },
     userPhoneHandler: function(e) { 
       this.phone_encryptedData = e.detail.encryptedData
       this.phone_iv = e.detail.iv
@@ -63,7 +76,9 @@ Component({
       getReq(app,params, function (res) {
         if (res.code == 200) {
           let datas = res.datas;
-          app.globalData.member_id = datas.member_id  
+          app.globalData.member_id = datas.member_id
+          app.globalData.hasmobile = datas.hasmobile
+
           if (datas.hasmobile == false) {
             self.setData({showAuthName:false,showAuthPhone:true})
           }

+ 1 - 1
pages/components/auth/auth.wxml

@@ -5,7 +5,7 @@
   </view>
 
   <view class="auth_text" wx:if="{{showAuthPhone}}">
-    <view>给充话费和油费,都需要用户手机号码,点击“授权手机号码”后,您将最快捷使用全部功能。</view>
+    <view>话费充值需要输入手机号码,油卡充值运营商需要用户手机号码。</view>
   </view>
 
   <button wx:if="{{showAuthName}}" 

+ 2 - 1
pages/components/blockItem/blockItem.wxml

@@ -6,7 +6,8 @@
   </block>
 
 <block wx:elif="{{item_data.show_type == 'brand'|| item_data.type == 'brand'}}">
-    <image src="{{item_data.image}}" bindload='load' class='{{imgShow? "show" : "hide"}}' lazy-load="true" mode='widthFix' style='min-height:250rpx;' data-title="{{item_data.title}}"></image>
+    <image src="{{item_data.image}}" bindload='load' class='{{imgShow? "show" : "hide"}}' lazy-load="true" mode='widthFix' 
+           style='min-height:250rpx;' data-title="{{item_data.title}}"></image>
 </block>
 
 <block wx:elif="{{item_data.show_type == 'ugc'|| item_data.type == 'ugc'}}">

+ 0 - 1
pages/components/blockList/blockList.wxml

@@ -4,7 +4,6 @@
                 scale="{{item.scale}}">
     </carousel>
     <divider wx:if="{{item.item_type == 'divider'}}" items="{{item}}"></divider>
-
     <homeThree wx:if="{{item.item_type == 'home3'}}" specialData="{{item}}" items="{{item.items}}"></homeThree> 
     <homeOne wx:if="{{item.item_type == 'home1'}}" special_datas="{{special_datas}}"  items="{{item.items}}" summery="{{summery}}"></homeOne>
     <homeOne wx:if="{{item.item_type == 'home5'}}" items="{{item.items}}"></homeOne>

+ 1 - 2
pages/login/login.js

@@ -2,8 +2,8 @@
 const api = require('../../config.js');
 const getReq = require('../../config.js').getReq;
 let app = getApp();
-Page({
 
+Page({
   /**
    * 页面的初始数据
    */
@@ -80,7 +80,6 @@ Page({
           act: "login",
           op: "wxauthen",
           relay_id: app.globalData.relay_id
-
       }
       getReq(app,params, function (res) {
         if (res.code == 200) {

+ 1 - 1
pages/login/login.wxss

@@ -13,7 +13,7 @@
 .auth_text {
   width: 82%;
   margin: auto;
-  font-size: 28rpx;
+  font-size: 32rpx;
   color: #333;
   line-height: 42rpx;
   text-align: center;

+ 4 - 0
pages/postage/postage.js

@@ -123,6 +123,10 @@ Page({
   // 立即充值
   handlerRecharge()
   {
+    if (!app.globalData.hasmobile) {
+      app.navigateto('/pages/auth/auth')
+      return;
+    }
     console.log('handlerRecharge:',this.data)
     const { goods_id } = this.data
     let card_type = ''

+ 20 - 12
utils/WxAuthor.js

@@ -1,12 +1,18 @@
 const getReq = require('../config.js').getReq
 const api    = require('../config.js').host
+
 export default class WxAuthor {
-  constructor(app) {
+  fGetSetting = true
+
+  constructor(app, getsetting) {
     this.target = app
-    this.init()
+    this.init(getsetting)
   }
   // 首先wx.login
-  init() {
+  init(getsetting) {
+    this.target.globalData.fMinistart = false
+
+    this.fGetSetting = getsetting
     wx.login({
       success: res => {
         this.ministart(res.code)
@@ -26,14 +32,15 @@ export default class WxAuthor {
         let { openid, unionid } = res.datas
         if (openid && unionid) {
           this.setId(openid, unionid)
-          this.getSetting(false)
+          if(this.fGetSetting) {
+            this.getSetting(false)
+          }
         } else {
-          this.getSetting(true)
+          if(this.fGetSetting) {
+            this.getSetting(true)
+          }          
         }
       }
-      else {
-        return
-      }
     })
   }
 
@@ -41,11 +48,9 @@ export default class WxAuthor {
     wx.getSetting({
       success: res => {
         if (res.authSetting['scope.userInfo']) {
+          console.log('wx getSetting:',res)
           this.getUserInfo(flag)
         }
-        else {
-          return
-        }
       }
     })
   }
@@ -56,6 +61,7 @@ export default class WxAuthor {
       withCredentials,
       success: res => {
         this.setUserInfo(res.userInfo, res.userInfo.nickName)
+
         let userInfo = this.target.globalData.userInfo
         if (flag) {
           let { encryptedData, signature, iv } = res
@@ -76,7 +82,6 @@ export default class WxAuthor {
       op: "wxauthen",
       relay_id: relay_id
     }
-
     getReq(this.target,params, res => {
       if (res.code == 200) {
         this.target.globalData.member_id = res.datas.member_id
@@ -124,5 +129,8 @@ export default class WxAuthor {
   setId(openid, unionid) {
     this.target.globalData.userId.openid = openid
     this.target.globalData.userId.unionid = unionid
+    var timeStamp = new Date().getTime();
+    timeStamp = Math.floor(timeStamp);
+    this.target.globalData.userId.timeStamp = timeStamp
   }
 }