From c6066fc6e44645203c1647a0faa2c5b20d8f36f6 Mon Sep 17 00:00:00 2001 From: yujialong <479214531@qq.com> Date: Wed, 8 Feb 2023 10:41:42 +0800 Subject: [PATCH] fix --- src/pages/account/login/index.vue | 9 +- src/pages/match/details/index.vue | 110 ++++++++++------ src/pages/match/list/index.vue | 172 +++++++++++++----------- src/pages/station/preview/index.vue | 2 +- src/pages/touristMatch/list/index.vue | 183 ++++++++++++++------------ 5 files changed, 274 insertions(+), 202 deletions(-) diff --git a/src/pages/account/login/index.vue b/src/pages/account/login/index.vue index 10bef34..db33aca 100644 --- a/src/pages/account/login/index.vue +++ b/src/pages/account/login/index.vue @@ -330,6 +330,9 @@ export default { ...mapActions("user", [ "setInfo" ]), + ...mapMutations('match', [ + 'SET_SOURCE' + ]), // 赋值学校列表及id setSchool(list) { this.schoolList = list @@ -417,10 +420,12 @@ export default { util.cookies.remove('serverLogin') this.reloadIndex() util.successMsg('登录成功') + const { toMatch } = this + this.SET_SOURCE('') this.$router.replace(this.courseId ? `/preCourse/details?id=${this.courseId}` : - this.toMatch ? - `/touristMatch` : + toMatch ? + `/touristMatch/details?id=` + toMatch : '/station') }, // 提交登录 diff --git a/src/pages/match/details/index.vue b/src/pages/match/details/index.vue index c49a712..5cfa4b5 100644 --- a/src/pages/match/details/index.vue +++ b/src/pages/match/details/index.vue @@ -14,7 +14,15 @@ 距离{{ endList[status] }}还有 {{ end }}
- {{ statusList[status] }} +{{ item.status == 4 ? item.stageName : statusList[item.status] }}
@@ -316,6 +324,7 @@ export default { 'SET_TYPE' ]), getList() { + this.clearTimer() const { form } = this const { eventType, competitionScope } = form const data = { @@ -357,82 +366,93 @@ export default { // 定时处理时间及状态 handleStatus() { this.listData.map(item => { - let total = '' - let time = '' - let status = '' - let signUpStartTime = new Date(this.core.dateCompatible(item.signUpStartTime)) // 报名开始时间 - let signUpEndTime = new Date(this.core.dateCompatible(item.signUpEndTime)) // 报名结束时间 - let playStartTime = new Date(this.core.dateCompatible(item.playStartTime)) // 比赛开始时间 - let playEndTime = new Date(this.core.dateCompatible(item.playEndTime)) // 比赛结束时间 - let timer = setInterval(() => { - const now = new Date() - if (now < signUpStartTime) { // 报名没开始 - status = 0 - total = signUpStartTime - now - } else if (now > signUpStartTime && now < signUpEndTime) { // 报名进行中 - // whetherToSignUp 0已报名,1未报名 - status = item.whetherToSignUp ? 2 : 1 // 1已报名,2立即报名 - total = signUpEndTime - now - } else if (now > signUpEndTime && now < playStartTime) { // 报名结束了,但比赛没开始 - status = 3 - total = playStartTime - now - } else if (now > playStartTime && now < playEndTime) { // 比赛进行中 - // 进行中的赛事,则遍历每个阶段的开始结束时间,看阶段比赛是否开始 - let curStage = null - const stages = item.competitionStageList - if (stages) { - for (const i in stages) { - const e = stages[i] - const startTime = new Date(e.startTime) - const endTime = new Date(e.endTime) - if (now < startTime) { // 阶段比赛未开始,不显示进入比赛按钮 - this.$set(item, 'stageName', '') - this.$set(item, 'endText', '阶段开始') - total = startTime - now - break - } else if (now >= startTime && now <= endTime) { // 阶段比赛进行中,显示进入比赛按钮 - if (item.whetherToSignUp === 0 && e.method !== 2) this.$set(item, 'stageName', e.count ? '已提交' : '进入' + e.stageName) // 报名了并且没参加比赛才能进入比赛 - this.$set(item, 'endText', '阶段结束') - curStage = e - total = endTime - now - break - } else if (stages[i + 1] && now > endTime && now < new Date(stages[i + 1].startTime)) { // 过了该阶段的结束时间,但是没到下个阶段的开始时间,不显示进入比赛按钮 - this.$set(item, 'stageName', '') - this.$set(item, 'endText', '阶段开始') - total = new Date(stages[i + 1].startTime) - now - break - } else if (i === stages.length - 1) { // 当前时间在比赛开始结束时间之间,并且是最后一个阶段结束时间之后 - this.$set(item, 'stageName', '') - this.$set(item, 'endText', '竞赛结束') - total = playEndTime - now - break + if (item.signUpStartTime && item.signUpEndTime && item.playStartTime && item.playEndTime) { + let total = '' + let time = '' + let status = '' + let signUpStartTime = new Date(this.core.dateCompatible(item.signUpStartTime)) // 报名开始时间 + let signUpEndTime = new Date(this.core.dateCompatible(item.signUpEndTime)) // 报名结束时间 + let playStartTime = new Date(this.core.dateCompatible(item.playStartTime)) // 比赛开始时间 + let playEndTime = new Date(this.core.dateCompatible(item.playEndTime)) // 比赛结束时间 + let timer = setInterval(() => { + const now = new Date() + if (now < signUpStartTime) { // 报名没开始 + status = 0 + total = signUpStartTime - now + } else if (now > signUpStartTime && now < signUpEndTime) { // 报名进行中 + // whetherToSignUp 0已报名,1未报名 + status = item.whetherToSignUp ? 2 : 1 // 1已报名,2立即报名 + total = signUpEndTime - now + } else if (now > signUpEndTime && now < playStartTime) { // 报名结束了,但比赛没开始 + status = 3 + total = playStartTime - now + } else if (now > playStartTime && now < playEndTime) { // 比赛进行中 + // 如果是完整比赛 + if (item.releaseType) { + // 进行中的赛事,则遍历每个阶段的开始结束时间,看阶段比赛是否开始 + let curStage = null + const stages = item.competitionStageList + if (stages) { + item.playingStages = [] + stages.forEach(e => { + if (now >= new Date(e.startTime) && now <= new Date(e.endTime) && e.method !== 2) item.playingStages.push(e) + }) + for (const i in stages) { + const e = stages[i] + const startTime = new Date(e.startTime) + const endTime = new Date(e.endTime) + if (now < startTime) { // 阶段比赛未开始,不显示进入比赛按钮 + this.$set(item, 'stageName', '') + this.$set(item, 'endText', '阶段开始') + total = startTime - now + break + } else if (now >= startTime && now <= endTime) { // 阶段比赛进行中,显示进入比赛按钮 + if (item.whetherToSignUp === 0 && e.method !== 2) this.$set(item, 'stageName', e.count ? '已提交' : '进入' + e.stageName) // 报名了并且没参加比赛才能进入比赛 + this.$set(item, 'endText', '阶段结束') + curStage = e + total = endTime - now + break + } else if (stages[i + 1] && now > endTime && now < new Date(stages[i + 1].startTime)) { // 过了该阶段的结束时间,但是没到下个阶段的开始时间,不显示进入比赛按钮 + this.$set(item, 'stageName', '') + this.$set(item, 'endText', '阶段开始') + total = new Date(stages[i + 1].startTime) - now + break + } else if (i === stages.length - 1) { // 当前时间在比赛开始结束时间之间,并且是最后一个阶段结束时间之后 + this.$set(item, 'stageName', '') + this.$set(item, 'endText', '竞赛结束') + total = playEndTime - now + break + } + } } + item.curStage = curStage + } else { // 仅发布信息 + this.$set(item, 'endText', '竞赛结束') + total = playEndTime - now } + status = 4 + } else if (now > playEndTime) { // 比赛结束 + status = 5 } - item.curStage = curStage - status = 4 - } else if (now > playEndTime) { // 比赛结束 - status = 5 - } - this.$set(item, 'status', status) - total = total / 1000 - --total - if (total > 86400) { // 超过一天则显示天数 - clearInterval(timer) - this.$set(item, 'end', Math.floor(total / 86400) + '天') - } else if (total > 0) { // 一天之内,显示时分秒 - let hours = Math.floor(total / (60 * 60)) - let minutes = Math.floor(total % (60 * 60) / 60) - let seconds = Math.floor(total % (60 * 60) % 60) - time = `${this.core.formateTime(hours)}:${this.core.formateTime(minutes)}:${this.core.formateTime(seconds)}` - if (total > 0) this.$set(item, 'end', time) - } else if (item.status === 5) { // 竞赛结束,清除定时器 - clearInterval(timer) - } - }, 1000) - this.timerList.push(timer) + this.$set(item, 'status', status) + total = total / 1000 + --total + if (total > 86400) { // 超过一天则显示天数 + // clearInterval(timer) + this.$set(item, 'end', Math.floor(total / 86400) + '天') + } else if (total > 0) { // 一天之内,显示时分秒 + let hours = Math.floor(total / (60 * 60)) + let minutes = Math.floor(total % (60 * 60) / 60) + let seconds = Math.floor(total % (60 * 60) % 60) + time = `${this.core.formateTime(hours)}:${this.core.formateTime(minutes)}:${this.core.formateTime(seconds)}` + if (total > 0) this.$set(item, 'end', time) + } else if (item.status === 5) { // 竞赛结束,清除定时器 + clearInterval(timer) + } + }, 1000) + this.timerList.push(timer) + } }) - console.log("🚀 ~ file: index.vue:434 ~ handleStatus ~ timerList", this.listData) }, // 清除定时器 clearTimer() { @@ -492,7 +512,6 @@ export default { this.$router.push(`/match/details?id=${item.id}`); }, handleCurrentChange(val) { - this.clearTimer() this.page = val; this.getData(); }, @@ -546,6 +565,11 @@ export default { util.successMsg('报名成功!') }).catch(res => {}) }, + // 选择要进入的阶段 + chooseStage(e, item) { + item.curStage = e + this.signup(item) + }, // 判断是否能进赛事 getAllow(item) { // 是否允许参加赛事(淘汰赛制) diff --git a/src/pages/station/preview/index.vue b/src/pages/station/preview/index.vue index 9748b6c..c34669c 100644 --- a/src/pages/station/preview/index.vue +++ b/src/pages/station/preview/index.vue @@ -90,7 +90,7 @@
{{ item.status == 4 ? item.stageName : statusList[item.status] }}
@@ -279,6 +287,7 @@ export default { 'SET_SOURCE' ]), getList() { + this.clearTimer() const { form } = this const scope = form.competitionScope const data = { @@ -312,16 +321,6 @@ export default { this.listData = records this.totals = data.total this.handleStatus() - - // 如果是登录前点报名去登录的,则跳转到该赛事,toMatch存的是点击的赛事id,通过scrollIntoView去跳到赛事的位置 - const id = this.toMatch - if (id) { - this.$nextTick(() => { - this.SET_SOURCE('') - const item = records.find(e => e.id === id) - item && this.toDetail(item) - }) - } this.loadIns.close() }).catch(res => { this.loadIns.close() @@ -330,82 +329,92 @@ export default { // 定时处理时间及状态 handleStatus() { this.listData.map(item => { - let total = '' - let time = '' - let status = '' - let signUpStartTime = new Date(this.core.dateCompatible(item.signUpStartTime)) // 报名开始时间 - let signUpEndTime = new Date(this.core.dateCompatible(item.signUpEndTime)) // 报名结束时间 - let playStartTime = new Date(this.core.dateCompatible(item.playStartTime)) // 比赛开始时间 - let playEndTime = new Date(this.core.dateCompatible(item.playEndTime)) // 比赛结束时间 - let timer = setInterval(() => { - const now = new Date() - if (now < signUpStartTime) { // 报名没开始 - status = 0 - total = signUpStartTime - now - } else if (now > signUpStartTime && now < signUpEndTime) { // 报名进行中 - // whetherToSignUp 0已报名,1未报名 - status = item.whetherToSignUp === 0 ? 1 : 2 // 1已报名,2立即报名 - total = signUpEndTime - now - } else if (now > signUpEndTime && now < playStartTime) { // 报名结束了,但比赛没开始 - status = 3 - total = playStartTime - now - } else if (now > playStartTime && now < playEndTime) { // 比赛进行中 - // 进行中的赛事,则遍历每个阶段的开始结束时间,看阶段比赛是否开始 - let curStage = null - const stages = item.competitionStageList - if (stages) { - for (const i in stages) { - const e = stages[i] - const startTime = new Date(e.startTime) - const endTime = new Date(e.endTime) - if (now < startTime) { // 阶段比赛未开始,不显示进入比赛按钮 - this.$set(item, 'stageName', '') - this.$set(item, 'endText', '阶段开始') - total = startTime - now - break - } else if (now >= startTime && now <= endTime) { // 阶段比赛进行中,显示进入比赛按钮 - if ((item.whetherToSignUp === 0 || !util.local.get(Setting.tokenKey)) && e.method !== 2) this.$set(item, 'stageName', e.count ? '已提交' : '进入' + e.stageName) // 报名了并且没参加比赛才能进入比赛 - this.$set(item, 'endText', '阶段结束') - curStage = e - total = endTime - now - break - } else if (stages[i + 1] && now > endTime && now < new Date(stages[i + 1].startTime)) { // 过了该阶段的结束时间,但是没到下个阶段的开始时间,不显示进入比赛按钮 - this.$set(item, 'stageName', '') - this.$set(item, 'endText', '阶段开始') - total = new Date(stages[i + 1].startTime) - now - break - } else if (i === stages.length - 1) { // 当前时间在比赛开始结束时间之间,并且是最后一个阶段结束时间之后 - this.$set(item, 'stageName', '') - this.$set(item, 'endText', '竞赛结束') - total = playEndTime - now - break + if (item.signUpStartTime && item.signUpEndTime && item.playStartTime && item.playEndTime) { + let total = '' + let time = '' + let status = '' + let signUpStartTime = new Date(this.core.dateCompatible(item.signUpStartTime)) // 报名开始时间 + let signUpEndTime = new Date(this.core.dateCompatible(item.signUpEndTime)) // 报名结束时间 + let playStartTime = new Date(this.core.dateCompatible(item.playStartTime)) // 比赛开始时间 + let playEndTime = new Date(this.core.dateCompatible(item.playEndTime)) // 比赛结束时间 + let timer = setInterval(() => { + const now = new Date() + if (now < signUpStartTime) { // 报名没开始 + status = 0 + total = signUpStartTime - now + } else if (now > signUpStartTime && now < signUpEndTime) { // 报名进行中 + // whetherToSignUp 0已报名,1未报名 + status = item.whetherToSignUp === 0 ? 1 : 2 // 1已报名,2立即报名 + total = signUpEndTime - now + } else if (now > signUpEndTime && now < playStartTime) { // 报名结束了,但比赛没开始 + status = 3 + total = playStartTime - now + } else if (now > playStartTime && now < playEndTime) { // 比赛进行中 + // 如果是完整比赛 + if (item.releaseType) { + // 进行中的赛事,则遍历每个阶段的开始结束时间,看阶段比赛是否开始 + let curStage = null + const stages = item.competitionStageList + if (stages) { + item.playingStages = [] + stages.forEach(e => { + if (now >= new Date(e.startTime) && now <= new Date(e.endTime) && e.method !== 2) item.playingStages.push(e) + }) + for (const i in stages) { + const e = stages[i] + const startTime = new Date(e.startTime) + const endTime = new Date(e.endTime) + if (now < startTime) { // 阶段比赛未开始,不显示进入比赛按钮 + this.$set(item, 'stageName', '') + this.$set(item, 'endText', '阶段开始') + total = startTime - now + break + } else if (now >= startTime && now <= endTime) { // 阶段比赛进行中,显示进入比赛按钮 + if ((item.whetherToSignUp === 0 || !util.local.get(Setting.tokenKey)) && e.method !== 2) this.$set(item, 'stageName', e.count ? '已提交' : '进入' + e.stageName) // 报名了并且没参加比赛才能进入比赛 + this.$set(item, 'endText', '阶段结束') + curStage = e + total = endTime - now + break + } else if (stages[i + 1] && now > endTime && now < new Date(stages[i + 1].startTime)) { // 过了该阶段的结束时间,但是没到下个阶段的开始时间,不显示进入比赛按钮 + this.$set(item, 'stageName', '') + this.$set(item, 'endText', '阶段开始') + total = new Date(stages[i + 1].startTime) - now + break + } else if (i === stages.length - 1) { // 当前时间在比赛开始结束时间之间,并且是最后一个阶段结束时间之后 + this.$set(item, 'stageName', '') + this.$set(item, 'endText', '竞赛结束') + total = playEndTime - now + break + } + } } + item.curStage = curStage + } else { // 仅发布信息 + this.$set(item, 'endText', '竞赛结束') + total = playEndTime - now } + status = 4 + } else if (now > playEndTime) { // 比赛结束 + status = 5 } - item.curStage = curStage - status = 4 - } else if (now > playEndTime) { // 比赛结束 - status = 5 - } - this.$set(item, 'status', status) - total = total / 1000 - --total - if (total > 86400) { // 超过一天则显示天数 - clearInterval(timer) - this.$set(item, 'end', Math.floor(total / 86400) + '天') - } else if (total > 0) { // 一天之内,显示时分秒 - let hours = Math.floor(total / (60 * 60)) - let minutes = Math.floor(total % (60 * 60) / 60) - let seconds = Math.floor(total % (60 * 60) % 60) - time = `${this.core.formateTime(hours)}:${this.core.formateTime(minutes)}:${this.core.formateTime(seconds)}` - if (total > 0) this.$set(item, 'end', time) - } else if (item.status === 5) { // 竞赛结束,清除定时器 - clearInterval(timer) - } - console.log(33, this.listData) - }, 1000) - this.timerList.push(timer) - + this.$set(item, 'status', status) + total = total / 1000 + --total + if (total > 86400) { // 超过一天则显示天数 + // clearInterval(timer) + this.$set(item, 'end', Math.floor(total / 86400) + '天') + } else if (total > 0) { // 一天之内,显示时分秒 + let hours = Math.floor(total / (60 * 60)) + let minutes = Math.floor(total % (60 * 60) / 60) + let seconds = Math.floor(total % (60 * 60) % 60) + time = `${this.core.formateTime(hours)}:${this.core.formateTime(minutes)}:${this.core.formateTime(seconds)}` + if (total > 0) this.$set(item, 'end', time) + } else if (item.status === 5) { // 竞赛结束,清除定时器 + clearInterval(timer) + } + }, 1000) + this.timerList.push(timer) + } }) }, // 清除定时器 @@ -456,7 +465,6 @@ export default { this.$router.push(`/touristMatch/details?id=${item.id}`); }, handleCurrentChange(val) { - this.clearTimer() this.page = val; this.getData(); }, @@ -509,6 +517,11 @@ export default { util.successMsg('报名成功!') }).catch(res => {}) }, + // 选择要进入的阶段 + chooseStage(e, item) { + item.curStage = e + this.signup(item) + }, // 判断是否能进赛事 getAllow(item) { // 是否允许参加赛事(淘汰赛制)