From 836deefab1d55cf9174bf958827c0c1545e7bbe8 Mon Sep 17 00:00:00 2001 From: xuhuajiao <13476289682@163.com> Date: Wed, 23 Sep 2026 13:57:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9C=80=E6=B1=82=E4=BC=98=E5=8C=96=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/accessToLibrary/index.vue | 125 ++++++++++++++++----------- src/views/newBookRecommend/index.vue | 34 +++++--- src/views/notice/index.vue | 89 ++++++++++++------- src/views/readStar/index-height.vue | 2 +- src/views/readStar/index.vue | 2 +- 5 files changed, 156 insertions(+), 96 deletions(-) diff --git a/src/views/accessToLibrary/index.vue b/src/views/accessToLibrary/index.vue index 208aa94..12742d3 100644 --- a/src/views/accessToLibrary/index.vue +++ b/src/views/accessToLibrary/index.vue @@ -31,9 +31,7 @@ export default { props: { isSelfService: { type: Boolean, - default: function() { - return false - } + default: false } }, data() { @@ -43,70 +41,87 @@ export default { dayOutNum: 0, monthNum: 0, totalNum: 0, - otherDoorOther: null + otherDoorOther: null, + abortController: null, + isPageHide: false } }, created() { - // 获取数据 this.getInitIntoNum() }, mounted() { - // 每15秒获取一次 - this.timer = setInterval(() => { - this.getInitIntoNum() - }, 15000) + document.addEventListener('visibilitychange', this.handleVisibility) + this.startPoll() }, beforeDestroy() { - // 销毁定时器 - this.$once('hook:beforeDestroy', () => { - clearInterval(this.timer) - }) + this.stopPoll() + if (this.abortController) { + this.abortController.abort() + } + document.removeEventListener('visibilitychange', this.handleVisibility) }, methods: { + handleVisibility() { + this.isPageHide = document.hidden + if (this.isPageHide) { + this.stopPoll() + } else { + this.startPoll() + } + }, + startPoll() { + this.stopPoll() + this.timer = setInterval(() => { + this.getInitIntoNum() + }, 15000) + }, + stopPoll() { + if (this.timer) { + clearInterval(this.timer) + this.timer = null + } + }, getInitIntoNum() { - // http://192.168.99.118:8080/#/?doorCodes=D001&D002&D007&startTime=2023-01-01&endTime=2023-08-31 - // this.otherDoorOther = window.location.href.split('?')[1]?.split('=')[1] - const currentURL = window.location.href - console.log(currentURL) - if (currentURL.indexOf('?') !== -1) { - const query = currentURL.split('?')[1] - console.log(query) - console.log(query.indexOf('startTime')) - if (query.indexOf('startTime') !== -1 || query.indexOf('endTime') !== -1) { - const paramsUrl = query.split('&') - console.log(paramsUrl) - let startTimeIndex = -1 - for (let i = 0; i < paramsUrl.length; i++) { - const [key] = paramsUrl[i].split('=') - if (key === 'startTime' || key === 'endTime') { - startTimeIndex = i - break - } + // 【修复】hash模式,#?后面的参数串 + const fullUrl = window.location.href + const hashContent = fullUrl.split('#')[1] || '' + let queryStr = '' + if (hashContent.includes('?')) { + queryStr = hashContent.split('?')[1] + } + console.log('queryStr', queryStr) + + let otherDoorOther = null + if (queryStr) { + // 找到 &startTime= / &endTime= 的位置,在此截断,前面全部属于doorCodes值 + let cutIndex = Infinity + const markers = ['&startTime=', '&endTime='] + for (const m of markers) { + const idx = queryStr.indexOf(m) + if (idx !== -1 && idx < cutIndex) { + cutIndex = idx } - // 去除 startTime 参数及其后面的参数 - const filteredParams = startTimeIndex >= 0 ? paramsUrl.slice(0, startTimeIndex) : params - const newQueryString = filteredParams.join('&') - this.otherDoorOther = newQueryString.split('=')[1] + } + let doorCodesRaw + if (cutIndex !== Infinity) { + doorCodesRaw = queryStr.substring(0, cutIndex) } else { - this.otherDoorOther = query.split('=')[1] + doorCodesRaw = queryStr + } + // 去掉 doorCodes= 前缀 + if (doorCodesRaw.startsWith('doorCodes=')) { + doorCodesRaw = doorCodesRaw.replace('doorCodes=', '') + } + if (doorCodesRaw) { + otherDoorOther = doorCodesRaw.replace(/&/g, '、') } - } else { - this.otherDoorOther = null } + this.otherDoorOther = otherDoorOther + console.log('otherDoorOther', otherDoorOther) const startTime = this.$route.query.startTime const endTime = this.$route.query.endTime - console.log('otherDoorOther', this.otherDoorOther) - - if (this.otherDoorOther && this.otherDoorOther !== '' && this.otherDoorOther.indexOf('&')) { - this.otherDoorOther = this.otherDoorOther.replace(/\&/g, '、') - } else { - this.otherDoorOther = null - } - - console.log('otherDoorOther2', this.otherDoorOther) - let params if (!this.isSelfService) { params = { @@ -121,7 +136,14 @@ export default { endTime: endTime } } - FetchInitIntoNum(params).then((res) => { + + // 增加请求取消(如果你的axios封装支持signal就打开,不支持注释掉abort相关) + if (this.abortController) this.abortController.abort() + this.abortController = new AbortController() + + FetchInitIntoNum(params, { + signal: this.abortController?.signal + }).then((res) => { if (res.errCode === 0) { this.dayNum = res.data.dayPeopleNum this.monthNum = res.data.monthPeopleNum @@ -130,6 +152,11 @@ export default { } else { this.$message.error('接口错误') } + }).catch(err => { + // abort取消的请求不弹报错 + if (err.name !== 'AbortError') { + console.error('进馆人数接口异常', err) + } }) } } diff --git a/src/views/newBookRecommend/index.vue b/src/views/newBookRecommend/index.vue index c22a4d5..77a0326 100644 --- a/src/views/newBookRecommend/index.vue +++ b/src/views/newBookRecommend/index.vue @@ -42,7 +42,8 @@