fix(merch/detail): 防止重复初始化头部高度

1. 新增headerHeightInited状态避免重复调用initHeaderHeight
2. 在initHeaderHeight中增加商品名称校验防止无效执行
3. 仅在页面首次获取商品数据后初始化头部高度
This commit is contained in:
2026-05-29 14:58:08 +08:00
parent 6745f2093e
commit dc4b3df715

View File

@@ -322,7 +322,8 @@ export default {
return { return {
headerHeight: 320, headerHeight: 320,
screenWidth: uni.getSystemInfoSync().windowWidth, screenWidth: uni.getSystemInfoSync().windowWidth,
changeStyleDebounce: null changeStyleDebounce: null,
headerHeightInited: false
}; };
}, },
mixins: [list], mixins: [list],
@@ -337,7 +338,9 @@ export default {
if (res.code >= 0 && res.data) { if (res.code >= 0 && res.data) {
this.merch = res.data; this.merch = res.data;
this.$nextTick(() => { this.$nextTick(() => {
this.initHeaderHeight(); if (!this.headerHeightInited) {
this.initHeaderHeight();
}
}); });
} }
} }
@@ -353,10 +356,13 @@ export default {
} }
}, },
initHeaderHeight() { initHeaderHeight() {
if (!this.merch || !this.merch.merch_name) return;
if (this.headerHeightInited) return;
const query = uni.createSelectorQuery().in(this); const query = uni.createSelectorQuery().in(this);
query.select('.head-wrap').boundingClientRect(rect => { query.select('.head-wrap').boundingClientRect(rect => {
if (rect && rect.height > 0) { if (rect && rect.height > 0) {
this.headerHeight = (rect.height / this.screenWidth) * 750; this.headerHeight = (rect.height / this.screenWidth) * 750;
this.headerHeightInited = true;
} }
}).exec(); }).exec();
}, },