refactor(merch/detail): 优化商品详情页头部高度初始化逻辑
1. 移除冗余的headerHeightInited状态和监听逻辑 2. 提取获取商品详情的逻辑为单独getMerch方法 3. 移除initHeaderHeight的延迟定时器并修复top样式值
This commit is contained in:
@@ -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';
|
||||
</style>
|
||||
<style scoped>
|
||||
view.head-wrap {
|
||||
top: -1 !important;
|
||||
.head-wrap {
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.merch-image-wrap {
|
||||
|
||||
Reference in New Issue
Block a user