feat(图片预览): 添加图片预览功能并优化视频播放重置逻辑
添加van-image-preview组件实现图片预览功能,包括图片列表管理和索引控制 优化视频播放器停止逻辑,增加播放进度重置到开始位置 修复长文本显示问题,添加word-break和word-wrap样式
Showing
1 changed file
with
46 additions
and
0 deletions
| ... | @@ -177,6 +177,14 @@ | ... | @@ -177,6 +177,14 @@ |
| 177 | </div> | 177 | </div> |
| 178 | </div> | 178 | </div> |
| 179 | </van-popup> | 179 | </van-popup> |
| 180 | + | ||
| 181 | + <!-- 图片预览弹窗 --> | ||
| 182 | + <van-image-preview | ||
| 183 | + v-model:show="imageShow" | ||
| 184 | + :images="imageList" | ||
| 185 | + :start-position="imageIndex" | ||
| 186 | + :show-index="true" | ||
| 187 | + /> | ||
| 180 | </div> | 188 | </div> |
| 181 | </template> | 189 | </template> |
| 182 | 190 | ||
| ... | @@ -233,6 +241,9 @@ const videoUrl = ref('') | ... | @@ -233,6 +241,9 @@ const videoUrl = ref('') |
| 233 | const videoCover = ref('') | 241 | const videoCover = ref('') |
| 234 | const isVideoPlaying = ref(false) | 242 | const isVideoPlaying = ref(false) |
| 235 | const videoPlayerRef = ref(null) | 243 | const videoPlayerRef = ref(null) |
| 244 | +const imageShow = ref(false) | ||
| 245 | +const imageList = ref([]) | ||
| 246 | +const imageIndex = ref(0) | ||
| 236 | 247 | ||
| 237 | /** | 248 | /** |
| 238 | * 返回上一页 | 249 | * 返回上一页 |
| ... | @@ -452,6 +463,10 @@ const onClickPreview = (file, detail) => { | ... | @@ -452,6 +463,10 @@ const onClickPreview = (file, detail) => { |
| 452 | } else if (activeType.value === 'video' || isVideoFile(fileName)) { | 463 | } else if (activeType.value === 'video' || isVideoFile(fileName)) { |
| 453 | console.log('准备播放视频:', fileName, fileUrl) | 464 | console.log('准备播放视频:', fileName, fileUrl) |
| 454 | showVideo(fileName, fileUrl) | 465 | showVideo(fileName, fileUrl) |
| 466 | + } else if (activeType.value === 'image' || isImageFile(fileName)) { | ||
| 467 | + console.log('图片预览由van-uploader组件处理,跳过文件列表点击预览') | ||
| 468 | + // 图片预览由van-uploader的@click-preview事件处理,避免重复弹出 | ||
| 469 | + return | ||
| 455 | } else { | 470 | } else { |
| 456 | console.log('该文件类型不支持预览,文件名:', fileName, '打卡类型:', activeType.value) | 471 | console.log('该文件类型不支持预览,文件名:', fileName, '打卡类型:', activeType.value) |
| 457 | showToast('该文件类型不支持预览') | 472 | showToast('该文件类型不支持预览') |
| ... | @@ -534,6 +549,9 @@ const previewFile = (item) => { | ... | @@ -534,6 +549,9 @@ const previewFile = (item) => { |
| 534 | } else if (activeType.value === 'video' || isVideoFile(fileName)) { | 549 | } else if (activeType.value === 'video' || isVideoFile(fileName)) { |
| 535 | console.log('准备播放视频:', fileName, fileUrl) | 550 | console.log('准备播放视频:', fileName, fileUrl) |
| 536 | showVideo(fileName, fileUrl) | 551 | showVideo(fileName, fileUrl) |
| 552 | + } else if (activeType.value === 'image' || isImageFile(fileName)) { | ||
| 553 | + console.log('准备预览图片:', fileName, fileUrl) | ||
| 554 | + showImage(fileUrl) | ||
| 537 | } else { | 555 | } else { |
| 538 | console.log('该文件类型不支持预览,文件名:', fileName, '打卡类型:', activeType.value) | 556 | console.log('该文件类型不支持预览,文件名:', fileName, '打卡类型:', activeType.value) |
| 539 | showToast('该文件类型不支持预览') | 557 | showToast('该文件类型不支持预览') |
| ... | @@ -561,6 +579,16 @@ const isVideoFile = (fileName) => { | ... | @@ -561,6 +579,16 @@ const isVideoFile = (fileName) => { |
| 561 | } | 579 | } |
| 562 | 580 | ||
| 563 | /** | 581 | /** |
| 582 | + * 判断是否为图片文件 | ||
| 583 | + * @param {string} fileName - 文件名 | ||
| 584 | + * @returns {boolean} | ||
| 585 | + */ | ||
| 586 | +const isImageFile = (fileName) => { | ||
| 587 | + const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg'] | ||
| 588 | + return imageExtensions.some(ext => fileName.toLowerCase().includes(ext)) | ||
| 589 | +} | ||
| 590 | + | ||
| 591 | +/** | ||
| 564 | * 显示音频播放器 | 592 | * 显示音频播放器 |
| 565 | * @param {string} title - 音频标题 | 593 | * @param {string} title - 音频标题 |
| 566 | * @param {string} url - 音频URL | 594 | * @param {string} url - 音频URL |
| ... | @@ -586,6 +614,17 @@ const showVideo = (title, url, cover = '') => { | ... | @@ -586,6 +614,17 @@ const showVideo = (title, url, cover = '') => { |
| 586 | } | 614 | } |
| 587 | 615 | ||
| 588 | /** | 616 | /** |
| 617 | + * 显示图片预览 | ||
| 618 | + * @param {string} url - 图片URL | ||
| 619 | + * @param {number} index - 图片索引(可选) | ||
| 620 | + */ | ||
| 621 | +const showImage = (url, index = 0) => { | ||
| 622 | + imageList.value = [url] | ||
| 623 | + imageIndex.value = index | ||
| 624 | + imageShow.value = true | ||
| 625 | +} | ||
| 626 | + | ||
| 627 | +/** | ||
| 589 | * 开始播放视频 | 628 | * 开始播放视频 |
| 590 | */ | 629 | */ |
| 591 | const startVideoPlay = async () => { | 630 | const startVideoPlay = async () => { |
| ... | @@ -616,6 +655,11 @@ const handleVideoPause = () => { | ... | @@ -616,6 +655,11 @@ const handleVideoPause = () => { |
| 616 | const stopVideoPlay = () => { | 655 | const stopVideoPlay = () => { |
| 617 | if (videoPlayerRef.value && typeof videoPlayerRef.value.pause === 'function') { | 656 | if (videoPlayerRef.value && typeof videoPlayerRef.value.pause === 'function') { |
| 618 | videoPlayerRef.value.pause() | 657 | videoPlayerRef.value.pause() |
| 658 | + // 重置视频播放进度到开始位置 | ||
| 659 | + const player = videoPlayerRef.value.getPlayer() | ||
| 660 | + if (player && typeof player.currentTime === 'function') { | ||
| 661 | + player.currentTime(0) | ||
| 662 | + } | ||
| 619 | } | 663 | } |
| 620 | isVideoPlaying.value = false | 664 | isVideoPlaying.value = false |
| 621 | } | 665 | } |
| ... | @@ -929,6 +973,8 @@ onMounted(async () => { | ... | @@ -929,6 +973,8 @@ onMounted(async () => { |
| 929 | color: #333; | 973 | color: #333; |
| 930 | overflow: hidden; | 974 | overflow: hidden; |
| 931 | text-overflow: ellipsis; | 975 | text-overflow: ellipsis; |
| 976 | + word-break: break-all; | ||
| 977 | + word-wrap: break-word; | ||
| 932 | // white-space: nowrap; | 978 | // white-space: nowrap; |
| 933 | } | 979 | } |
| 934 | 980 | ... | ... |
-
Please register or login to post a comment