mobileclient/libs.js

79 lines
2.3 KiB
JavaScript

/**
* 结算 埋点方法
* @param {string} key
* @param {number} settlementType
*/
const settlementFun = (token, settlementType) => {
let obj_yz_data = JSON.parse(sessionStorage.getItem("bm_auth"));
if (obj_yz_data && obj_yz_data.settlement_data.is_settlement) {
return;
}
let params = {
token,
type: settlementType
};
req.axiosPost("/key/settlement/create", params).then((res) => {
console.log("点 =>", res);
if (res.code === 200) {
// 接口请求成功后,就不能再请求接口了
let obj_sy = JSON.parse(sessionStorage.getItem("bm_auth"));
obj_sy.settlement_data.is_settlement = true;
sessionStorage.setItem("bm_auth", JSON.stringify(obj_sy));
}
});
};
// 兼容IOS 返回
const locationReplace = (url) => {
if (history.replaceState) {
history.replaceState(null, document.title, url);
history.go(0);
} else {
location.replace(url);
}
};
// 获取url参数
const getQueryString = (name) => {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
};
/** 倒计时函数
* @param {*} timestamp
* @returns
*/
const pageOutTime = (timestamp) => {
console.log(1);
if (timestamp || timestamp === "0") {
const now = new Date().getTime(); // 获取当前时间的时间戳
console.log("2", now);
let diff = Number(timestamp) - now; // 计算差异(以毫秒为单位)
console.log("3", diff);
// 判断还剩多久
if (diff <= 0) {
window.location.replace("/outtime.html");
return false;
} else {
// 将差异转换为小时、分钟、秒
const hours = Math.floor(diff / (1000 * 60 * 60));
diff -= hours * (1000 * 60 * 60);
const minutes = Math.floor(diff / (1000 * 60));
diff -= minutes * (1000 * 60);
const seconds = Math.floor(diff / 1000);
const hoursPadded = String(hours).padStart(2, "0");
const minutesPadded = String(minutes).padStart(2, "0");
const secondsPadded = String(seconds).padStart(2, "0");
console.log("hoursPadded", hoursPadded);
console.log("minutesPadded", minutesPadded);
console.log("secondsPadded", secondsPadded);
// 返回结果数组
return [hoursPadded, minutesPadded, secondsPadded];
}
}
};