(function() { window.tools = { // 判断对象数组中指定属性是否有某个值的数据 objArrHasValue(objArr, key, value) { return objArr.find(obj => obj[key] === value) !== undefined; }, // 获取对象数组中指定属性为指定值的对象 objArrGetObjByValue(objArr, key, value) { return objArr.find(obj => obj[key] === value); }, // 对url追加项目版本号,用于页面更新后用户端的强制刷新 urlAddVer(url) { let newUrl = url; // Mock version for H5 const version_number = '1.0.0'; if (newUrl.indexOf('_v=') !== -1) { return newUrl; } if (newUrl.indexOf('?') !== -1) { newUrl += "&_v=" + version_number; } else { newUrl += "?_v=" + version_number; } console.log("[urlAddVer] newUrl", newUrl); return newUrl; }, // 导航到彩图奔跑APP内的某个页面或执行APP内部的某些功能 appAction(url, actType = "") { console.log("appAction", url); // Safe guard for getApp audio try { if(window.getApp && window.getApp().$audio) { window.getApp().$audio.destroy(); window.getApp().$audio.pause(); } } catch(e) {} if (url.indexOf('http') !== -1) { // http 或 https 开头的网址 window.location.href = this.urlAddVer(url); } else if (url == "reload") { window.location.reload(); } else if (actType == "uni.navigateTo") { uni.navigateTo({ url: this.urlAddVer(url) }); } else { // Native bridge simulation or actual call if(window.appAction) { window.appAction(url); } else { window.location.href = url; } } }, // 格式化赛事时间 09-09 16:48 fmtMcTime(timestamp) { var date = new Date(timestamp * 1000); var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' '; var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'; var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()); const timeStr = M + D + h + m; return timeStr; }, // 获取活动时间 09-09 16:48 至 09-30 16:48 getActtime(beginSecond, endSecond) { const acttime = this.fmtMcTime(beginSecond) + " 至 " + this.fmtMcTime(endSecond); return acttime; }, // 格式化赛事时间 2024.9.9-30 2024.9.9-10.30 2024.9.9-2025.10.30 fmtMcTime2(timestamp1, timestamp2) { const date1 = new Date(timestamp1 * 1000); const date2 = new Date(timestamp2 * 1000); const Y1 = date1.getFullYear(); const Y2 = date2.getFullYear(); const M1 = date1.getMonth() + 1; const M2 = date2.getMonth() + 1; const D1 = date1.getDate(); const D2 = date2.getDate(); var timeStr1 = Y1 + '.' + M1 + '.' + D1; var timeStr2 = ''; if (Y2 != Y1) { timeStr2 += Y2 + '.' + M2 + '.' + D2; } else if (M2 != M1) { timeStr2 += M2 + '.' + D2; } else if (D2 != D1) { timeStr2 += D2; } var timeStr = timeStr1; if (timeStr2.length > 0) { timeStr += '-' + timeStr2; } return timeStr; }, // 判断赛事/活动状态 0: 未开始 1: 进行中 2: 已结束 checkMcState(beginSecond, endSecond) { let mcState = 0; // 未开始 if (beginSecond > 0 && endSecond > 0) { const now = Date.now() / 1000; const dif1 = beginSecond - now; const dif2 = endSecond - now; if (dif1 > 0) { mcState = 0; // 未开始 } else if (dif2 > 0) { mcState = 1; // 进行中 } else { mcState = 2; // 已结束 } } return mcState; }, // 动态创建