浏览代码

update template/xcx/components/authorize/authorize.js.
修改小程序授权获取用户信息

吴昊天 4 年之前
父节点
当前提交
155a8b822e
共有 1 个文件被更改,包括 25 次插入1 次删除
  1. 25 1
      template/xcx/components/authorize/authorize.js

+ 25 - 1
template/xcx/components/authorize/authorize.js

@@ -25,11 +25,17 @@ Component({
     cloneIner: null,
     loading:false,
     errorSum:0,
-    errorNum:3
+    errorNum:3,
+	canIUseGetUserProfile: false // 判断是否为最新获取用户信息函数
   },
   attached() {
     this.get_logo_url();
     this.setAuthStatus();
+	if (wx.getUserProfile) {
+	      this.setData({
+	        canIUseGetUserProfile: true
+	      })
+	    }
   },
   methods: {
     close(){
@@ -82,6 +88,24 @@ Component({
         }
       })
     },
+    // 获取用户信息
+  	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();
+  	  		  }
+  	  });
+  	},	
     //授权
     setUserInfo(userInfo,isLogin) {
       let that = this;