mirror of
https://gitee.com/zongzhige/shopxo.git
synced 2026-06-06 03:56:57 +08:00
百度小程序新增获取手机号码一键登录
This commit is contained in:
@ -70,8 +70,8 @@ App({
|
||||
|
||||
// 请求地址
|
||||
request_url: "{{request_url}}",
|
||||
// request_url: 'http://shopxo.com/',
|
||||
request_url: 'https://dev.shopxo.net/',
|
||||
request_url: 'http://shopxo.com/',
|
||||
// request_url: 'https://dev.shopxo.net/',
|
||||
|
||||
// 基础信息
|
||||
application_title: "{{application_title}}",
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
{
|
||||
"pages": [
|
||||
"pages/login/login",
|
||||
"pages/index/index",
|
||||
"pages/goods-category/goods-category",
|
||||
"pages/cart/cart",
|
||||
"pages/user/user",
|
||||
"pages/web-view/web-view",
|
||||
"pages/login/login",
|
||||
|
||||
"pages/paytips/paytips",
|
||||
"pages/goods-search/goods-search",
|
||||
"pages/goods-detail/goods-detail",
|
||||
|
||||
@ -17,7 +17,7 @@ page{
|
||||
.content input{
|
||||
font-size: 28rpx;
|
||||
color: #4e4e4e;
|
||||
height: 40px;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
}
|
||||
.content .code{
|
||||
@ -26,13 +26,13 @@ page{
|
||||
position: relative;
|
||||
}
|
||||
.content .code .verify{
|
||||
width: 63%;
|
||||
width: 63%;
|
||||
}
|
||||
.content .code .verify-sub{
|
||||
border: solid 1px #ff6482;
|
||||
border: solid 1px #ff6482;
|
||||
color: #ff6482;
|
||||
width: 35%;
|
||||
height: 35px;
|
||||
height: 35px;
|
||||
line-height: 35px;
|
||||
border-radius: 10rpx;
|
||||
position: absolute;
|
||||
@ -40,7 +40,7 @@ page{
|
||||
right: 0;
|
||||
}
|
||||
.content .code .verify-sub.sub-disabled{
|
||||
border: solid 1px #eee;
|
||||
border: solid 1px #eee;
|
||||
color: #a6a6a6
|
||||
}
|
||||
.content .submit{
|
||||
@ -60,4 +60,19 @@ page{
|
||||
}
|
||||
.user-login button {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录确认
|
||||
*/
|
||||
.login-logo {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.submit-list {
|
||||
margin-top: 100rpx;
|
||||
}
|
||||
.submit-list button:not(:last-child) {
|
||||
margin-bottom: 40rpx;
|
||||
}
|
||||
@ -9,7 +9,9 @@ Page({
|
||||
verify_disabled: false,
|
||||
form_submit_loading: false,
|
||||
verify_time_total: 60,
|
||||
temp_clear_time: null
|
||||
temp_clear_time: null,
|
||||
// 0确认页面, 1验证码绑定, 2一键获取绑定
|
||||
login_status: 2,
|
||||
},
|
||||
|
||||
/**
|
||||
@ -97,14 +99,12 @@ Page({
|
||||
}, 1000);
|
||||
} else {
|
||||
this.setData({ verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false });
|
||||
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
swan.hideLoading();
|
||||
this.setData({ verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false });
|
||||
|
||||
app.showToast("服务器请求出错");
|
||||
}
|
||||
});
|
||||
@ -161,18 +161,80 @@ Page({
|
||||
}, 1000);
|
||||
} else {
|
||||
this.setData({ form_submit_loading: false });
|
||||
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
swan.hideLoading();
|
||||
this.setData({ form_submit_loading: false });
|
||||
|
||||
app.showToast("服务器请求出错");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 获取手机号码一键登录
|
||||
confirm_phone_number_event(e) {
|
||||
var encrypted_data = e.detail.encryptedData || null;
|
||||
var iv = e.detail.iv || null;
|
||||
if(encrypted_data != null && iv != null) {
|
||||
// 邀请人参数
|
||||
var params = swan.getStorageSync(this.data.cache_launch_info_key) || null;
|
||||
var referrer = (params == null) ? 0 : (params.referrer || 0);
|
||||
|
||||
// 解密数据并绑定手机
|
||||
var data = {
|
||||
"encrypted_data": encrypted_data,
|
||||
"iv": iv,
|
||||
"openid": this.data.user.baidu_openid,
|
||||
"nickname": this.data.user.nickname,
|
||||
"avatar": this.data.user.avatar,
|
||||
"province": this.data.user.province,
|
||||
"city": this.data.user.city,
|
||||
"gender": this.data.user.gender,
|
||||
"referrer": referrer
|
||||
};
|
||||
swan.showLoading({ title: "处理中..." });
|
||||
var self = this;
|
||||
swan.request({
|
||||
url: app.get_request_url('baiduusermobilebind', 'user'),
|
||||
method: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
header: { 'content-type': 'application/x-www-form-urlencoded' },
|
||||
success: (res) => {
|
||||
swan.hideLoading();
|
||||
if (res.data.code == 0 && (res.data.data || null) != null) {
|
||||
app.showToast(res.data.msg, 'success');
|
||||
|
||||
swan.setStorage({
|
||||
key: app.data.cache_user_info_key,
|
||||
data: res.data.data
|
||||
});
|
||||
|
||||
var event_callback = this.data.params.event_callback || null;
|
||||
setTimeout(function () {
|
||||
// 触发回调函数
|
||||
if (event_callback != null) {
|
||||
getCurrentPages()[getCurrentPages().length - 2][event_callback]();
|
||||
}
|
||||
swan.navigateBack();
|
||||
}, 1000);
|
||||
} else {
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
swan.hideLoading();
|
||||
self.showToast('服务器请求出错');
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 确认使用验证码
|
||||
confirm_verify_event(e) {
|
||||
this.setData({login_status: 1});
|
||||
},
|
||||
|
||||
});
|
||||
@ -1,5 +1,6 @@
|
||||
<view s-if="user != null" class="content">
|
||||
<form bindsubmit="formSubmit">
|
||||
<!-- 表单验证码 -->
|
||||
<form s-if="login_status == 1" bindsubmit="formSubmit">
|
||||
<input type="number" placeholder="输入手机号码" maxlength="11" name="mobile" bindinput="bind_key_input" class="mobile" />
|
||||
<view class="code clearfix">
|
||||
<input type="number" placeholder="验证码" maxlength="4" name="verify" class="verify" />
|
||||
@ -7,8 +8,18 @@
|
||||
</view>
|
||||
<button type="default" formType="submit" hover-class="none" plain loading="{{form_submit_loading}}" disabled="{{form_submit_loading}}" class="submit {{form_submit_loading ? 'my-btn-gray' : 'my-btn-default'}}">确认绑定</button>
|
||||
</form>
|
||||
|
||||
<!-- 确认授权方式 -->
|
||||
<view s-if="login_status == 2" class="tc">
|
||||
<image class="login-logo" src="/images/user-nav-customer-service-icon.png" mode="widthFix" />
|
||||
<view class="submit-list">
|
||||
<button type="warn" class="mobile-submit" open-type="getPhoneNumber" bindgetphonenumber="confirm_phone_number_event">获取手机号码一键登录</button>
|
||||
<button type="warn" class="mobile-submit" plain="{{true}}" bindtap="confirm_verify_event">验证码登录</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 获取用户信息授权 -->
|
||||
<view s-if="user == null" class="user-login tc">
|
||||
<view class="cr-888 fs-12">确认登录授权,为您提供更优质的服务</view>
|
||||
<button type="primary" size="mini" open-type="getUserInfo" bindgetuserinfo="get_user_info_event">授权登录</button>
|
||||
|
||||
Reference in New Issue
Block a user