From d7406956db4068ea0691289c0021dd39c0aaec17 Mon Sep 17 00:00:00 2001 From: zheng020 Date: Thu, 30 Apr 2026 05:52:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=B7=BB=E5=8A=A0=E4=BA=A4=E4=BA=92=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/index/views/home2/index.vue | 162 ++++++++++++++---- txw-mhzc-web/vue.config.js | 8 +- 2 files changed, 133 insertions(+), 37 deletions(-) diff --git a/txw-mhzc-web/src/pages/index/views/home2/index.vue b/txw-mhzc-web/src/pages/index/views/home2/index.vue index b845979..c1159a8 100644 --- a/txw-mhzc-web/src/pages/index/views/home2/index.vue +++ b/txw-mhzc-web/src/pages/index/views/home2/index.vue @@ -3,8 +3,9 @@
-
- +
+
热门搜索:
-
{{ tag }}
+
{{ + tag }}
@@ -71,8 +73,8 @@
-
-
+
+
核心驱动 @@ -90,7 +92,7 @@
-
+
@@ -103,7 +105,8 @@
-
+
{{ item.name }} @@ -115,7 +118,7 @@
-
+
@@ -144,7 +147,7 @@
-
+
@@ -156,7 +159,8 @@
-
+
{{ tab.name }}
@@ -195,7 +199,7 @@
-
+
@@ -242,7 +246,7 @@
-
+
立刻获取第一张碳身份证
让中国的每一个碳都拥有独一无二的可信数字身份
@@ -269,6 +273,9 @@ export default { activeTab: 0, topBannerHeight: 820, newsLoading: true, + isScrolling: false, + scrollThreshold: 1, + sectionIds: ['section-hero', 'section-core', 'section-capability', 'section-overseas', 'section-news', 'section-partner', 'section-bottom'], newsListByType: { gjzc: [], // 国家政策 hyzx: [], // 行业资讯 @@ -372,11 +379,80 @@ export default { this.syncBannerHeight(); window.addEventListener('resize', this.syncBannerHeight); this.fetchNewsData(); + window.addEventListener('wheel', this.handleWheel, { passive: false }); }, beforeDestroy() { window.removeEventListener('resize', this.syncBannerHeight); + window.removeEventListener('wheel', this.handleWheel); }, methods: { + handleWheel(e) { + if (this.isScrolling) return; + const delta = Math.abs(e.deltaY); + if (delta < this.scrollThreshold) return; + + e.preventDefault(); + this.isScrolling = true; + + const direction = e.deltaY > 0 ? 1 : -1; + const viewHeight = window.innerHeight; + + let currentIndex = -1; + let minDistance = Infinity; + + // 找到当前视口中最靠近顶部的模块 + for (let i = 0; i < this.sectionIds.length; i++) { + const el = document.getElementById(this.sectionIds[i]); + if (el) { + const rect = el.getBoundingClientRect(); + // 模块的顶部在视口内或视口上方,且底部在视口下方 + if (rect.top <= viewHeight && rect.bottom > 0) { + const distance = Math.abs(rect.top); + if (distance < minDistance) { + minDistance = distance; + currentIndex = i; + } + } + } + } + + // 如果没找到,尝试用另一种方式定位 + if (currentIndex === -1) { + const scrollTop = window.pageYOffset || document.documentElement.scrollTop; + for (let i = 0; i < this.sectionIds.length; i++) { + const el = document.getElementById(this.sectionIds[i]); + if (el && el.offsetTop <= scrollTop) { + currentIndex = i; + } + } + } + + let targetIndex; + if (direction > 0) { + // 向下滚动:到下一个模块 + targetIndex = currentIndex === -1 ? 0 : Math.min(currentIndex + 1, this.sectionIds.length - 1); + } else { + // 向上滚动:到上一个模块 + targetIndex = currentIndex === -1 ? 0 : Math.max(currentIndex - 1, 0); + } + + const targetEl = document.getElementById(this.sectionIds[targetIndex]); + if (targetEl) { + const rect = targetEl.getBoundingClientRect(); + const elHeight = rect.height; + if (elHeight < viewHeight) { + // 模块高度小于视口,垂直居中 + targetEl.scrollIntoView({ behavior: 'smooth', block: 'center' }); + } else { + // 模块高度大于视口,顶部落底 + targetEl.scrollIntoView({ behavior: 'smooth', block: 'start' }); + } + } + + setTimeout(() => { + this.isScrolling = false; + }, 800); + }, openNewTab(url) { window.open(url); }, @@ -508,7 +584,7 @@ export default { }; -