Browse Source

修复goods页面视频不显示问题

pull/9/head
Default User 2 months ago
parent
commit
e913b8572e
  1. 27
      pages/goods/index.js
  2. 13
      pages/goods/index.wxml

27
pages/goods/index.js

@ -1,6 +1,21 @@
// pages/goods/index.js
const API = require('../../utils/api.js')
// 媒体类型判断函数
function isVideoUrl(url) {
if (!url || typeof url !== 'string') {
return false;
}
const lowerUrl = url.toLowerCase();
const videoExtensions = ['.mp4', '.mov', '.avi', '.wmv', '.flv', '.webm', '.m4v', '.3gp'];
for (const ext of videoExtensions) {
if (lowerUrl.endsWith(ext)) {
return true;
}
}
return false;
}
Page({
// 分享给朋友/群聊
onShareAppMessage() {
@ -286,10 +301,20 @@ Page({
const creatorName = item.seller?.nickName || item.seller?.sellerNickName || '未知'
console.log('creatorName获取结果:', creatorName)
// 处理媒体URL,添加类型信息
const imageUrls = item.imageUrls || item.images || []
const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls]
const mediaItems = formattedImageUrls.map(url => ({
url: url,
type: isVideoUrl(url) ? 'video' : 'image'
}))
return {
...item,
formattedCreatedAt: this.formatDateTime(item.created_at || item.createTime),
creatorName: creatorName
creatorName: creatorName,
imageUrls: formattedImageUrls,
mediaItems: mediaItems
}
})

13
pages/goods/index.wxml

@ -83,7 +83,20 @@
>
<view class="product-card">
<view class="product-image-wrapper">
<video
wx:if="{{item.mediaItems && item.mediaItems.length > 0 && item.mediaItems[0].type === 'video'}}"
class="product-image"
src="{{item.mediaItems[0].url}}"
mode="aspectFill"
show-center-play-btn="{{true}}"
show-play-btn="{{false}}"
controls="{{true}}"
autoplay="{{true}}"
loop="{{true}}"
muted="{{true}}"
></video>
<image
wx:else
class="product-image"
src="{{item.imageUrls && item.imageUrls.length > 0 ? item.imageUrls[0] : '/images/default-avatar.png'}}"
mode="aspectFill"

Loading…
Cancel
Save