Commit 51985c71 by yancanhua

fix: 小程序描点定位开发

1 parent 1fab3bbb
<template> <template>
<page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta> <page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
<view class="car-detail-container" v-if="auctionVehicle"> <view class="car-detail-container" v-if="auctionVehicle">
<view class="header-anchor">
<view class="header-anchor-list" :class="{ headerActive: currentAnchorId === 'section1' }" @click="scrollToSection('section1')">
车辆档案
<view v-if="currentAnchorId === 'section1'" class="header-anchor-absolute"></view>
</view>
<view class="header-anchor-list" :class="{ headerActive: currentAnchorId === 'section2' }" @click="scrollToSection('section2')">
车况描述
<view v-if="currentAnchorId === 'section2'" class="header-anchor-absolute"></view>
</view>
<view class="header-anchor-list" :class="{ headerActive: currentAnchorId === 'section3' }" @click="scrollToSection('section3')">
检测报告
<view v-if="currentAnchorId === 'section3'" class="header-anchor-absolute"></view>
</view>
<view class="header-anchor-list" :class="{ headerActive: currentAnchorId === 'section4' }" @click="scrollToSection('section4')">
车辆图片
<view v-if="currentAnchorId === 'section4'" class="header-anchor-absolute"></view>
</view>
<view class="header-anchor-list" :class="{ headerActive: currentAnchorId === 'section5' }" @click="scrollToSection('section5')">
协议规则
<view v-if="currentAnchorId === 'section5'" class="header-anchor-absolute"></view>
</view>
</view>
<!-- 页面头部 --> <!-- 页面头部 -->
<!-- <view class="page-header">--> <!-- <view class="page-header">-->
<!-- &lt;!&ndash; 搜索框 &ndash;&gt;--> <!-- &lt;!&ndash; 搜索框 &ndash;&gt;-->
...@@ -82,6 +105,7 @@ ...@@ -82,6 +105,7 @@
</view> --> </view> -->
<!-- 车辆基本参数 --> <!-- 车辆基本参数 -->
<section id="section1">
<view class="section-card" v-if="auctionVehicle"> <view class="section-card" v-if="auctionVehicle">
<view class="section-title">车辆档案</view> <view class="section-title">车辆档案</view>
<view class="params-row"> <view class="params-row">
...@@ -114,17 +138,19 @@ ...@@ -114,17 +138,19 @@
<text class="config-tip">*过户次数、年检到期、交强险到期、钥匙、是否有抵押、电池购买方式均为车主口述</text> <text class="config-tip">*过户次数、年检到期、交强险到期、钥匙、是否有抵押、电池购买方式均为车主口述</text>
<van-button type="default" round block @click="navigateTo('/module/auction/AuctionVehicleDetail?aucvehId=' + auctionVehicle?.aucvehId)">查看完整车辆信息</van-button> <van-button type="default" round block @click="navigateTo('/module/auction/AuctionVehicleDetail?aucvehId=' + auctionVehicle?.aucvehId)">查看完整车辆信息</van-button>
</view> </view>
</section>
<!-- 车况描述 --> <!-- 车况描述 -->
<section id="section2">
<view class="section-card"> <view class="section-card">
<view class="section-title">车况描述</view> <view class="section-title">车况描述</view>
<view class="description-content"> <view class="description-content">
<text>{{ vehicle.historyCondition.conditionDescription }}</text> <text>{{ vehicle.historyCondition.conditionDescription }}</text>
</view> </view>
</view> </view>
</section>
<!-- 检测报告 -->
<!-- 车辆配置 --> <section id="section3">
<view class="section-card"> <view class="section-card">
<view class="section-title">检测报告</view> <view class="section-title">检测报告</view>
<van-row :gutter="12"> <van-row :gutter="12">
...@@ -142,9 +168,10 @@ ...@@ -142,9 +168,10 @@
</van-col> </van-col>
</van-row> </van-row>
</view> </view>
</section>
<!-- 车辆图片展示 --> <!-- 车辆图片展示 -->
<section id="section4">
<view class="section-card"> <view class="section-card">
<view class="section-title">车辆图片</view> <view class="section-title">车辆图片</view>
<view style="margin-bottom: 6px" v-if="albums.length>0"> <view style="margin-bottom: 6px" v-if="albums.length>0">
...@@ -161,8 +188,10 @@ ...@@ -161,8 +188,10 @@
<uni-icons type="right" size="14" color="#999"/> <uni-icons type="right" size="14" color="#999"/>
</view> </view>
</view> </view>
</section>
<!-- 协议规则 --> <!-- 协议规则 -->
<section id="section5">
<view class="protocolBox" > <view class="protocolBox" >
<view class="protocolBox-title">协议规则</view> <view class="protocolBox-title">协议规则</view>
<view class="protocolBox-content" > <view class="protocolBox-content" >
...@@ -171,6 +200,7 @@ ...@@ -171,6 +200,7 @@
<text class="protocolBox-rule" @click="navigateToAgreement('VIOLATION')">《违约扣款规则》</text> <text class="protocolBox-rule" @click="navigateToAgreement('VIOLATION')">《违约扣款规则》</text>
</view> </view>
</view> </view>
</section>
<view :style="{ height: auctionVehicle.auction.auctionMode == 2 ? '146px' : '60px' }"></view> <view :style="{ height: auctionVehicle.auction.auctionMode == 2 ? '146px' : '60px' }"></view>
</view> </view>
...@@ -338,6 +368,16 @@ export default class AuctionVehiclePage extends Vue { ...@@ -338,6 +368,16 @@ export default class AuctionVehiclePage extends Vue {
show = false; show = false;
/** /**
* 当前激活的锚点ID
*/
currentAnchorId = 'section1';
/**
* 各个锚点的位置信息
*/
anchorPositions: any = {};
/**
* 距开拍剩余时间 * 距开拍剩余时间
*/ */
bidStartRemaining = 0; bidStartRemaining = 0;
...@@ -487,6 +527,7 @@ export default class AuctionVehiclePage extends Vue { ...@@ -487,6 +527,7 @@ export default class AuctionVehiclePage extends Vue {
onShow((option) => { onShow((option) => {
this.loadData(); this.loadData();
this.loadBidInfo(); this.loadBidInfo();
this.updateAnchorPositions();
}); });
onUnload(() => { onUnload(() => {
this.stopFetchOrderState(); this.stopFetchOrderState();
...@@ -528,6 +569,26 @@ export default class AuctionVehiclePage extends Vue { ...@@ -528,6 +569,26 @@ export default class AuctionVehiclePage extends Vue {
async onPullDownRefresh() { async onPullDownRefresh() {
this.loadData().finally(() => uni.stopPullDownRefresh()); this.loadData().finally(() => uni.stopPullDownRefresh());
this.loadBidInfo(); this.loadBidInfo();
this.updateAnchorPositions();
}
/**
* 监听页面滚动
*/
@Hook('onPageScroll')
onPageScroll(e: any) {
const scrollTop = e.scrollTop + 47; // 加上头部锚点的高度
// 遍历所有锚点位置,找到当前滚动位置对应的锚点
let currentSection = 'section1';
const sections = ['section1', 'section2', 'section3', 'section4', 'section5'];
for (let i = sections.length - 1; i >= 0; i--) {
const sectionId = sections[i];
if (this.anchorPositions[sectionId] && scrollTop >= this.anchorPositions[sectionId]) {
currentSection = sectionId;
break;
}
}
this.currentAnchorId = currentSection;
} }
loadData(): Promise<void> { loadData(): Promise<void> {
...@@ -550,6 +611,12 @@ export default class AuctionVehiclePage extends Vue { ...@@ -550,6 +611,12 @@ export default class AuctionVehiclePage extends Vue {
} }
} }
} }
// 数据加载完成后,延迟更新锚点位置,确保 DOM 已渲染
this.$nextTick(() => {
setTimeout(() => {
this.updateAnchorPositions();
}, 300);
});
return Promise.resolve(); return Promise.resolve();
}); });
} }
...@@ -856,6 +923,43 @@ export default class AuctionVehiclePage extends Vue { ...@@ -856,6 +923,43 @@ export default class AuctionVehiclePage extends Vue {
}; };
} }
/**
* 滚动到指定锚点
* @param sectionId 锚点ID
*/
scrollToSection(sectionId: string) {
// 使用 selector 方式滚动,更准确
uni.pageScrollTo({
selector: `#${sectionId}`,
offset: -47, // 偏移量,减去头部锚点的高度
duration: 300
});
// 延迟更新当前激活的锚点
setTimeout(() => {
this.currentAnchorId = sectionId;
}, 300);
}
/**
* 更新所有锚点的位置信息
*/
updateAnchorPositions() {
const sections = ['section1', 'section2', 'section3', 'section4', 'section5'];
const query = uni.createSelectorQuery();
sections.forEach(sectionId => {
query.select(`#${sectionId}`).boundingClientRect();
});
query.exec((res) => {
sections.forEach((sectionId, index) => {
if (res[index]) {
this.anchorPositions[sectionId] = res[index].top;
}
});
});
}
} }
</script> </script>
...@@ -910,6 +1014,43 @@ export default class AuctionVehiclePage extends Vue { ...@@ -910,6 +1014,43 @@ export default class AuctionVehiclePage extends Vue {
margin-bottom: 60px; margin-bottom: 60px;
} }
.header-anchor{
position: fixed;
top: -1px;
left: 0;
width: 100%;
height: 47px;
z-index: 99;
background: #ffffff;
}
.header-anchor-list{
width: 20%;
height: 47px;
line-height: 47px;
color: #333333;
font-size: 14px;
float: left;
text-align: center;
position: relative;
}
.header-anchor-absolute {
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 0;
width: 16px;
height: 3px;
border-radius: 1.5px;
background: #185efe;
}
.headerActive{
color: #333333;
font-size: 16px;
}
/* 页面头部样式 */ /* 页面头部样式 */
.page-header { .page-header {
display: flex; display: flex;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!