Browse Source

优化详情页面图片预览实现,与买蛋标签页保持一致以解决滑动卡顿问题

pull/1/head
徐飞洋 3 months ago
parent
commit
16ed98326d
  1. 12
      pages/goods-detail/goods-detail.js
  2. 57
      pages/goods-detail/goods-detail.wxml

12
pages/goods-detail/goods-detail.js

@ -209,7 +209,6 @@ Page({
// 预览图片 // 预览图片
previewImage(e) { previewImage(e) {
console.log('预览图片事件:', e);
const { urls, index } = e.currentTarget.dataset; const { urls, index } = e.currentTarget.dataset;
if (!urls || urls.length === 0) { if (!urls || urls.length === 0) {
wx.showToast({ wx.showToast({
@ -239,19 +238,15 @@ Page({
resetZoom() { resetZoom() {
this.setData({ this.setData({
scale: 1, scale: 1,
lastScale: 1,
offsetX: 0, offsetX: 0,
offsetY: 0, offsetY: 0,
lastScale: 1, initialTouch: null
startDistance: 0,
isScaling: false,
initialTouch: null,
lastTapTime: 0
}); });
}, },
// 图片预览切换 // 图片预览切换
onPreviewImageChange(e) { onPreviewImageChange(e) {
console.log('图片预览切换:', e);
this.setData({ this.setData({
previewImageIndex: e.detail.current previewImageIndex: e.detail.current
}); });
@ -261,7 +256,6 @@ Page({
// 处理图片点击事件(单击/双击判断) // 处理图片点击事件(单击/双击判断)
handleImageTap(e) { handleImageTap(e) {
console.log('图片点击事件:', e);
const currentTime = Date.now(); const currentTime = Date.now();
const lastTapTime = this.data.lastTapTime || 0; const lastTapTime = this.data.lastTapTime || 0;
@ -330,7 +324,6 @@ Page({
// 处理触摸移动事件 // 处理触摸移动事件
handleTouchMove(e) { handleTouchMove(e) {
console.log('触摸移动事件:', e);
const touches = e.touches; const touches = e.touches;
if (touches.length === 1 && this.data.initialTouch && this.data.scale !== 1) { if (touches.length === 1 && this.data.initialTouch && this.data.scale !== 1) {
@ -376,7 +369,6 @@ Page({
// 处理触摸结束事件 // 处理触摸结束事件
handleTouchEnd(e) { handleTouchEnd(e) {
console.log('触摸结束事件:', e);
this.setData({ this.setData({
isScaling: false, isScaling: false,
lastScale: this.data.scale, lastScale: this.data.scale,

57
pages/goods-detail/goods-detail.wxml

@ -145,38 +145,33 @@
</view> </view>
<!-- 图片预览弹窗 --> <!-- 图片预览弹窗 -->
<view class="image-preview-container" wx:if="{{showImagePreview}}"> <view class="image-preview-mask" wx:if="{{showImagePreview}}" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.9); display: flex; justify-content: center; align-items: center; z-index: 10001;" catchtouchmove="true">
<view class="preview-header"> <view style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center;">
<view class="preview-close" bindtap="closeImagePreview"> <swiper
<text class="close-icon">×</text> style="width: 100%; height: 100%;"
</view> current="{{previewImageIndex}}"
<view class="preview-indicator"> bindchange="onPreviewImageChange"
<text>{{previewImageIndex + 1}} / {{previewImageUrls.length}}</text> indicator-dots="true"
</view> indicator-color="rgba(255,255,255,0.5)"
</view> indicator-active-color="#fff">
<swiper <block wx:for="{{previewImageUrls}}" wx:key="*this">
class="preview-swiper" <swiper-item>
current="{{previewImageIndex}}"
bindchange="onPreviewImageChange"
>
<block wx:for="{{previewImageUrls}}" wx:key="index">
<swiper-item>
<view
class="preview-image-wrapper"
bindtap="handleImageTap"
bindtouchstart="handleTouchStart"
bindtouchmove="handleTouchMove"
bindtouchend="handleTouchEnd"
>
<image <image
src="{{item}}" src="{{item}}"
mode="aspectFit" mode="aspectFit"
class="preview-image" style="width: 100%; height: 100%; transform: scale({{scale}}) translate({{offsetX}}px, {{offsetY}}px); transition: {{isScaling ? 'none' : 'transform 0.3s'}};"
style="transform: scale({{scale}}) translate({{offsetX}}px, {{offsetY}}px); transform-origin: center center; transition: transform 0.1s ease-out;" bindtap="handleImageTap"
/> bindtouchstart="handleTouchStart"
</view> bindtouchmove="handleTouchMove"
</swiper-item> bindtouchend="handleTouchEnd"
</block> bindtouchcancel="handleTouchEnd"
</swiper> ></image>
</swiper-item>
</block>
</swiper>
<view style="position: absolute; top: 40rpx; right: 40rpx; color: white; font-size: 40rpx;">
<text bindtap="closeImagePreview" style="background: rgba(0,0,0,0.5); padding: 10rpx 20rpx; border-radius: 50%;">×</text>
</view>
</view>
</view> </view>
</view> </view>
Loading…
Cancel
Save