var lsktl = {
addonVar: {
onoff_on: 1, onoff_off: 2
},
webhost: "https://e.lr12.com",
apiurl: "",
resurl: "",
appid: "",
addon_name: "ktTool",
clientInfo: {bsid: ""},
bsid_client: 0,
init: function () {
lsktl.clientInfo = wx.getSystemInfoSync();
this.apiurl = this.webhost + "/api.php/" + this.addon_name + "/";
this.resurl = this.webhost + "/static/addon/" + this.addon_name + "/";
this.clientInfo.zdinfo = wx.getSystemInfoSync();//得到系统消息
if (!lsktl.cache.get("bsid_client")) {
lsktl.cache.set("bsid_client", lsktl.uuid());
}
},
payinfo: function (order_id, options) {
if (lsktl.empty(lsktl.cache.get("openid"))) {//如果 openid是空的,则
wx.login({
success: function (e) {
if (e.code) {
wx.request({
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
data: {code: e.code},
url: lsktl.apiurl + "pub/wxapp_lginfo",
success: function (ret) {
if (0 == ret.data.errcode) {
if (!lsktl.empty(ret.data.ra.openid)) {
lsktl.cache.set("openid", ret.data.ra.openid);
lsktl.payinfo(order_id, options);//再回调
}
} else {
//即未获取 oenid
}
},
fail: function (res) {
console.info(res);
},
complete: function (res) {
}
});
}
},
fail: function (res) {
me.setData({
st_login: 0
});
},
complete: function (res) {
lsktl.loading.hide();
}
});
} else {
lsktl.loading.show();
lsktl.sendRequest({
url: "order/getpayinfo",
data: {id: order_id, paytype: "minipay", openid: lsktl.cache.get("openid")},
success: function (ret) {
lsktl.loading.hide();
if (ret.data.errcode > 0) {
wx.showToast({title: ret.data.errmsg});
return false;
}
ret.data.payinfo.success = function (ret) {
options.success(ret);
};
ret.data.payinfo.fail = function (ret) {
// options.fail(ret);
};
ret.data.payinfo.complete = function (ret) {
// options.complete || options.complete(ret);
options.complete();
};
wx.requestPayment(ret.data.payinfo);
}
});
}
},
cpage: function () {
return getCurrentPages()[getCurrentPages().length - 1];//当前页
},
empty(p1) {//判断一个对象是否为空
if (p1 == null) {
return true;
}
if (p1 == undefined) {
return true;
}
switch (typeof p1) {
case "undefined":
return true;
break;
case "object":
if (Object.keys(p1).length == 0) {
return true;
} else {
return false;
}
break;
case "number":
return p1 == 0 ? true : false;
break;
case "string":
return lsktl.trim(p1, "") == "" ? true : false;
break;
case "boolean":
return p1;
break;
default:
return true;
break;
}
return true;
},
pageshow: function () {//当面刚开始的时候,初始化一些当前页灵面的数据
var cp = lsktl.cpage();//得到当前页
cp.setData({
islogin: parseInt(lsktl.cache.get("islogin"))
});
},
url: {
format: function (url = "") {
var index = url.indexOf("?");
var options = {};
var route = url;//默认的是这个
var query = "";
if (index > 0) {//即大于
query = url.substr(index + 1);
route = url.substr(0, index);
if (query != "") {
var parts = query.split("&");
var kv;
for (var i = 0; i < parts.length; i++) {
kv = parts[i].split("=");
options[kv[0]] = kv[1];
}
}
}
route = lsktl.trim(route, "/");
var urlpath = "/" + route;
return {route: route, options: options, query: query, urlpath: urlpath};
},
get: function (url = "", key = "") {
var fa = lsktl.url.format(url);
var ra = fa.options[key];
ra = undefined ? 0 : ra;
return ra;
},
set: function (url, params = {}) {
var fa = lsktl.url.format(url);
for (var i in params) {
fa.options[i] = params[i];
}
var querystr = "";
for (var i in fa.options) {
querystr += i + "=" + fa.options[i] + "&";
}
querystr = lsktl.trim(querystr, "&");
var str = fa.urlpath + (querystr == "" ? "" : "?" + querystr);
return str;
}
},
gourl: function (params) {
// return false;
if (typeof params == "string") {//即如果是string
params = {
url: params
};
}
if (params.url.indexOf("pages/site/index") >= 0) {//即首页
wx.reLaunch({
url: "/" + lsktl.trim(params.url, '/')
});
return false;
}
var fa = lsktl.url.format(params.url);
//以上步骤已经得到了要跳转的url的route和options部分
var cpage = lsktl.cpage();//得到当前页面
var pagelist = getCurrentPages();
var init = 0;
var inIndex = -1;
var pagelen = pagelist.length;//得到长度
for (var i = 0; i < pagelen; i++) {
if (lsktl.trim(pagelist[i].route) == fa.route) {//即在里面
init = 1;
inIndex = i;//即所在的索引值
}
}
if (pagelen >= 9) {//如果大于9,则重新启动一下,
wx.reLaunch({
url: params.url
});
return false;//返回false
}
if (lsktl.trim(cpage.route) == fa.route && lsktl.empty(cpage.options) && lsktl.empty(fa.options)) {//相同的,并且没有options
return false;
}
if (init == 1 && lsktl.empty(pagelist[inIndex].options) && lsktl.empty(fa.options)) {//即在里面
wx.navigateBack({
delta: inIndex
});
return false;
}
wx.navigateTo({
url: params.url
});//跳转
},
back: function (delta = 1) {
wx.navigateBack({
delta: delta
});
},
sendRequest: function (params = {}) {
var pagelist = getCurrentPages();
var cpage = pagelist[pagel