|
|
@ -45,6 +45,17 @@ export default { |
|
|
|
scrollLock: false, |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
watch: { |
|
|
|
'$route'(to, from) { |
|
|
|
console.log(to, from); |
|
|
|
// 路由变化时重新计算位置 |
|
|
|
this.$nextTick(() => { |
|
|
|
this.calculateFloorOffsets(); |
|
|
|
this.handleScroll(); // 立即检查当前位置 |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
this.activeFloor = this.menuList[this.curIndex]?.list?.[0]?.desc; |
|
|
|
this.$nextTick(() => { |
|
|
@ -52,7 +63,7 @@ export default { |
|
|
|
this.scrollContainer = document.querySelector('.main-content') || |
|
|
|
document.getElementById('main-content') || |
|
|
|
window; |
|
|
|
console.log(this.scrollContainer,'this.scrollContainer---'); |
|
|
|
|
|
|
|
if (this.scrollContainer) { |
|
|
|
this.scrollContainer.addEventListener('scroll', this.handleScroll); |
|
|
|
this.calculateFloorOffsets(); |
|
|
@ -61,16 +72,6 @@ export default { |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
watch: { |
|
|
|
'$route'(to, from) { |
|
|
|
console.log(to, from); |
|
|
|
// 路由变化时重新计算位置 |
|
|
|
this.$nextTick(() => { |
|
|
|
this.calculateFloorOffsets(); |
|
|
|
this.handleScroll(); // 立即检查当前位置 |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
beforeDestroy() { |
|
|
|
if (this.scrollContainer) { |
|
|
|
this.scrollContainer.removeEventListener('scroll', this.handleScroll); |
|
|
@ -86,30 +87,6 @@ export default { |
|
|
|
var randomNumber = Math.random(); |
|
|
|
return randomNumber |
|
|
|
}, |
|
|
|
// calculateFloorOffsets() { |
|
|
|
// this.menuList.forEach(item => { |
|
|
|
// item.list.forEach(every => { |
|
|
|
// const el = document.getElementById(every.desc); |
|
|
|
// if (el) { |
|
|
|
// every.offsetTop = el.offsetTop; |
|
|
|
// } |
|
|
|
// }) |
|
|
|
// }); |
|
|
|
// }, |
|
|
|
// handleScroll() { |
|
|
|
// if (this.scrollLock) return |
|
|
|
// const scrollContainer = this.$parent.$refs.scrollContainer; |
|
|
|
// const scrollHeight = scrollContainer.scrollTop; |
|
|
|
// let activeFloor = this.menuList[this.curIndex]['list'][0]['desc']; |
|
|
|
// this.menuList[this.curIndex]['list'].forEach(item => { |
|
|
|
// if (scrollHeight + 72 >= item.offsetTop) { |
|
|
|
// activeFloor = item.desc; // 更新当前激活的楼层ID |
|
|
|
// } else { |
|
|
|
// return false; // 一旦找到第一个小于当前滚动位置的楼层,停止循环 |
|
|
|
// } |
|
|
|
// }); |
|
|
|
// this.activeFloor = activeFloor; // 更新数据以触发视图更新 |
|
|
|
// }, |
|
|
|
calculateFloorOffsets() { |
|
|
|
this.menuList.forEach(item => { |
|
|
|
item.list?.forEach(every => { |
|
|
@ -189,7 +166,7 @@ export default { |
|
|
|
console.log(type); |
|
|
|
}, |
|
|
|
setActiveCur(dom, item) { |
|
|
|
if (item.path && this.$route.path !== item.path) { |
|
|
|
if (this.$route.path !== item.path) { |
|
|
|
this.$router.push(item.path); |
|
|
|
store.commit('SET_PAGETITLE', item.name); |
|
|
|
} |
|
|
|