提交 e62ceabd 编写于 作者: G gongfuxiang

微信小程序登录+绑定手机号码

上级 66f7cbe9
......@@ -181,23 +181,6 @@ App({
);
},
/**
* 获取平台用户信息
* object 回调操作对象
* method 回调操作对象的函数
* return 有用户数据直接返回, 则回调调用者
*/
get_user_info(object, method) {
var user = this.get_user_cache_info();
if (user == false) {
// 唤醒用户授权
this.user_auth_code(object, method);
return false;
}
return user;
},
/**
* 从缓存获取用户信息
*/
......@@ -209,50 +192,13 @@ App({
return user;
},
/**
* 用户授权
* object 回调操作对象
* method 回调操作对象的函数
*/
user_auth_code(object, method) {
// 加载loding
wx.showLoading({ title: '授权中...' });
var $this = this;
// 请求授权接口
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userInfo']) {
wx.navigateTo({
url: "/pages/login/login"
});
// wx.authorize({
// scope: 'scope.userInfo',
// success() {
// $this.user_auth_login(object, method);
// },
// fail: (e) => {
// wx.hideLoading();
// $this.showToast('授权失败');
// }
// });
} else {
$this.user_auth_login(object, method);
}
},
fail: (e) => {
wx.hideLoading();
$this.showToast('授权校验失败');
}
});
},
/**
* 用户登录
* object 回调操作对象
* method 回调操作对象的函数
*/
user_auth_login(object, method) {
wx.showLoading({ title: "授权中..." });
var $this = this;
wx.checkSession({
success: function () {
......
......@@ -120,20 +120,20 @@ textarea {
.my-btn-default{
font-size: 38rpx;
color: #fff;
border: none;
background-color:#d2364c;
color: #fff !important;
border: none !important;
background-color:#d2364c !important;
border-radius: 2px;
}
.my-btn-default.btn-disabled{
background-color: #a6a6a6;
color: #fff;
background-color: #a6a6a6 !important;
color: #fff !important;
}
.my-btn-gray{
font-size: 30rpx;
color: #fff;
border: none;
background-color:#a6a6a6;
color: #fff !important;
border: none !important;
background-color:#a6a6a6 !important;
border-radius: 2px;
}
......@@ -240,7 +240,7 @@ textarea {
background-color: #ed6977 !important;
}
.bg-warning {
background-color: #F37B1D !important;
background-color: #F37B1D !important;
}
.bg-active-main {
background-color: #d2364c !important;
......
......@@ -42,7 +42,7 @@
</view>
<!-- 留言 -->
<textarea onInput="bind_user_note_event" maxlength="60" auto-height placeholder="留言" class="spacing-mb" />
<textarea bindinput="bind_user_note_event" maxlength="60" auto-height placeholder="留言" class="spacing-mb" />
<!-- 扩展数据展示 -->
<view wx:if="{{extension_list.length > 0}}" class="extension-list spacing-mb">
......
......@@ -17,26 +17,24 @@ Page({
},
init(e) {
var user = app.get_user_info(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if ((user.mobile || null) == null) {
wx.showModal({
title: '温馨提示',
content: '绑定手机号码',
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
if (result.confirm) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
}
},
});
} else {
this.get_data();
}
var user = app.get_user_cache_info(this, "init");
// 用户未绑定用户则转到登录页面
if (user == false || ((user.mobile || null) == null)) {
wx.showModal({
title: '温馨提示',
content: '绑定手机号码',
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
if (result.confirm) {
wx.navigateTo({
url: "/pages/login/login?event_callback=init"
});
}
},
});
} else {
this.get_data();
}
},
......@@ -75,10 +73,7 @@ Page({
data_bottom_line_status: false,
data_list_loding_msg: res.data.msg,
});
wx.showToast({
type: "fail",
content: res.data.msg
});
app.showToast(res.data.msg);
}
},
fail: () => {
......@@ -89,10 +84,7 @@ Page({
data_list_loding_msg: '服务器请求出错',
});
wx.showToast({
type: "fail",
content: "服务器请求出错"
});
app.showToast("服务器请求出错");
}
});
},
......@@ -132,18 +124,18 @@ Page({
if (buy_number < buy_min_number) {
buy_number = buy_min_number;
if (buy_min_number > 1) {
wx.showToast({ content: '起购' + buy_min_number + inventory_unit });
app.showToast('起购' + buy_min_number + inventory_unit );
return false;
}
}
if (buy_max_number > 0 && buy_number > buy_max_number) {
buy_number = buy_max_number;
wx.showToast({ content: '限购' + buy_max_number + inventory_unit });
app.showToast('限购' + buy_max_number + inventory_unit );
return false;
}
if (buy_number > inventory) {
buy_number = inventory;
wx.showToast({ content: '库存数量' + inventory + inventory_unit });
app.showToast( '库存数量' + inventory + inventory_unit );
return false;
}
......@@ -167,17 +159,11 @@ Page({
// 选择处理
this.selected_calculate();
} else {
wx.showToast({
type: "fail",
content: res.data.msg
});
app.showToast(res.data.msg);
}
},
fail: () => {
wx.showToast({
type: "fail",
content: "服务器请求出错"
});
app.showToast("服务器请求出错");
}
});
},
......@@ -225,17 +211,11 @@ Page({
if (res.data.code == 0) {
this.cart_delete(id, type);
} else {
wx.showToast({
type: 'fail',
content: res.data.msg
});
app.showToast(res.data.msg);
}
},
fail: () => {
wx.showToast({
type: 'fail',
content: '服务器请求出错'
});
app.showToast("服务器请求出错");
}
});
},
......@@ -257,22 +237,13 @@ Page({
data_list_loding_status: temp_data_list.length == 0 ? 0 : this.data.data_list_loding_status,
});
wx.showToast({
type: 'success',
content: (type == 'delete') ? '删除成功' : '收藏成功'
});
app.showToast(((type == 'delete') ? '删除成功' : '收藏成功'), 'success');
} else {
wx.showToast({
type: 'fail',
content: (type == 'delete') ? '删除失败' : '收藏失败'
});
app.showToast((type == 'delete') ? '删除失败' : '收藏失败');
}
},
fail: () => {
wx.showToast({
type: 'fail',
content: '服务器请求出错'
});
app.showToast("服务器请求出错");
}
});
},
......@@ -342,10 +313,7 @@ Page({
}
if (selected_count <= 0) {
wx.showToast({
type: "fail",
content: '请选择商品'
});
app.showToast("请选择商品");
return false
}
......
......@@ -23,7 +23,7 @@
<!-- 数量 -->
<view class="number-content tc oh">
<view bindtap="goods_buy_number_event" class="number-submit tc cr-888 fl" data-index="{{index}}" data-type="0">-</view>
<input onBlur="goods_buy_number_blur" class="tc cr-888 fl" type="number" value="{{item.stock}}" data-index="{{index}}" />
<input bindblur="goods_buy_number_blur" class="tc cr-888 fl" type="number" value="{{item.stock}}" data-index="{{index}}" />
<view bindtap="goods_buy_number_event" class="number-submit tc cr-888 fl" data-index="{{index}}" data-type="1">+</view>
</view>
......
......@@ -121,7 +121,7 @@
<view class="title fl">购买数量</view>
<view class="number-content tc oh">
<view bindtap="goods_buy_number_event" class="number-submit tc cr-888 fl" data-type="0">-</view>
<input onBlur="goods_buy_number_blur" class="tc cr-888 fl" type="number" value="{{temp_buy_number}}" />
<input bindblur="goods_buy_number_blur" class="tc cr-888 fl" type="number" value="{{temp_buy_number}}" />
<view bindtap="goods_buy_number_event" class="number-submit tc cr-888 fl" data-type="1">+</view>
</view>
</view>
......
......@@ -30,9 +30,38 @@ Page({
* 登录授权事件
*/
get_user_info_event(e) {
console.log(e, e.detail.userInfo);
//app.user_auth_login();
wx.navigateBack();
this.user_auth_code();
},
/**
* 用户授权
* object 回调操作对象
* method 回调操作对象的函数
*/
user_auth_code(object, method) {
// 请求授权接口
var $this = this;
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userInfo']) {
$this.setData({ user: null});
} else {
app.user_auth_login($this, 'user_auth_back_event');
}
},
fail: (e) => {
app.showToast("授权校验失败");
}
});
},
/**
* 授权返回事件
*/
user_auth_back_event() {
this.setData({
user: app.get_user_cache_info() || null
});
},
/**
......@@ -83,20 +112,14 @@ Page({
} else {
this.setData({verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false});
wx.showToast({
type: 'fail',
content: res.data.msg
});
app.showToast(res.data.msg);
}
},
fail: () => {
wx.hideLoading();
this.setData({verify_submit_text: '获取验证码', verify_loading: false, verify_disabled: false});
wx.showToast({
type: 'fail',
content: '服务器请求出错'
});
app.showToast("服务器请求出错");
}
});
}
......@@ -111,16 +134,16 @@ Page({
var validation = [
{fields: 'mobile', msg: '请填写手机号码'},
{fields: 'verify', msg: '请填写验证码'},
{fields: 'alipay_openid', msg: '授权id不能为空'}
{fields: 'weixin_openid', msg: '授权id不能为空'}
];
e.detail.value['alipay_openid'] = this.data.user.alipay_openid;
e.detail.value['weixin_openid'] = this.data.user.weixin_openid;
e.detail.value['nickname'] = this.data.user.nickname;
e.detail.value['avatar'] = this.data.user.avatar;
e.detail.value['province'] = this.data.user.province;
e.detail.value['city'] = this.data.user.city;
e.detail.value['gender'] = this.data.user.gender;
e.detail.value['referrer'] = this.data.user.referrer;
e.detail.value['app_type'] = 'alipay';
e.detail.value['app_type'] = 'weixin';
if(app.fields_check(e.detail.value, validation))
{
wx.showLoading({content: '处理中...'});
......@@ -139,10 +162,7 @@ Page({
if(res.data.code == 0 && (res.data.data || null) != null)
{
clearInterval(this.data.temp_clear_time);
wx.showToast({
type: 'success',
content: res.data.msg
});
app.showToast(res.data.msg, 'success');
wx.setStorage({
key: app.data.cache_user_info_key,
......@@ -162,20 +182,14 @@ Page({
} else {
this.setData({form_submit_loading: false});
wx.showToast({
type: 'fail',
content: res.data.msg
});
app.showToast(res.data.msg);
}
},
fail: () => {
wx.hideLoading();
this.setData({form_submit_loading: false});
wx.showToast({
type: 'fail',
content: '服务器请求出错'
});
app.showToast("服务器请求出错");
}
});
}
......
<view wx:if="{{user != null}}" class="content">
<form bindsubmit="formSubmit">
<input type="number" placeholder="输入手机号码" maxlength="11" name="mobile" onInput="bind_key_input" class="mobile" />
<input type="number" placeholder="输入手机号码" maxlength="11" name="mobile" bindinput="bind_key_input" class="mobile" />
<view class="code clearfix">
<input type="number" placeholder="验证码" maxlength="6" name="verify" class="verify" />
<button type="default" hover-class="none" size="mini" loading="{{verify_loading}}" disabled="{{verify_disabled}}" bindtap="verify_send" class="verify-sub fr {{verify_disabled ? 'sub-disabled' : ''}}">{{verify_submit_text}}</button>
<button type="default" hover-class="none" size="mini" loading="{{verify_loading}}" disabled="{{verify_disabled}}" bindtap="verify_send" class="verify-sub {{verify_disabled ? 'sub-disabled' : ''}}">{{verify_submit_text}}</button>
</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>
......
......@@ -23,6 +23,7 @@ page{
.content .code{
margin: 20rpx 0;
border-bottom: solid 1px #eee;
position: relative;
}
.content .code .verify{
width: 63%;
......@@ -34,6 +35,9 @@ page{
height: 35px;
line-height: 35px;
border-radius: 10rpx;
position: absolute;
top: 0;
right: 0;
}
.content .code .verify-sub.sub-disabled{
border: solid 1px #eee;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册