|
|
@@ -328,44 +328,6 @@
|
|
|
this.moduleNavList = Object.entries(navMap)
|
|
|
.filter(([key]) => this[key]?.length > 0)
|
|
|
.map(([, value]) => value);
|
|
|
- this.initObserver();
|
|
|
- },
|
|
|
- // 初始化 IntersectionObserver
|
|
|
- initObserver() {
|
|
|
- if (this.moduleObserver) {
|
|
|
- this.moduleObserver.disconnect();
|
|
|
- }
|
|
|
- this.$nextTick(() => {
|
|
|
- const query = uni.createSelectorQuery().in(this);
|
|
|
- query.select('.top-nav-wrapper').boundingClientRect();
|
|
|
- query.select('.content-wrapper').boundingClientRect();
|
|
|
- query.exec((rects) => {
|
|
|
- if (rects[0]) {
|
|
|
- this.topNavHeight = rects[0].bottom;
|
|
|
- }
|
|
|
- // 初始化 observer
|
|
|
- this.moduleObserver = uni.createIntersectionObserver(this, {
|
|
|
- thresholds: [0, 0.5, 1],
|
|
|
- observeAll: true
|
|
|
- });
|
|
|
- // 监测区域顶部设为导航栏底部
|
|
|
- this.moduleObserver.relativeTo('.content-wrapper', {
|
|
|
- top: rects[0] ? rects[0].height : 80
|
|
|
- });
|
|
|
- // 根据 moduleNavList 动态监测模块
|
|
|
- // this.moduleNavList.forEach(item => {
|
|
|
- // this.moduleObserver.observe('#module-' + item.id, (res) => {
|
|
|
- // console.log('res~~~', res);
|
|
|
- // if (res.intersectionRatio > 0) {
|
|
|
- // const index = parseInt(res.dataset.index);
|
|
|
- // if (!isNaN(index)) {
|
|
|
- // this.currentNavIndex = index;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // });
|
|
|
- // });
|
|
|
- });
|
|
|
- });
|
|
|
},
|
|
|
// 点击导航跳转
|
|
|
goToModule(item, index) {
|