Browse Source

动态计算遮挡和地图尺寸

zhaowenkang/feature-20251028181547-行情页面
zhaowenkang 1 month ago
parent
commit
fcb9eeac98
  1. 83
      pages/home/marketSituation.vue

83
pages/home/marketSituation.vue

@ -39,10 +39,10 @@
</view> </view>
<!-- 可滚动内容区域 --> <!-- 可滚动内容区域 -->
<scroll-view class="content_scroll" scroll-y="true" :style="{ top: (iSMT + 136) + 'px' }">
<scroll-view class="content_scroll" scroll-y="true" :style="{ top: contentTopPosition + 'px' }">
<view class="content"> <view class="content">
<view class="map"> <view class="map">
<image src="/static/marketSituation-image/map.png" mode="aspectFill"></image>
<image src="/static/marketSituation-image/map.png" mode="widthFix"></image>
</view> </view>
<view class="global_index"> <view class="global_index">
<view class="global_index_title"> <view class="global_index_title">
@ -99,7 +99,7 @@
</template> </template>
<script setup> <script setup>
import { ref, onMounted } from 'vue'
import { ref, onMounted, watch, nextTick, computed } from 'vue'
import footerBar from '../../components/footerBar.vue' import footerBar from '../../components/footerBar.vue'
import IndexCard from '../../components/IndexCard.vue' import IndexCard from '../../components/IndexCard.vue'
@ -107,6 +107,7 @@ const type = ref('marketSituation')
const iSMT = ref(0) const iSMT = ref(0)
const searchValue = ref('') const searchValue = ref('')
const contentHeight = ref(0) const contentHeight = ref(0)
const headerHeight = ref(0) // header
// Tab // Tab
const channelData = ref([ const channelData = ref([
@ -126,6 +127,13 @@ const channelData = ref([
const pageIndex = ref(0) const pageIndex = ref(0)
const scrollToView = ref('') const scrollToView = ref('')
// contenttop
const contentTopPosition = computed(() => {
const statusBarHeight = iSMT.value || 0
const currentHeaderHeight = headerHeight.value > 0 ? headerHeight.value : 140
return statusBarHeight + currentHeaderHeight
})
// //
const showCountryModal = ref(false) const showCountryModal = ref(false)
const selectedCountry = ref('概况') const selectedCountry = ref('概况')
@ -335,20 +343,35 @@ onMounted(() => {
// //
iSMT.value = uni.getSystemInfoSync().statusBarHeight; iSMT.value = uni.getSystemInfoSync().statusBarHeight;
//
const systemInfo = uni.getSystemInfoSync()
const windowHeight = systemInfo.windowHeight
const statusBarHeight = systemInfo.statusBarHeight || 0
const headerHeight = 160 // headertab
const footerHeight = 100 //
contentHeight.value = windowHeight - statusBarHeight - headerHeight - footerHeight
// tab // tab
if (channelData.value.length > 0) { if (channelData.value.length > 0) {
pageIndex.value = 0 pageIndex.value = 0
scrollToView.value = 'nav' + channelData.value[0].id scrollToView.value = 'nav' + channelData.value[0].id
} }
// DOM
nextTick(() => {
// header
uni.createSelectorQuery().select('.header_fixed').boundingClientRect((rect) => {
if (rect) {
headerHeight.value = rect.height
console.log('Header实际高度:', headerHeight.value, 'px')
}
}).exec()
})
})
// headerHeightcontentHeight
watch(headerHeight, (newHeight) => {
if (newHeight > 0) {
const systemInfo = uni.getSystemInfoSync()
const windowHeight = systemInfo.windowHeight
const statusBarHeight = systemInfo.statusBarHeight || 0
const footerHeight = 100
contentHeight.value = windowHeight - statusBarHeight - newHeight - footerHeight
console.log('重新计算contentHeight:', contentHeight.value)
}
}) })
</script> </script>
@ -551,9 +574,7 @@ onMounted(() => {
} }
.map { .map {
flex: 1;
width: calc(100% - 60rpx); width: calc(100% - 60rpx);
min-height: 450rpx;
margin: 0 30rpx; margin: 0 30rpx;
display: flex; display: flex;
align-items: center; align-items: center;
@ -561,12 +582,40 @@ onMounted(() => {
background-color: #F3F3F3; background-color: #F3F3F3;
border-radius: 30rpx; border-radius: 30rpx;
border: 1rpx solid #E0E0E0; border: 1rpx solid #E0E0E0;
padding: 30rpx 20rpx;
box-sizing: border-box;
/* 设置最小高度保护,但允许内容撑开 */
min-height: 200rpx;
} }
.map image { .map image {
width: 90%;
height: 400rpx;
object-fit: contain;
width: 100%;
height: auto;
max-width: 100%;
display: block;
/* widthFix模式下,高度会自动按比例调整 */
/* 设置最大高度避免图片过大 */
max-height: 60vh;
/* 添加平滑过渡效果 */
transition: all 0.3s ease;
max-height: 60vh;
}
/* 响应式优化 */
@media screen and (max-width: 750rpx) {
.map {
margin: 0 20rpx;
width: calc(100% - 40rpx);
padding: 20rpx 15rpx;
}
}
@media screen and (max-width: 480rpx) {
.map {
margin: 0 15rpx;
width: calc(100% - 30rpx);
padding: 15rpx 10rpx;
}
} }
.static-footer { .static-footer {

Loading…
Cancel
Save