diff --git a/components/goods-card/goods-card.js b/components/goods-card/goods-card.js index 1ad8696..307e067 100644 --- a/components/goods-card/goods-card.js +++ b/components/goods-card/goods-card.js @@ -19,7 +19,8 @@ Component({ }, data: { - isSoldOut: false + isSoldOut: false, + isVideo: false }, observers: { @@ -27,10 +28,28 @@ Component({ this.setData({ isSoldOut: status === 'sold_out' }); + }, + 'imageUrl': function(imageUrl) { + this.setData({ + isVideo: this.isVideoUrl(imageUrl) + }); } }, methods: { + // 判断是否为视频URL + isVideoUrl: function(url) { + if (!url) return false; + const videoExtensions = ['.mp4', '.mov', '.avi', '.wmv', '.flv', '.webm']; + const lowerUrl = url.toLowerCase(); + for (let ext of videoExtensions) { + if (lowerUrl.indexOf(ext) > -1) { + return true; + } + } + return false; + }, + onTap: function() { const goodsId = this.properties.id; if (goodsId) { diff --git a/components/goods-card/goods-card.wxml b/components/goods-card/goods-card.wxml index 26db4ae..60ca01b 100644 --- a/components/goods-card/goods-card.wxml +++ b/components/goods-card/goods-card.wxml @@ -1,12 +1,25 @@ + + + + 暂无图片 diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 2858639..1e84ed8 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -1891,7 +1891,10 @@ Page({ id: goodsDetail.id || '', name: goodsDetail.name || '', imageUrl: (goodsDetail.imageUrls && goodsDetail.imageUrls.length > 0) ? - (goodsDetail.imageUrls.find(url => !isVideoUrl(url)) || '') : '', + (goodsDetail.imageUrls.find(url => !isVideoUrl(url)) || + goodsDetail.imageUrls.find(url => isVideoUrl(url)) || + goodsDetail.videoCoverUrl || '') : + (goodsDetail.videoCoverUrl || ''), price: goodsDetail.price || '', region: goodsDetail.region || '', displaySpecification: goodsDetail.displaySpecification || goodsDetail.specification || goodsDetail.spec || goodsDetail.specs || '',