商品详情轮播图及评价图点击预览功能

This commit is contained in:
yangdanqi 2022-05-01 18:45:54 +08:00
parent 3918c52643
commit 4f1d542908
2 changed files with 37 additions and 10 deletions

View File

@ -19,7 +19,7 @@
</view> </view>
<view class="grid flex-sub padding-lr col-3 grid-square" v-if="reviewer.picList"> <view class="grid flex-sub padding-lr col-3 grid-square" v-if="reviewer.picList">
<view class="bg-img" :style="'background-image:url(' + item.url + ');'" <view class="bg-img" :style="'background-image:url(' + item.url + ');'"
v-for="(item, index) in reviewer.picList" :key="index" v-if="index < 3"> v-for="(item, index) in reviewer.picList" :key="index" v-if="index < 3" :data-url="item.url" :data-imgs="reviewer.picList" @click="viewImage($event)">
</view> </view>
</view> </view>
</view> </view>
@ -42,7 +42,18 @@
} }
}, },
methods: { methods: {
viewImage(e) {
let imgList = e.currentTarget.dataset.imgs;
let curUrl = e.currentTarget.dataset.url;
let picList = [];
for(let i = 0; i < imgList.length; i++) {
picList.push(imgList[i].url);
}
uni.previewImage({
urls: picList,
current: curUrl
});
}
} }
} }
</script> </script>

View File

@ -17,7 +17,7 @@
</uni-transition> </uni-transition>
<!-- 轮播图视频 --> <!-- 轮播图视频 -->
<swiper class="screen-swiper" @change="changeSwiper"> <swiper class="screen-swiper" @change="changeSwiper">
<swiper-item v-for="(item,index) in swiperList" :key="item.id" @click="pauseVideo($event, item)"> <swiper-item v-for="(item,index) in swiperList" :key="item.id" @click="clickSwiper($event, item)">
<image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image> <image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
<video v-if="item.type=='video'" id="productVideo" :src="item.url" :controls="true" :autoplay="false" <video v-if="item.type=='video'" id="productVideo" :src="item.url" :controls="true" :autoplay="false"
:show-center-play-btn="true" :show-fullscreen-btn="false"></video> :show-center-play-btn="true" :show-fullscreen-btn="false"></video>
@ -177,7 +177,8 @@
ifShowPageMeta: false, ifShowPageMeta: false,
orderNow: false, orderNow: false,
totalPickCount: 0, totalPickCount: 0,
ifHasCsMsg: true ifHasCsMsg: true,
swiperPicUrls: []
} }
}, },
onLoad() { onLoad() {
@ -204,6 +205,11 @@
this.reviewers = productDetail.reviewers; this.reviewers = productDetail.reviewers;
this.productDetailImgUrl = productDetail.productDetailImgUrl; this.productDetailImgUrl = productDetail.productDetailImgUrl;
this.shopInfo = productDetail.shopInfo; this.shopInfo = productDetail.shopInfo;
for (let i = 0; i < this.swiperList.length; i++) {
if (this.swiperList[i].type === 'image') {
this.swiperPicUrls.push(this.swiperList[i].url);
}
}
}, },
bindEvent() { bindEvent() {
uni.$on('product-detail_add2Cart', this.add2Cart); uni.$on('product-detail_add2Cart', this.add2Cart);
@ -217,10 +223,20 @@
showAllSpecs() { showAllSpecs() {
this.isShowAllSpecs = !this.isShowAllSpecs; this.isShowAllSpecs = !this.isShowAllSpecs;
}, },
pauseVideo(e, item) { clickSwiper(e, item) {
if (item.type !== 'video') { if (item.type === 'image') {
return; this.viewImage(item.url);
} else if (item.type === 'video') {
this.pauseVideo(e);
} }
},
viewImage(url) {
uni.previewImage({
urls: this.swiperPicUrls,
current: url
});
},
pauseVideo(e) {
if (this.productVideoPlaying) { if (this.productVideoPlaying) {
this.productVideoContext.pause(); this.productVideoContext.pause();
} else { } else {