refactor(merch/detail): 优化商品详情页头部高度初始化逻辑
1. 移除冗余的headerHeightInited状态和监听逻辑 2. 提取获取商品详情的逻辑为单独getMerch方法 3. 移除initHeaderHeight的延迟定时器并修复top样式值
This commit is contained in:
@@ -322,23 +322,27 @@ export default {
|
|||||||
return {
|
return {
|
||||||
headerHeight: 320,
|
headerHeight: 320,
|
||||||
screenWidth: uni.getSystemInfoSync().windowWidth,
|
screenWidth: uni.getSystemInfoSync().windowWidth,
|
||||||
headerHeightInited: false,
|
|
||||||
changeStyleDebounce: null
|
changeStyleDebounce: null
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mixins: [list],
|
mixins: [list],
|
||||||
watch: {
|
|
||||||
'merch.desc': {
|
|
||||||
handler() {
|
|
||||||
if (!this.headerHeightInited) {
|
|
||||||
this.$nextTick(() => {
|
|
||||||
this.initHeaderHeight();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
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() {
|
showFullDesc() {
|
||||||
if (this.merch.desc) {
|
if (this.merch.desc) {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
@@ -349,15 +353,12 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
initHeaderHeight() {
|
initHeaderHeight() {
|
||||||
setTimeout(() => {
|
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();
|
|
||||||
}, 100);
|
|
||||||
},
|
},
|
||||||
changeListStyle() {
|
changeListStyle() {
|
||||||
if (this.changeStyleDebounce) clearTimeout(this.changeStyleDebounce);
|
if (this.changeStyleDebounce) clearTimeout(this.changeStyleDebounce);
|
||||||
@@ -377,8 +378,8 @@ export default {
|
|||||||
@import './public/css/list.scss';
|
@import './public/css/list.scss';
|
||||||
</style>
|
</style>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
view.head-wrap {
|
.head-wrap {
|
||||||
top: -1 !important;
|
top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.merch-image-wrap {
|
.merch-image-wrap {
|
||||||
|
|||||||
Reference in New Issue
Block a user