wpfw_ewei_wxapp/app.js
2023-02-26 08:10:18 +08:00

196 lines
7.1 KiB
JavaScript

var e = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/typeof")), t = require("utils/core.js");
App({
onShow: function(i) {
var r = this;
1007 != i.scene && 1008 != i.scene && 1044 != i.scene || void 0 !== a && a.getShareParams().then(function(a) {
var i = r.getCache("usermid");
if ("object" != (0, e.default)(i) && null != i && "" != i) {
var n = {};
n.mid = a.custom_params, r.url(n), r.setCache("usermid", n), wx.setStorageSync("livemid", a.custom_params);
}
"object" == (0, e.default)(i) && "" != a.custom_params && null != a.custom_params && (i.mid = a.custom_params,
r.url(i), r.setCache("usermid", i), wx.setStorageSync("livemid", a.custom_params)),
"" != i && null != i || ((i = {}).mid = 0);
var o = r;
if (i.mid < 1) {
var s = a.share_openid;
t.post("member/get_member", {
shar_openid: s
}, function(e) {
i.mid = e.member.id, o.setCache("usermid", i);
}, !0, !0);
}
}).catch(function(e) {
console.log("get share params", e);
});
var n = this;
this.onLaunch();
try {
"" != this.getCache("userinfo_id") && t.get("member", {}, function(e) {
n.setCache("userinfo_id", e.id);
});
} catch (e) {}
},
onLaunch: function() {
var e = this;
wx.getSystemInfo({
success: function(t) {
"0" == t.model.indexOf("iPhone X") ? e.setCache("isIpx", t.model) : e.setCache("isIpx", "");
}
});
var t = this;
wx.getSystemInfo({
success: function(e) {
wx.setStorageSync("systemInfo", e);
var a = e.windowWidth, i = e.windowHeight;
t.globalData.ww = a, t.globalData.hh = i;
}
}), setTimeout(function() {
t.scanCarts();
}, 50);
},
scanCarts: function() {
var e = this;
t.get("member/cart/get_cart", {}, function(t) {
if (e.getCache("userinfo_openid")) {
var a = 0, i = t.merch_list;
if (void 0 === i) {
i = t.list;
for (var r = 0; r < i.length; r++) a += parseInt(i[r].total);
} else if (null != i) for (var n = 0; n < i.length; n++) for (var o = i[n].list, s = 0; s < o.length; s++) a += parseInt(o[s].total);
var c = e.globalData.tabnum;
0 != a && "" != c ? wx.setTabBarBadge({
index: c,
text: "" + a
}) : wx.removeTabBarBadge({
index: c
});
}
});
},
checkAuth: function(e, a) {
var i = "/pages/auth/index", r = getCurrentPages(), n = r[r.length - 1];
if (console.log(n), "pages/auth/index" == n.route || "/pages/auth/index" == n.route) return !0;
var o = {
params: n.options || null,
url: n.route
};
if (o.params.hasOwnProperty("scene")) {
var s = {}, c = decodeURIComponent(o.params.scene).split("&").shift().split("=");
s.id = c[1], o.params = s;
}
this.setCache("routeData", o);
var u = this.getCache("userinfo");
u && "1" != a ? t.get("member", {}, function(e) {
e.error && wx.navigateTo({
url: i
});
}) : u || "1" != a || wx.navigateTo({
url: i
}), e && e();
},
requirejs: function(e) {
return require("utils/" + e + ".js");
},
getConfig: function() {
if (null !== this.globalData.api) return {
api: this.globalData.api,
approot: this.globalData.approot,
appid: this.globalData.appid
};
var e = wx.getExtConfigSync();
return this.globalData.api = e.config.api, this.globalData.approot = e.config.approot,
this.globalData.appid = e.config.appid, e.config;
},
getCache: function(e, t) {
var a = +new Date() / 1e3, i = "";
a = parseInt(a);
try {
(i = wx.getStorageSync(e + this.globalData.appid)).expire > a || 0 == i.expire ? i = i.value : (i = "",
this.removeCache(e));
} catch (e) {
i = void 0 === t ? "" : t;
}
return i = i || "";
},
setCache: function(e, t, a) {
var i = +new Date() / 1e3, r = !0, n = {
expire: a ? i + parseInt(a) : 0,
value: t
};
try {
wx.setStorageSync(e + this.globalData.appid, n);
} catch (e) {
r = !1;
}
return r;
},
removeCache: function(e) {
var t = !0;
try {
wx.removeStorageSync(e + this.globalData.appid);
} catch (e) {
t = !1;
}
return t;
},
close: function() {
this.globalDataClose.flag = !0, wx.reLaunch({
url: "/pages/index/index"
});
},
getSet: function() {
var e = this;
"" == e.getCache("cacheset") && setTimeout(function() {
var a = e.getCache("cacheset");
t.get("cacheset", {
version: a.version
}, function(t) {
t.update && e.setCache("cacheset", t.data);
});
}, 10);
},
url: function(e) {
e = e || {};
var t, a, i = {}, r = this.getCache("usermid");
t = e.mid || "", a = e.merchid || "";
var n = e.mid || r.mid || "";
for (var o in r) void 0 !== r[o] && (i[o] = r[o]);
i.mid = "number" == typeof t && t > 0 ? t : r.mid, i.mid = t, "" != r ? ("" != r.merchid && void 0 !== r.merchid || (i.merchid = a),
i.mid = n) : (i.mid = n, i.merchid = a), this.setCache("usermid", i);
},
impower: function(e, t, a) {
wx.getSetting({
success: function(i) {
i.authSetting["scope." + e] || wx.showModal({
title: "用户未授权",
content: "您点击了拒绝授权,暂时无法" + t + ",点击去设置可重新获取授权喔~",
confirmText: "去设置",
success: function(e) {
e.confirm ? wx.openSetting({
success: function(e) {}
}) : "route" == a ? wx.switchTab({
url: "/pages/index/index"
}) : "details" == a || wx.navigateTo({
url: "/pages/index/index"
});
}
});
}
});
},
globalDataClose: {
flag: !1
},
globalData: {
appid: "wxcef6b3319f9c3b5e",
api: "http://we2.cnp5.cn/app/ewei_shopv2_api.php?i=1",
approot: "http://we2.cnp5.cn/addons/ewei_shopv2/",
userInfo: null,
isgoods: false,
tabnum: 2
}
});
// 播播资源网 www.ttbobo.com