refactor(merch/detail): 优化商品详情页头部高度初始化逻辑

1. 移除冗余的headerHeightInited状态和监听逻辑
2. 提取获取商品详情的逻辑为单独getMerch方法
3. 移除initHeaderHeight的延迟定时器并修复top样式值
This commit is contained in:
2026-05-29 14:47:58 +08:00
parent 3781e54a32
commit 6745f2093e

View File

@@ -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) {
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();
});
}
}
}
});
},
methods: {
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);
},
changeListStyle() {
if (this.changeStyleDebounce) clearTimeout(this.changeStyleDebounce);
@@ -377,8 +378,8 @@ export default {
@import './public/css/list.scss';
</style>
<style scoped>
view.head-wrap {
top: -1 !important;
.head-wrap {
top: 0;
}
.merch-image-wrap {