Parcourir la source

fix: 1. 登录需要点击两次才能成功
2. 分享商品后,被分享的人点击后无法从商品详情页面返回

yll il y a 4 ans
Parent
commit
6130f3ffba

+ 63 - 21
view/xcx/components/authorize/authorize.js

@@ -26,16 +26,17 @@ Component({
     loading:false,
     errorSum:0,
     errorNum:3,
+    code: null, // wx login code
 	  canIUseGetUserProfile: false // 判断是否为最新获取用户信息函数
   },
   attached() {
     this.get_logo_url();
     this.setAuthStatus();
-	if (wx.getUserProfile) {
-	      this.setData({
-	        canIUseGetUserProfile: true
-	      })
-	    }
+	  if (wx.getUserProfile) {
+	    this.setData({
+	      canIUseGetUserProfile: true
+	    })
+	  }
   },
   methods: {
     close(){
@@ -88,24 +89,60 @@ Component({
         }
       })
     },
+
+    wxSilentLogin: function () {
+      return new Promise((resolve, reject) => {
+        wx.login({
+          success (res) {
+            resolve(res.code)
+          },
+          fail (err) {
+            reject(err)
+          }
+        })
+      })
+    },
+    wxGetUserProfile: function () {
+      return new Promise((resolve, reject) => {
+        wx.getUserProfile({
+          desc: '用于完善会员资料',
+          success: (res) => {
+            resolve(res)
+          },
+          fail: (err) => {
+            reject(err)
+          }
+        })
+      })
+    },
     // 获取用户信息
   	getUserProfile() {
   	  let that = this;
-  	  wx.showLoading({ title: '正在登录中' });
-  	  	wx.getUserProfile({
-  	  	      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
-  	  	      success: (res) => {
-  				  Util.getCodeLogin((code)=>{
-  					  let userInfo = res;
-  					  userInfo.code = code.code;
-  					  that.getWxUserInfo(userInfo);
-  				  })
-  	  	      },
-  	  		  fail: (err) => {
-  				  wx.hideLoading();
-  	  		  }
-  	  });
-  	},	
+      wx.showLoading({ title: '正在登录中' });
+      let p1 = this.wxSilentLogin()
+      let p2 = this.wxGetUserProfile()
+      Promise.all([p1, p2]).then((res) => {
+        let userInfo = res[1];
+        userInfo.code = res[0];
+        that.getWxUserInfo(userInfo);
+      }).catch((err) => {
+        console.log(err)
+      })
+      // wx.getUserProfile({
+  	  // 	desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
+  	  // 	success: (res) => {
+  		// 		Util.getCodeLogin((code)=>{
+  		// 			let userInfo = res;
+  		// 			userInfo.code = code.code;
+  		// 			that.getWxUserInfo(userInfo);
+  		// 		})
+  	  //   }, // success
+  	  // 	fail: (err) => {
+  		// 		wx.hideLoading();
+  	  // 	}
+  	  // });
+    }, //getUserProfile
+    
     //授权
     setUserInfo(userInfo,isLogin) {
       let that = this;
@@ -123,10 +160,13 @@ Component({
         });
       }
     },
+
+    // 从后台获取详细信息
     getWxUserInfo: function (userInfo){
       let that = this;
       userInfo.spread_spid = app.globalData.spid;//获取推广人ID
       userInfo.spread_code = app.globalData.code;//获取推广人分享二维码ID
+      // 发送到后台
       login(userInfo).then(res => {
         app.globalData.token = res.data.token;
         app.globalData.isLog = true;
@@ -153,10 +193,12 @@ Component({
         }
       });
     },
+
+    // 点击打开用户协议
     onTabRegular: function() {
       wx.navigateTo({
         url: `/pages/user_license/license`
       })
-    }
+    } //onTabRegular
   },
 })

+ 1 - 1
view/xcx/components/authorize/authorize.wxml

@@ -10,7 +10,7 @@
       <view class='item' bindtap='close'>随便逛逛</view>
       <!-- 在高版本中获取用户信息已改成uni.getUserProfile-->
 	  <button class='item grant'  type="primary" wx:if="{{canIUseGetUserProfile}}" lang="zh_CN" bindtap="getUserProfile">同意并授权</button>
-	  <button class='item grant'  type="primary" wx:else open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="setUserInfo"> 同意并授权 </button>
+	  <button class='item grant'  type="primary" wx:else open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="setUserInfo">同意并授权</button>
    </view>
 </view>
 <view class='mask' hidden='{{iShidden}}' catchtouchmove="true" bindtap='close'></view>

+ 2 - 1
view/xcx/pages/goods_details/index.js

@@ -815,7 +815,8 @@ Page({
     return {
       title: that.data.storeInfo.store_name || '',
       imageUrl: that.data.storeInfo.image || '',
-      path: '/pages/goods_details/index?id=' + that.data.id + '&spid=' + that.data.uid,
+      path: '/pages/index/index?a=share&id=' + that.data.id + '&spid=' + that.data.uid,
+      //path: '/pages/goods_details/index?id=' + that.data.id + '&spid=' + that.data.uid,
     }
   }
 })

+ 1 - 1
view/xcx/pages/goods_details/index.wxml

@@ -187,7 +187,7 @@
   <action-sheet-item hover-class='none'>
     <button open-type="share" class='contact' hover-class='none'>
       <view class='iconn'></view>
-      发送给朋
+      微信好
     </button>
     <button class='contact' bindtap='goPoster' hover-class='none'>
       <view class='iconn iconn1'></view>

+ 5 - 0
view/xcx/pages/index/index.js

@@ -96,6 +96,11 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    if (options.a && options.a == 'share' && options.id && options.spid) {
+      wx.navigateTo({
+        url: '/pages/goods_details/index?id=' + options.id + '&spid=' + options.spid,
+      })
+    }
     wxh.selfLocation(1);
     this.getCategoryData();
     // this.getCoupon();