JMApp/utils/common.js
2024-03-20 11:39:05 +08:00

86 lines
3.4 KiB
JavaScript

function e(e) {
return [ e.getFullYear(), e.getMonth() + 1, e.getDate() ].map(function(e) {
return e > 9 ? e : "0" + e;
}).join("-");
}
function t(e) {
return e > 9 ? e : "0" + e;
}
module.exports = {
changeTimeyear: function(e) {
return [ e.getFullYear(), "年", e.getMonth() + 1, "月", e.getDate() ].map(function(e, t) {
return e > 9 || t % 2 == 1 ? e : "0" + e;
}).join("");
},
changeTime: e,
changeTimeMD: function(e) {
return [ e.getMonth() + 1, e.getDate() ].join(".");
},
changeTimeDate: function(n) {
var o = new Date(), i = new Date(o.getTime() - 864e5);
return e(o) === e(n) ? "今日 " + [ t(n.getHours()), t(n.getMinutes()) ].join(":") : e(i) === e(n) ? "昨日 " + [ t(n.getHours()), t(n.getMinutes()) ].join(":") : [ n.getMonth() + 1, n.getDate() ].join("月") + " " + [ t(n.getHours()), t(n.getMinutes()) ].join(":");
},
caculateQueryHeight: function(e) {
return new Promise(function(t, n) {
wx.createSelectorQuery().select("." + e).boundingClientRect(function(e) {
console.log(e), t({
width: e.width,
height: e.height,
left: e.left,
right: e.right,
top: e.top,
bottom: e.bottom
});
}).exec();
});
},
confirmAlert: function(e, t) {
return new Promise(function(n, o) {
wx.showModal({
title: t || "提示",
content: e,
cancelColor: "#999999",
confirmColor: "#62C4A3",
success: function(e) {
e.confirm ? n(e) : o();
}
});
});
},
changeNum: t,
changeTimeHoursAgo: function(t) {
var n = new Date(), o = new Date(n.getTime() - 864e5);
if (e(n) === e(t)) {
var i = Math.floor((n.getTime() - t.getTime()) / 36e5);
return 0 == i ? Math.floor((n.getTime() - t.getTime()) / 6e4) + "分钟前" : i + "小时前";
}
return e(o) === e(t) ? "昨天" : n.getFullYear() == t.getFullYear() ? [ t.getMonth() + 1, t.getDate() ].join("月") : [ t.getFullYear(), t.getMonth() + 1, t.getDate() ].join(".");
},
showToast: function(e) {
wx.showToast({
title: e,
icon: "none",
duration: 2e3,
mask: !0
});
},
restTime: function(e) {
var t = 1e3 * e - new Date().getTime();
if (t <= 0) return !1;
var n, o, i, r, a = t / 1e3 / 3600 / 24, u = 24 * (a - (n = Math.floor(a))), g = 60 * (u - (o = Math.floor(u))), c = 60 * (g - (i = Math.floor(g)));
return r = Math.floor(c), {
day: (n + "").padStart(2, "0"),
hour: (o + "").padStart(2, "0"),
minute: (i + "").padStart(2, "0"),
second: (r + "").padStart(2, "0")
};
},
replaceDetail: function(e) {
for (var t = ""; -1 != e.indexOf("<img"); ) t += e.substring("0", e.indexOf("<img") + 4),
-1 != (e = e.substring(e.indexOf("<img") + 4)).indexOf("style=") && e.indexOf("style=") < e.indexOf(">") ? (t += e.substring(0, e.indexOf('style="') + 7) + "max-width:100%;height:auto;margin:0 auto;",
e = e.substring(e.indexOf('style="') + 7)) : t += ' style="max-width:100%;height:auto;margin:0 auto;" ';
return t += e;
}
};