JMApp/utils/login.js
2024-03-20 18:16:30 +08:00

116 lines
3.9 KiB
JavaScript

var e = require("../@babel/runtime/helpers/typeof"), o = (require("./common.js"),
null), a = null;
function t() {
return new Promise(function(e, o) {
return wx.login({
success: e,
fail: o
});
});
}
function n(a) {
var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
return wx.showLoading(), new Promise(function(n, c) {
console.log("requestdevicecode", o.globalData.devicecode);
var i = Object.assign({}, {
devicecode: o.globalData.devicecode
}, o.globalData.options, t);
console.log("sendData", a, i), wx.request({
url: a,
data: i,
header: {
"content-type": "application/json",
Accept: "application/json, text/plain",
Cookie: "_miucms_session=" + wx.getStorageSync("_miucms_session"),
token: wx.getStorageSync("session") || ""
},
method: "POST",
success: function(o) {
var t = o.data;
if ("object" != e(t) && null != t) {
t = t.replace("\ufeff", "");
var i = JSON.parse(t);
o.data = i;
}
wx.hideLoading();
var l = o.data;
switch (1 * l.code) {
case 200:
case 888:
n(l);
break;
case 201:
a.indexOf("carwashcoupon/receive") > -1 || wx.showModal({
title: "提示",
content: l.message
}), c(l);
break;
case 404:
wx.showModal({
title: "提示",
content: "未找到当前接口"
}), c(l);
break;
case 401:
var s = getCurrentPages(), r = s[s.length - 1];
console.log(401, a), wx.redirectTo({
url: "/pages/login/login?fromPage=".concat(r.route)
}), c(l);
break;
default:
wx.showModal({
title: "提示",
content: l.message
}), c(l);
}
},
fail: function(e) {
wx.hideLoading(), console.log("reqest error", e), c("fail");
}
});
});
}
function c(e, a) {
console.log("appstart", e), o = a, n("https://jmqf.v0750.com/miniprogram", {
code: e
}, !0).then(function(e) {
var o = e.data;
console.log("总接口", o), a.globalData.user = o.user, wx.setStorageSync("session", o.user.session),
a.globalData.isUserAuthorization = o.user > 0 ? 2 : 1, a.globalData.config = o.config,
a.globalData.servicetel = o.servicetel, a.globalData.canGetData = !0, a.globalData.protocol = o.protocol;
});
}
module.exports = {
initial_url: "https://jmqf.v0750.com/miniprogram",
login: t,
request: n,
pageStart: function(e) {
return new Promise(function(o, t) {
e.globalData.canGetData ? o() : a = setInterval(function() {
e.globalData.canGetData && (clearInterval(a), o());
}, 1e3);
});
},
getLogin: function(e) {
o = e, t().then(function(a) {
console.log("获取用户登录态成功!", a.code), o.globalData.code = a.code, c(a.code, e);
}).catch(function(o) {
c(res.code, e);
});
},
baseUrl: "https://jmqf.v0750.com/",
getDevicecode: function(e, a) {
o = e, n("https://jmqf.v0750.com/miniprogram/identify/reload", a, !0).then(function(e) {
var a = e.data;
console.log("onshow获取到的数据", a), o.globalData.devicecode = a.devicecode || o.globalData.devicecode;
});
}
};