提交 7b4b9de3 编写于 作者: D devil_gong

微信/支付宝小程序优化

上级 947a852f
...@@ -220,6 +220,22 @@ App({ ...@@ -220,6 +220,22 @@ App({
return user.data; return user.data;
}, },
/**
* 用户登录
* object 回调操作对象
* method 回调操作对象的函数
* auth_data 授权数据
*/
user_auth_login(object, method, auth_data) {
var openid = my.getStorageSync({key: this.data.cache_user_login_key});
if ((openid.data || null) == null)
{
this.user_login(object, method);
} else {
this.get_user_login_info(object, method, openid.data, auth_data);
}
},
/** /**
* 用户授权 * 用户授权
* object 回调操作对象 * object 回调操作对象
...@@ -309,22 +325,6 @@ App({ ...@@ -309,22 +325,6 @@ App({
}); });
}, },
/**
* 用户登录
* object 回调操作对象
* method 回调操作对象的函数
* auth_data 授权数据
*/
user_auth_login(object, method, auth_data) {
var openid = my.getStorageSync({key: this.data.cache_user_login_key});
if ((openid.data || null) == null)
{
this.user_login(object, method);
} else {
this.get_user_login_info(object, method, openid.data, auth_data);
}
},
/** /**
* 获取用户授权信息 * 获取用户授权信息
* object 回调操作对象 * object 回调操作对象
......
...@@ -6,6 +6,10 @@ Page({ ...@@ -6,6 +6,10 @@ Page({
data_list_loding_msg: '', data_list_loding_msg: '',
data_list: [], data_list: [],
data_base: null, data_base: null,
// 优惠劵领取
temp_coupon_receive_index: null,
temp_coupon_receive_value: null,
}, },
onLoad(params) { onLoad(params) {
...@@ -82,45 +86,59 @@ Page({ ...@@ -82,45 +86,59 @@ Page({
// 优惠劵领取事件 // 优惠劵领取事件
coupon_receive_event(e) { coupon_receive_event(e) {
var user = app.get_user_info(this, "coupon_receive_event"); // 参数处理
// 用户未绑定用户则转到登录页面 if((e || null) == null)
if (app.user_is_need_login(user)) { {
my.redirectTo({ var index = this.data.temp_coupon_receive_index;
url: "/pages/login/login?event_callback=coupon_receive_event" var value = this.data.temp_coupon_receive_value;
});
return false;
} else { } else {
var self = this;
var index = e.currentTarget.dataset.index; var index = e.currentTarget.dataset.index;
var value = e.currentTarget.dataset.value; var value = e.currentTarget.dataset.value;
var temp_list = this.data.data_list; this.setData({temp_coupon_receive_index: index, temp_coupon_receive_value: value});
if (temp_list[index]['is_operable'] != 0) { }
my.showLoading({ title: "处理中..." });
my.request({ // 登录校验
url: app.get_request_url("receive", "coupon"), var user = app.get_user_info(this, 'coupon_receive_event');
method: "POST", if (user != false) {
data: { "coupon_id": value }, // 用户未绑定用户则转到登录页面
dataType: "json", if (app.user_is_need_login(user)) {
header: { 'content-type': 'application/x-www-form-urlencoded' }, my.navigateTo({
success: res => { url: "/pages/login/login?event_callback=coupon_receive_event"
my.hideLoading(); });
if (res.data.code == 0) { return false;
app.showToast(res.data.msg, "success"); } else {
if (self.data.data_base != null && self.data.data_base.is_repeat_receive != 1) var self = this;
{ var temp_list = this.data.data_list;
temp_list[index]['is_operable'] = 0; if (temp_list[index]['is_operable'] != 0) {
temp_list[index]['is_operable_name'] = '已领取'; my.showLoading({ title: "处理中..." });
self.setData({ data_list: temp_list }); my.request({
url: app.get_request_url("receive", "coupon"),
method: "POST",
data: { "coupon_id": value },
dataType: "json",
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: res => {
my.hideLoading();
if (res.data.code == 0) {
app.showToast(res.data.msg, "success");
if (self.data.data_base != null && self.data.data_base.is_repeat_receive != 1)
{
temp_list[index]['is_operable'] = 0;
temp_list[index]['is_operable_name'] = '已领取';
self.setData({ data_list: temp_list });
}
} else {
if (app.is_login_check(res.data, self, 'coupon_receive_event')) {
app.showToast(res.data.msg);
}
} }
} else { },
app.showToast(res.data.msg); fail: () => {
my.hideLoading();
app.showToast("服务器请求出错");
} }
}, });
fail: () => { }
my.hideLoading();
app.showToast("服务器请求出错");
}
});
} }
} }
}, },
......
...@@ -20,15 +20,22 @@ Page({ ...@@ -20,15 +20,22 @@ Page({
// 初始化 // 初始化
init() { init() {
var user = app.get_user_info(this, "init"); var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面 if (user != false) {
if (app.user_is_need_login(user)) { // 用户未绑定用户则转到登录页面
my.redirectTo({ if (app.user_is_need_login(user)) {
url: "/pages/login/login?event_callback=init" my.redirectTo({
}); url: "/pages/login/login?event_callback=init"
return false; });
return false;
} else {
// 获取数据
this.get_data_list();
}
} else { } else {
// 获取数据 this.setData({
this.get_data_list(); data_list_loding_status: 0,
data_bottom_line_status: false,
});
} }
}, },
......
...@@ -58,6 +58,10 @@ Page({ ...@@ -58,6 +58,10 @@ Page({
// 站点类型 // 站点类型
common_site_type: 0, common_site_type: 0,
customer_service_tel: null, customer_service_tel: null,
// 优惠劵领取
temp_coupon_receive_index: null,
temp_coupon_receive_value: null,
}, },
onLoad(params) { onLoad(params) {
...@@ -772,44 +776,60 @@ Page({ ...@@ -772,44 +776,60 @@ Page({
// 优惠劵领取事件 // 优惠劵领取事件
coupon_receive_event(e) { coupon_receive_event(e) {
var user = app.get_user_info(this, "coupon_receive_event"); // 参数处理
// 用户未绑定用户则转到登录页面 if((e || null) == null)
if (app.user_is_need_login(user)) { {
my.redirectTo({ var index = this.data.temp_coupon_receive_index;
url: "/pages/login/login?event_callback=coupon_receive_event" var value = this.data.temp_coupon_receive_value;
});
return false;
} else { } else {
var self = this;
var index = e.currentTarget.dataset.index; var index = e.currentTarget.dataset.index;
var value = e.currentTarget.dataset.value; var value = e.currentTarget.dataset.value;
var temp_list = this.data.plugins_coupon_data.data; this.setData({temp_coupon_receive_index: index, temp_coupon_receive_value: value});
if (temp_list[index]['is_operable'] != 0) { }
my.showLoading({ title: "处理中..." });
my.request({ // 登录校验
url: app.get_request_url("receive", "coupon"), var user = app.get_user_info(this, 'coupon_receive_event');
method: "POST", if (user != false) {
data: { "coupon_id": value }, // 用户未绑定用户则转到登录页面
dataType: "json", if (app.user_is_need_login(user)) {
header: { 'content-type': 'application/x-www-form-urlencoded' }, my.navigateTo({
success: res => { url: "/pages/login/login?event_callback=coupon_receive_event"
my.hideLoading(); });
if (res.data.code == 0) { return false;
app.showToast(res.data.msg, "success"); } else {
if (self.data.plugins_coupon_data.base != null && self.data.plugins_coupon_data.base.is_repeat_receive != 1) { var self = this;
temp_list[index]['is_operable'] = 0; var index = e.currentTarget.dataset.index;
temp_list[index]['is_operable_name'] = '已领取'; var value = e.currentTarget.dataset.value;
self.setData({ 'plugins_coupon_data.data': temp_list }); var temp_list = this.data.plugins_coupon_data.data;
if (temp_list[index]['is_operable'] != 0) {
my.showLoading({ title: "处理中..." });
my.request({
url: app.get_request_url("receive", "coupon"),
method: "POST",
data: { "coupon_id": value },
dataType: "json",
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: res => {
my.hideLoading();
if (res.data.code == 0) {
app.showToast(res.data.msg, "success");
if (self.data.plugins_coupon_data.base != null && self.data.plugins_coupon_data.base.is_repeat_receive != 1) {
temp_list[index]['is_operable'] = 0;
temp_list[index]['is_operable_name'] = '已领取';
self.setData({ 'plugins_coupon_data.data': temp_list });
}
} else {
if (app.is_login_check(res.data, self, 'coupon_receive_event')) {
app.showToast(res.data.msg);
}
} }
} else { },
app.showToast(res.data.msg); fail: () => {
my.hideLoading();
app.showToast("服务器请求出错");
} }
}, });
fail: () => { }
my.hideLoading();
app.showToast("服务器请求出错");
}
});
} }
} }
}, },
......
...@@ -24,15 +24,22 @@ Page({ ...@@ -24,15 +24,22 @@ Page({
init() { init() {
var user = app.get_user_info(this, "init"); var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面 if (user != false) {
if (app.user_is_need_login(user)) { // 用户未绑定用户则转到登录页面
my.redirectTo({ if (app.user_is_need_login(user)) {
url: "/pages/login/login?event_callback=init" my.redirectTo({
}); url: "/pages/login/login?event_callback=init"
return false; });
return false;
} else {
// 获取数据
this.get_data_list();
}
} else { } else {
// 获取数据 this.setData({
this.get_data_list(); data_list_loding_status: 0,
data_bottom_line_status: false,
});
} }
}, },
......
...@@ -164,7 +164,7 @@ App({ ...@@ -164,7 +164,7 @@ App({
var user = this.get_user_cache_info(); var user = this.get_user_cache_info();
if (user == false) { if (user == false) {
// 唤醒用户授权 // 唤醒用户授权
this.user_auth_login(object, method); this.user_login(object, method);
return false; return false;
} else { } else {
...@@ -187,23 +187,21 @@ App({ ...@@ -187,23 +187,21 @@ App({
* 用户登录 * 用户登录
* object 回调操作对象 * object 回调操作对象
* method 回调操作对象的函数 * method 回调操作对象的函数
* auth_data 授权数据
*/ */
user_auth_login(object, method, auth_data) { user_auth_login(object, method, auth_data) {
wx.showLoading({ title: "授权中..." });
var self = this; var self = this;
wx.checkSession({ wx.checkSession({
success: function () { success: function () {
var openid = wx.getStorageSync(self.data.cache_user_login_key) || null; var openid = wx.getStorageSync(self.data.cache_user_login_key) || null;
if (openid == null) if (openid == null)
{ {
self.user_login(object, method, auth_data); self.user_login(object, method);
} else { } else {
self.get_user_login_info(object, method, openid, auth_data); self.get_user_login_info(object, method, openid, auth_data);
} }
}, },
fail: function () { fail: function () {
self.user_login(object, method, auth_data); self.user_login(object, method);
} }
}); });
}, },
...@@ -214,58 +212,86 @@ App({ ...@@ -214,58 +212,86 @@ App({
* method 回调操作对象的函数 * method 回调操作对象的函数
* auth_data 授权数据 * auth_data 授权数据
*/ */
user_login(object, method, auth_data) { user_login(object, method) {
var self = this; var openid = wx.getStorageSync(this.data.cache_user_login_key) || null;
wx.login({ if (openid == null)
success: (res) => { {
if (res.code) { var self = this;
wx.request({ // 加载loding
url: self.get_request_url('wechatuserauth', 'user'), wx.showLoading({ title: "授权中..." });
method: 'POST',
data: { authcode: res.code }, wx.login({
dataType: 'json', success: (res) => {
header: { 'content-type': 'application/x-www-form-urlencoded' }, if (res.code) {
success: (res) => { wx.request({
if (res.data.code == 0) { url: self.get_request_url('wechatuserauth', 'user'),
var data = res.data.data; method: 'POST',
if ((data.is_alipay_user_exist || 0) == 1) { data: { authcode: res.code },
wx.hideLoading(); dataType: 'json',
wx.setStorage({ header: { 'content-type': 'application/x-www-form-urlencoded' },
key: self.data.cache_user_info_key, success: (res) => {
data: data, wx.hideLoading();
success: (res) => { if (res.data.code == 0) {
if (typeof object === 'object' && (method || null) != null) { var data = res.data.data;
object[method](); if ((data.is_alipay_user_exist || 0) == 1) {
wx.setStorage({
key: self.data.cache_user_info_key,
data: data,
success: (res) => {
if (typeof object === 'object' && (method || null) != null) {
object[method]();
}
},
fail: () => {
self.showToast('用户信息缓存失败');
} }
}, });
fail: () => { } else {
self.showToast('用户信息缓存失败'); wx.setStorage({
} key: self.data.cache_user_login_key,
}); data: data.openid
});
self.login_to_auth();
}
} else { } else {
wx.setStorage({ wx.hideLoading();
key: self.data.cache_user_login_key, self.showToast(res.data.msg);
data: data
});
self.get_user_login_info(object, method, data, auth_data);
} }
} else { },
fail: () => {
wx.hideLoading(); wx.hideLoading();
self.showToast(res.data.msg); self.showToast('服务器请求出错');
} },
}, });
fail: () => { }
wx.hideLoading(); },
self.showToast('服务器请求出错'); fail: (e) => {
}, wx.hideLoading();
}); self.showToast('授权失败');
} }
}, });
fail: (e) => { } else {
wx.hideLoading(); this.login_to_auth();
self.showToast('授权失败'); }
} },
});
/**
* 跳转到登录页面授权
*/
login_to_auth() {
wx.showModal({
title: '温馨提示',
content: '授权用户信息',
confirmText: '确认',
cancelText: '暂不',
success: (result) => {
if (result.confirm) {
wx.navigateTo({
url: "/pages/login/login"
});
}
}
});
}, },
/** /**
...@@ -281,6 +307,7 @@ App({ ...@@ -281,6 +307,7 @@ App({
var referrer = (params == null) ? 0 : (params.referrer || 0); var referrer = (params == null) ? 0 : (params.referrer || 0);
// 远程解密数据 // 远程解密数据
wx.showLoading({ title: "授权中..." });
var self = this; var self = this;
wx.request({ wx.request({
url: self.get_request_url('wechatuserinfo', 'user'), url: self.get_request_url('wechatuserinfo', 'user'),
......
...@@ -6,6 +6,10 @@ Page({ ...@@ -6,6 +6,10 @@ Page({
data_list_loding_msg: '', data_list_loding_msg: '',
data_list: [], data_list: [],
data_base: null, data_base: null,
// 优惠劵领取
temp_coupon_receive_index: null,
temp_coupon_receive_value: null,
}, },
onLoad(params) { onLoad(params) {
...@@ -80,45 +84,59 @@ Page({ ...@@ -80,45 +84,59 @@ Page({
// 优惠劵领取事件 // 优惠劵领取事件
coupon_receive_event(e) { coupon_receive_event(e) {
var user = app.get_user_info(this, "coupon_receive_event"); // 参数处理
// 用户未绑定用户则转到登录页面 if((e || null) == null)
if (app.user_is_need_login(user)) { {
wx.redirectTo({ var index = this.data.temp_coupon_receive_index;
url: "/pages/login/login?event_callback=coupon_receive_event" var value = this.data.temp_coupon_receive_value;
});
return false;
} else { } else {
var self = this;
var index = e.currentTarget.dataset.index; var index = e.currentTarget.dataset.index;
var value = e.currentTarget.dataset.value; var value = e.currentTarget.dataset.value;
var temp_list = this.data.data_list; this.setData({temp_coupon_receive_index: index, temp_coupon_receive_value: value});
if (temp_list[index]['is_operable'] != 0) { }
wx.showLoading({ title: "处理中..." });
wx.request({ // 登录校验
url: app.get_request_url("receive", "coupon"), var user = app.get_user_info(this, 'coupon_receive_event');
method: "POST", if (user != false) {
data: { "coupon_id": value }, // 用户未绑定用户则转到登录页面
dataType: "json", if (app.user_is_need_login(user)) {
header: { 'content-type': 'application/x-www-form-urlencoded' }, wx.navigateTo({
success: res => { url: "/pages/login/login?event_callback=coupon_receive_event"
wx.hideLoading(); });
if (res.data.code == 0) { return false;
app.showToast(res.data.msg, "success"); } else {
if (self.data.data_base != null && self.data.data_base.is_repeat_receive != 1) var self = this;
{ var temp_list = this.data.data_list;
temp_list[index]['is_operable'] = 0; if (temp_list[index]['is_operable'] != 0) {
temp_list[index]['is_operable_name'] = '已领取'; wx.showLoading({ title: "处理中..." });
self.setData({ data_list: temp_list }); wx.request({
url: app.get_request_url("receive", "coupon"),
method: "POST",
data: { "coupon_id": value },
dataType: "json",
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: res => {
wx.hideLoading();
if (res.data.code == 0) {
app.showToast(res.data.msg, "success");
if (self.data.data_base != null && self.data.data_base.is_repeat_receive != 1)
{
temp_list[index]['is_operable'] = 0;
temp_list[index]['is_operable_name'] = '已领取';
self.setData({ data_list: temp_list });
}
} else {
if (app.is_login_check(res.data, self, 'coupon_receive_event')) {
app.showToast(res.data.msg);
}
} }
} else { },
app.showToast(res.data.msg); fail: () => {
wx.hideLoading();
app.showToast("服务器请求出错");
} }
}, });
fail: () => { }
wx.hideLoading();
app.showToast("服务器请求出错");
}
});
} }
} }
}, },
......
...@@ -20,15 +20,22 @@ Page({ ...@@ -20,15 +20,22 @@ Page({
// 初始化 // 初始化
init() { init() {
var user = app.get_user_info(this, "init"); var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面 if (user != false) {
if (app.user_is_need_login(user)) { // 用户未绑定用户则转到登录页面
wx.redirectTo({ if (app.user_is_need_login(user)) {
url: "/pages/login/login?event_callback=init" wx.redirectTo({
}); url: "/pages/login/login?event_callback=init"
return false; });
return false;
} else {
// 获取数据
this.get_data_list();
}
} else { } else {
// 获取数据 this.setData({
this.get_data_list(); data_list_loding_status: 0,
data_bottom_line_status: false,
});
} }
}, },
......
...@@ -69,6 +69,10 @@ Page({ ...@@ -69,6 +69,10 @@ Page({
// 站点模式 // 站点模式
common_site_type: 0, common_site_type: 0,
customer_service_tel: null, customer_service_tel: null,
// 优惠劵领取
temp_coupon_receive_index: null,
temp_coupon_receive_value: null,
}, },
onLoad(params) { onLoad(params) {
...@@ -785,71 +789,31 @@ Page({ ...@@ -785,71 +789,31 @@ Page({
// 商品海报分享 // 商品海报分享
poster_event() { poster_event() {
var user = app.get_user_info(this, 'poster_event'); var user = app.get_user_info(this, 'poster_event');
// 用户未绑定用户则转到登录页面 if (user != false) {
if (app.user_is_need_login(user)) { // 用户未绑定用户则转到登录页面
wx.navigateTo({ if (app.user_is_need_login(user)) {
url: "/pages/login/login?event_callback=init" wx.navigateTo({
}); url: "/pages/login/login?event_callback=poster_event"
return false; });
} else { return false;
wx.showLoading({ title: '生成中...' }); } else {
wx.request({ wx.showLoading({ title: '生成中...' });
url: app.get_request_url('poster', 'goods'),
method: 'POST',
data: { "goods_id": this.data.goods.id },
dataType: 'json',
success: (res) => {
wx.hideLoading();
if (res.data.code == 0) {
wx.previewImage({
current: res.data.data,
urls: [res.data.data]
});
} else {
app.showToast(res.data.msg);
}
},
fail: () => {
wx.hideLoading();
app.showToast("服务器请求出错");
}
});
}
},
// 优惠劵领取事件
coupon_receive_event(e) {
var user = app.get_user_nifo(this, "coupon_receive_event");
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
my.redirectTo({
url: "/pages/login/login?event_callback=coupon_receive_event"
});
return false;
} else {
var self = this;
var index = e.currentTarget.dataset.index;
var value = e.currentTarget.dataset.value;
var temp_list = this.data.plugins_coupon_data.data;
if (temp_list[index]['is_operable'] != 0) {
wx.showLoading({ title: "处理中..." });
wx.request({ wx.request({
url: app.get_request_url("receive", "coupon"), url: app.get_request_url('poster', 'goods'),
method: "POST", method: 'POST',
data: { "coupon_id": value }, data: { "goods_id": this.data.goods.id },
dataType: "json", dataType: 'json',
header: { 'content-type': 'application/x-www-form-urlencoded' }, success: (res) => {
success: res => {
wx.hideLoading(); wx.hideLoading();
if (res.data.code == 0) { if (res.data.code == 0) {
app.showToast(res.data.msg, "success"); wx.previewImage({
if (self.data.plugins_coupon_data.base != null && self.data.plugins_coupon_data.base.is_repeat_receive != 1) { current: res.data.data,
temp_list[index]['is_operable'] = 0; urls: [res.data.data]
temp_list[index]['is_operable_name'] = '已领取'; });
self.setData({ 'plugins_coupon_data.data': temp_list });
}
} else { } else {
app.showToast(res.data.msg); if (app.is_login_check(res.data, this, 'poster_event')) {
app.showToast(res.data.msg);
}
} }
}, },
fail: () => { fail: () => {
...@@ -861,6 +825,64 @@ Page({ ...@@ -861,6 +825,64 @@ Page({
} }
}, },
// 优惠劵领取事件
coupon_receive_event(e) {
// 参数处理
if((e || null) == null)
{
var index = this.data.temp_coupon_receive_index;
var value = this.data.temp_coupon_receive_value;
} else {
var index = e.currentTarget.dataset.index;
var value = e.currentTarget.dataset.value;
this.setData({temp_coupon_receive_index: index, temp_coupon_receive_value: value});
}
// 登录校验
var user = app.get_user_info(this, 'coupon_receive_event');
if (user != false) {
// 用户未绑定用户则转到登录页面
if (app.user_is_need_login(user)) {
wx.navigateTo({
url: "/pages/login/login?event_callback=coupon_receive_event"
});
return false;
} else {
var self = this;
var temp_list = this.data.plugins_coupon_data.data;
if (temp_list[index]['is_operable'] != 0) {
wx.showLoading({ title: "处理中..." });
wx.request({
url: app.get_request_url("receive", "coupon"),
method: "POST",
data: { "coupon_id": value },
dataType: "json",
header: { 'content-type': 'application/x-www-form-urlencoded' },
success: res => {
wx.hideLoading();
if (res.data.code == 0) {
app.showToast(res.data.msg, "success");
if (self.data.plugins_coupon_data.base != null && self.data.plugins_coupon_data.base.is_repeat_receive != 1) {
temp_list[index]['is_operable'] = 0;
temp_list[index]['is_operable_name'] = '已领取';
self.setData({ 'plugins_coupon_data.data': temp_list });
}
} else {
if (app.is_login_check(res.data, self, 'coupon_receive_event')) {
app.showToast(res.data.msg);
}
}
},
fail: () => {
wx.hideLoading();
app.showToast("服务器请求出错");
}
});
}
}
}
},
// 展示型事件 // 展示型事件
exhibition_submit_event(e) { exhibition_submit_event(e) {
app.call_tel(this.data.customer_service_tel); app.call_tel(this.data.customer_service_tel);
......
...@@ -24,15 +24,22 @@ Page({ ...@@ -24,15 +24,22 @@ Page({
init() { init() {
var user = app.get_user_info(this, "init"); var user = app.get_user_info(this, "init");
// 用户未绑定用户则转到登录页面 if (user != false) {
if (app.user_is_need_login(user)) { // 用户未绑定用户则转到登录页面
wx.redirectTo({ if (app.user_is_need_login(user)) {
url: "/pages/login/login?event_callback=init" wx.redirectTo({
}); url: "/pages/login/login?event_callback=init"
return false; });
return false;
} else {
// 获取数据
this.get_data_list();
}
} else { } else {
// 获取数据 this.setData({
this.get_data_list(); data_list_loding_status: 0,
data_bottom_line_status: false,
});
} }
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册