From f51fcad9c2dcd7d1165b2686b94adc676e04c0f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E9=A6=99=E7=90=AA?= <624506849@qq.com> Date: Mon, 10 Aug 2026 14:08:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9B=B4=E6=96=B0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E9=A1=B5=E9=9D=A2=E6=A0=B7=E5=BC=8F=E5=92=8C=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BB=A5=E6=94=AF=E6=8C=81=E5=A4=9A=E7=AB=AF=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 search.scss 文件,优化样式以适应小程序和 H5/APP-PLUS 端 - 更新 searchPage.vue 文件,调整条件编译指令以支持多端展示 - 移除不必要的计算逻辑,简化代码结构,提高可读性 --- pages/navigation/search/search.scss | 24 +++++++- pages/navigation/search/searchPage.vue | 81 ++------------------------ 2 files changed, 25 insertions(+), 80 deletions(-) diff --git a/pages/navigation/search/search.scss b/pages/navigation/search/search.scss index 4ed9545..268cce0 100644 --- a/pages/navigation/search/search.scss +++ b/pages/navigation/search/search.scss @@ -133,14 +133,23 @@ page { margin-bottom: 20rpx; } } -.scoll-page, -.goods-scroll { +.scoll-page { flex: 1; min-height: 0; height: 100%; box-sizing: border-box; } +/* #ifdef MP */ +.goods-scroll { + flex: 1; + height: 0; + min-height: 0; + width: 100%; + box-sizing: border-box; +} +/* #endif */ + .search-navbar-wrap { box-sizing: border-box; flex-shrink: 0; @@ -163,6 +172,12 @@ page { background: $bg-color; } +/* #ifdef MP */ +.goods-content { + height: 0; +} +/* #endif */ + .content { background-color: $bg-color; height: 100vh; @@ -171,14 +186,16 @@ page { flex-direction: column; } -/* #ifdef H5 */ +/* #ifdef H5 || APP-PLUS */ .content--goods { + display: block; height: auto; min-height: 100vh; overflow: visible; } .goods-content--h5 { + display: block; flex: none; min-height: auto; overflow: visible; @@ -440,6 +457,7 @@ page { display: flex; width: 100%; height: 80rpx; + flex-shrink: 0; background: #fff; box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.06); z-index: 10; diff --git a/pages/navigation/search/searchPage.vue b/pages/navigation/search/searchPage.vue index 6670b42..615e532 100644 --- a/pages/navigation/search/searchPage.vue +++ b/pages/navigation/search/searchPage.vue @@ -105,7 +105,7 @@ 筛选 - + @@ -115,12 +115,11 @@ - + (null) @@ -328,7 +321,6 @@ const sortParams = ref({ const routerVal = ref('') const capsuleInsetRight = ref(0) const searchNavbarWidth = ref(0) -const goodsScrollHeight = ref(0) const searchNavbarStyle = computed(() => { if (searchNavbarWidth.value) { @@ -341,17 +333,7 @@ const searchNavbarStyle = computed(() => { } }) -const goodsScrollStyle = computed(() => { - if (goodsScrollHeight.value > 0) { - return { - height: `${goodsScrollHeight.value}px`, - } - } - return {} -}) - onPageScroll((e) => { - console.log(e) scrollTop.value = e.scrollTop }) @@ -390,23 +372,6 @@ onLoad((val) => { onReady(() => { setSearchNavbarWidth() - calcGoodsScrollHeight() -}) - -onShow(() => { - calcGoodsScrollHeight() -}) - -onMounted(() => { - // #ifdef H5 - window.addEventListener('resize', calcGoodsScrollHeight) - // #endif -}) - -onBeforeUnmount(() => { - // #ifdef H5 - window.removeEventListener('resize', calcGoodsScrollHeight) - // #endif }) watch(keyword, (val) => { @@ -427,22 +392,8 @@ watch(sortPopup, (val) => { } }) -watch(isShowSeachGoods, (val) => { - if (val) { - nextTick(() => { - calcGoodsScrollHeight() - }) - } -}) - -watch(isSWitch, () => { - nextTick(() => { - calcGoodsScrollHeight() - }) -}) - onReachBottom(() => { - // #ifdef H5 + // #ifdef H5 || APP-PLUS if (!isShowSeachGoods.value || loadingType.value !== 'more') { return } @@ -450,27 +401,6 @@ onReachBottom(() => { // #endif }) -function calcGoodsScrollHeight() { - nextTick(() => { - const query = uni.createSelectorQuery().in(proxy) - query.select('.goods-content').boundingClientRect() - query.select('.goods-content .navbar').boundingClientRect() - query.exec((res) => { - const contentRect = res[0] - const navbarRect = res[1] - if (!contentRect) { - return - } - const sortBarHeight = navbarRect ? navbarRect.height : uni.upx2px(80) - const { windowHeight } = uni.getWindowInfo() - const height = - Math.max(contentRect.height, windowHeight - contentRect.top) - - sortBarHeight - goodsScrollHeight.value = Math.max(height, 0) - }) - }) -} - function setSearchNavbarWidth() { // #ifdef MP-WEIXIN try { @@ -738,9 +668,6 @@ async function loadData(type?: string, _loading?: number) { empty.value = goodsListData.value.length === 0 initSortGoods() - nextTick(() => { - calcGoodsScrollHeight() - }) if (store.state.isShowToast) { uni.hideLoading() } @@ -849,7 +776,7 @@ function saveKeyword(saveKey: string) { @import './search.scss';