|
|
@@ -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
|
|
|
},
|
|
|
})
|