Commit 19a98200 by liimin

refactor(components): 优化轮播组件自动播放逻辑和内存管理

refactor(pages): 重构详情页数据结构并优化性能

fix(components): 修复轮播组件销毁时未清理定时器的问题
1 parent 4747dbb0
......@@ -77,6 +77,16 @@ export default {
this.getDatalist()
if (this.autoplay) this.autoPlayFunction()
},
beforeDestroy() {
if (this.autoPlayTimer) {
clearTimeout(this.autoPlayTimer)
this.autoPlayTimer = null
}
if (this.endTimer) {
clearTimeout(this.endTimer)
this.endTimer = null
}
},
methods: {
getDatalist() {
this.datalist = this.moduleList
......@@ -195,6 +205,13 @@ export default {
})
}
},
restartAutoPlay() {
if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer)
this.autoPlayTimer = setTimeout(() => {
this.playStatus = true
this.autoPlayFunction()
}, this.interval)
},
starts(e) {
this.ismove = e.touches[0].pageX
this.playStatus = false
......@@ -212,16 +229,16 @@ export default {
if (nums > 30) this.updateCarouselPositions('left')
if (nums < -30) this.updateCarouselPositions('right')
this.endTimer = setTimeout(() => {
this.playStatus = true
this.autoPlayFunction()
}, this.interval)
this.restartAutoPlay()
},
handleClick(item) {
if (item.class !== 'block-center') {
// 点击两侧卡片也可以切换
if (item.class === 'block-right') this.updateCarouselPositions('left')
if (item.class === 'block-left') this.updateCarouselPositions('right')
// 重置自动轮播计时器
this.restartAutoPlay()
return
}
const data = this.moduleList[item.isIndex]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!