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

微信/支付宝小程序优化

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