From 6745f2093ebfe321e23d3dad786a8f568e1ddbbb Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Fri, 29 May 2026 14:47:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(merch/detail):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=95=86=E5=93=81=E8=AF=A6=E6=83=85=E9=A1=B5=E5=A4=B4=E9=83=A8?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 移除冗余的headerHeightInited状态和监听逻辑 2. 提取获取商品详情的逻辑为单独getMerch方法 3. 移除initHeaderHeight的延迟定时器并修复top样式值 --- pages_promotion/merch/detail.vue | 47 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/pages_promotion/merch/detail.vue b/pages_promotion/merch/detail.vue index 54dd0c9..122774c 100644 --- a/pages_promotion/merch/detail.vue +++ b/pages_promotion/merch/detail.vue @@ -322,23 +322,27 @@ export default { return { headerHeight: 320, screenWidth: uni.getSystemInfoSync().windowWidth, - headerHeightInited: false, changeStyleDebounce: null }; }, mixins: [list], - watch: { - 'merch.desc': { - handler() { - if (!this.headerHeightInited) { - this.$nextTick(() => { - this.initHeaderHeight(); - }); - } - } - } - }, methods: { + getMerch() { + this.$api.sendRequest({ + url: '/merch/api/merch/merchinfo', + data: { + merch_id: this.merch_id + }, + success: res => { + if (res.code >= 0 && res.data) { + this.merch = res.data; + this.$nextTick(() => { + this.initHeaderHeight(); + }); + } + } + }); + }, showFullDesc() { if (this.merch.desc) { uni.showModal({ @@ -349,15 +353,12 @@ export default { } }, initHeaderHeight() { - setTimeout(() => { - const query = uni.createSelectorQuery().in(this); - query.select('.head-wrap').boundingClientRect(rect => { - if (rect && rect.height > 0) { - this.headerHeight = (rect.height / this.screenWidth) * 750; - this.headerHeightInited = true; - } - }).exec(); - }, 100); + const query = uni.createSelectorQuery().in(this); + query.select('.head-wrap').boundingClientRect(rect => { + if (rect && rect.height > 0) { + this.headerHeight = (rect.height / this.screenWidth) * 750; + } + }).exec(); }, changeListStyle() { if (this.changeStyleDebounce) clearTimeout(this.changeStyleDebounce); @@ -377,8 +378,8 @@ export default { @import './public/css/list.scss';