头条小程序支持一键获取手机号码登录

master
gongfuxiang 2022-08-02 23:23:30 +08:00
parent bea63fcf6d
commit 12c5bbad1a
2 changed files with 90 additions and 72 deletions

19
App.vue
View File

@ -318,6 +318,20 @@
user_login(object, method) { user_login(object, method) {
var login_data = uni.getStorageSync(this.data.cache_user_login_key) || null; var login_data = uni.getStorageSync(this.data.cache_user_login_key) || null;
if (login_data == null) { if (login_data == null) {
this.user_login_handle(object, method, true);
} else {
this.login_to_auth();
}
},
/**
* 用户登录处理
* object 回调操作对象
* method 回调操作对象的函数
* auth_data 授权数据
* is_to_auth 是否进入授权
*/
user_login_handle(object, method, is_to_auth = true) {
var self = this; var self = this;
uni.showLoading({ uni.showLoading({
title: "授权中..." title: "授权中..."
@ -358,8 +372,10 @@
key: self.data.cache_user_login_key, key: self.data.cache_user_login_key,
data: data data: data
}); });
if(is_to_auth) {
self.login_to_auth(); self.login_to_auth();
} }
}
} else { } else {
uni.hideLoading(); uni.hideLoading();
self.showToast(res.data.msg); self.showToast(res.data.msg);
@ -377,9 +393,6 @@
self.showToast('授权失败'); self.showToast('授权失败');
} }
}); });
} else {
this.login_to_auth();
}
}, },
/** /**

View File

@ -555,17 +555,17 @@
this.user_auth_code(userinfo); this.user_auth_code(userinfo);
// #endif // #endif
// #ifdef MP-TOUTIAO // #ifdef MP-TOUTIAO
if(e == 1) { uni.getUserProfile({
var self = this; force: true,
uni.getUserInfo({ success: (res) => {
success (res) { // getUserProfilelogin
var userinfo = JSON.parse(res.rawData); // login
self.user_auth_code(userinfo); // sessionKey
app.globalData.user_login_handle(null, null, false);
//
this.user_auth_code(res.userInfo);
} }
}); });
} else {
app.globalData.auth_check(this, 'get_user_info_event', 'scope.userInfo');
}
// #endif // #endif
// #ifdef MP-KUAISHOU // #ifdef MP-KUAISHOU
var userinfo = e.target.userInfo; var userinfo = e.target.userInfo;
@ -573,7 +573,7 @@
// #endif // #endif
}, },
// //
// auth_data // auth_data
user_auth_code(auth_data) { user_auth_code(auth_data) {
if ((auth_data || null) != null) { if ((auth_data || null) != null) {
@ -876,9 +876,14 @@
}, },
fail: () => { fail: () => {
uni.hideLoading(); uni.hideLoading();
self.showToast('服务器请求出错'); app.globalData.showToast('服务器请求出错');
} }
}); });
} else {
var msg = e.errmsg || e.errMsg || e.detail.errmsg || e.detail.errMsg || null;
if(msg != null) {
app.globalData.showToast(msg);
}
} }
}, },