var tools = { // 对url追加项目版本号,用于页面更新后用户端的强制刷新 // 每次页面变更必须更新项目版本号 urlAddVer(url) { let newUrl = url; // 获取当前app的版本 const systemInfo = uni.getSystemInfoSync(); // #ifdef H5 const version_number = systemInfo.appVersion; // console.log('版本号:', version_number); if (newUrl.indexOf('_v=') !== -1) { return newUrl; } if (newUrl.indexOf('?') !== -1) { newUrl += "&_v=" + version_number; } else { newUrl += "?_v=" + version_number; } // #endif console.log("[urlAddVer] newUrl", newUrl); return newUrl; }, // 导航到彩图奔跑APP内的某个页面或执行APP内部的某些功能 appAction(url, actType="") { console.log("appAction", url); // console.log("getApp", getApp()); // getApp().$audio.destroy(); // getApp().$audio.pause(); 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 if (actType == "uni.switchTab") { uni.switchTab({ url: this.urlAddVer(url) }); } else { window.location.href = url; } }, // 格式化赛事时间 09-09 16:48 fmtMcTime(timestamp) { var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 // var Y = date.getFullYear() + '-'; 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()); // var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()); const timeStr = M + D + h + m; // console.log("timeStr", timeStr); return timeStr; }, // 获取活动时间 09-09 16:48 至 09-30 16:48 getActtime(beginSecond, endSecond) { const acttime = this.fmtMcTime(beginSecond) + " 至 " + this.fmtMcTime(endSecond); // console.log("acttime:", acttime); 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); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 const date2 = new Date(timestamp2 * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘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; } // console.log("timeStr", timeStr); return timeStr; }, // 格式化赛事时间 2024年9月9日 至 9月12日 2024年12月9日 至 2025年1月6日 fmtMcTime3(timestamp1, timestamp2) { const date1 = new Date(timestamp1 * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 const date2 = new Date(timestamp2 * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘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 { timeStr2 += M2 + '月' + D2 + '日'; } var timeStr = timeStr1; if (timeStr2.length > 0) { timeStr += ' 至 ' + timeStr2; } // console.log("timeStr", timeStr); 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; // const dif = 3600*24 - 60; if (dif1 > 0) { console.log("活动未开始"); mcState = 0; // 未开始 } else if (dif2 > 0) { console.log("活动进行中"); mcState = 1; // 进行中 } else { console.log("活动已结束"); mcState = 2; // 已结束 } } return mcState; }, // 动态创建