Skip to content

Commit 6ee72e9

Browse files
author
Taois
committed
feat: 列表图片传递到详情页面
1 parent 78e0022 commit 6ee72e9

File tree

8 files changed

+62
-15
lines changed

8 files changed

+62
-15
lines changed

dashboard/src/components/SearchResults.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ const handleVideoClick = (video) => {
390390
sourceRouteName: props.sourceRoute?.name,
391391
sourceRouteParams: JSON.stringify(props.sourceRoute?.params || {}),
392392
sourceRouteQuery: JSON.stringify(props.sourceRoute?.query || {}),
393-
fromSearch: 'true' // 标识来自搜索结果
393+
fromSearch: 'true', // 标识来自搜索结果
394+
// 添加来源图片信息,用于详情页图片备用
395+
sourcePic: video.vod_pic
394396
}
395397
});
396398
}

dashboard/src/components/VideoGrid.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ const handleVideoClick = async (video) => {
167167
// 添加来源页面信息
168168
sourceRouteName: props.sourceRoute?.name || '',
169169
sourceRouteParams: JSON.stringify(props.sourceRoute?.params || {}),
170-
sourceRouteQuery: JSON.stringify(props.sourceRoute?.query || {})
170+
sourceRouteQuery: JSON.stringify(props.sourceRoute?.query || {}),
171+
// 添加来源图片信息,用于详情页图片备用
172+
sourcePic: video.vod_pic
171173
}
172174
173175
router.push({

dashboard/src/components/actions/InputAction.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ export default {
555555
tempSiteExt: site.ext,
556556
// 标识从专项动作进入
557557
fromSpecialAction: 'true',
558-
actionType: '__detail__'
558+
actionType: '__detail__',
559+
// 添加来源图片信息,用于详情页图片备用(专项动作通常没有图片)
560+
sourcePic: ''
559561
}
560562
})
561563

dashboard/src/views/BookGallery.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@ const goToDetail = async (item) => {
429429
// 添加来源页面信息
430430
sourceRouteName: 'BookGallery',
431431
sourceRouteParams: JSON.stringify({}),
432-
sourceRouteQuery: JSON.stringify({})
432+
sourceRouteQuery: JSON.stringify({}),
433+
// 添加来源图片信息,用于详情页图片备用
434+
sourcePic: item.pic
433435
}
434436
})
435437

dashboard/src/views/Collection.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ const goToDetail = async (item) => {
378378
// 添加来源页面信息
379379
sourceRouteName: 'Collection',
380380
sourceRouteParams: JSON.stringify({}),
381-
sourceRouteQuery: JSON.stringify({})
381+
sourceRouteQuery: JSON.stringify({}),
382+
// 添加来源图片信息,用于详情页图片备用
383+
sourcePic: item.pic
382384
}
383385
})
384386

dashboard/src/views/History.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ const goToDetail = async (item) => {
372372
// 添加来源页面信息
373373
sourceRouteName: 'History',
374374
sourceRouteParams: JSON.stringify({}),
375-
sourceRouteQuery: JSON.stringify({})
375+
sourceRouteQuery: JSON.stringify({}),
376+
// 添加来源图片信息,用于详情页图片备用
377+
sourcePic: item.pic
376378
}
377379
})
378380
} catch (error) {

dashboard/src/views/Video.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ const handleRefreshList = () => {
441441
sourceRouteName: route.name,
442442
sourceRouteParams: JSON.stringify(route.params),
443443
sourceRouteQuery: JSON.stringify({ ...route.query, activeKey: currentActiveKey.value }),
444-
fromSearch: fromSearch // 标识是否来自搜索
444+
fromSearch: fromSearch, // 标识是否来自搜索
445+
// 添加来源图片信息,用于详情页图片备用
446+
sourcePic: video.vod_pic
445447
}
446448
});
447449
}
@@ -504,7 +506,9 @@ const handlePush = async (vodId) => {
504506
// 传递来源页面信息
505507
sourceRouteName: route.name,
506508
sourceRouteParams: JSON.stringify(route.params),
507-
sourceRouteQuery: JSON.stringify(route.query)
509+
sourceRouteQuery: JSON.stringify(route.query),
510+
// 添加来源图片信息,用于详情页图片备用(推送时通常没有图片)
511+
sourcePic: ''
508512
}
509513
});
510514

dashboard/src/views/VideoDetail.vue

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<a-card class="video-info-card" :class="{ 'collapsed-when-playing': showVideoPlayer || showBookReader }">
119119
<div class="video-header">
120120
<div class="video-poster" @click="showImageModal">
121-
<img :src="videoDetail.vod_pic" :alt="videoDetail.vod_name" @error="handleImageError" />
121+
<img :src="finalPosterImage" :alt="videoDetail.vod_name" @error="handleImageError" />
122122
<div class="poster-overlay">
123123
<icon-eye class="view-icon" />
124124
<span>查看大图</span>
@@ -318,6 +318,7 @@ const descriptionExpanded = ref(false)
318318
const currentRoute = ref(0)
319319
const currentEpisode = ref(0)
320320
const favoriteLoading = ref(false)
321+
const imageErrorCount = ref(0) // 图片加载失败计数器
321322
// 当前使用的站源信息(可能是全局站源或临时站源)
322323
const currentSiteInfo = ref({
323324
name: '',
@@ -413,6 +414,20 @@ const viewerOptions = ref({
413414
})
414415
415416
// 计算属性
417+
// 最终显示的海报图片
418+
const finalPosterImage = computed(() => {
419+
// 优先使用详情页接口返回的图片
420+
if (videoDetail.value?.vod_pic) {
421+
return videoDetail.value.vod_pic
422+
}
423+
// 其次使用来源页面传递的图片
424+
if (originalVideoInfo.value?.sourcePic) {
425+
return originalVideoInfo.value.sourcePic
426+
}
427+
// 最后使用默认图片
428+
return '/src/assets/default-poster.svg'
429+
})
430+
416431
const playRoutes = computed(() => {
417432
if (!videoDetail.value?.vod_play_from || !videoDetail.value?.vod_play_url) {
418433
return []
@@ -491,6 +506,9 @@ const loadVideoDetail = async () => {
491506
return
492507
}
493508
509+
// 重置图片错误计数器
510+
imageErrorCount.value = 0
511+
494512
// 从路由参数中获取原始视频信息
495513
originalVideoInfo.value = {
496514
id: route.params.id,
@@ -503,7 +521,8 @@ const loadVideoDetail = async () => {
503521
remarks: route.query.remarks || '',
504522
content: route.query.content || '',
505523
actor: route.query.actor || '',
506-
director: route.query.director || ''
524+
director: route.query.director || '',
525+
sourcePic: route.query.sourcePic || '' // 来源页面的图片,用于备用
507526
}
508527
509528
// 检查是否有当前站点
@@ -753,20 +772,32 @@ const handleImageError = (event) => {
753772
if (event.target.src.includes('default-poster.svg')) {
754773
return
755774
}
756-
// 使用BASE_URL确保在任何路由层级和部署环境下都能正确访问
775+
776+
imageErrorCount.value++
777+
778+
// 第一次失败:如果当前显示的是详情页接口返回的图片,尝试使用来源页面的图片
779+
if (imageErrorCount.value === 1 && originalVideoInfo.value?.sourcePic &&
780+
videoDetail.value?.vod_pic && event.target.src === videoDetail.value.vod_pic) {
781+
event.target.src = originalVideoInfo.value.sourcePic
782+
return
783+
}
784+
785+
// 第二次失败或没有备用图片:使用默认图片
757786
const basePath = import.meta.env.BASE_URL || '/'
758787
event.target.src = `${basePath}default-poster.svg`
759788
event.target.style.objectFit = 'contain'
760789
event.target.style.backgroundColor = '#f7f8fa'
761790
}
762791
763792
const showImageModal = () => {
764-
if (videoDetail.value?.vod_pic) {
793+
const currentImage = finalPosterImage.value
794+
// 只有当不是默认图片时才显示大图查看
795+
if (currentImage && !currentImage.includes('default-poster.svg')) {
765796
// 设置当前图片到 viewer,包含图片URL和名称
766-
viewerImages.value = [videoDetail.value.vod_pic]
797+
viewerImages.value = [currentImage]
767798
viewerImageData.value = [{
768-
src: videoDetail.value.vod_pic,
769-
name: videoDetail.value.vod_name || '未知标题'
799+
src: currentImage,
800+
name: videoDetail.value?.vod_name || originalVideoInfo.value?.name || '未知标题'
770801
}]
771802
772803
// 等待下一个 tick 后显示 viewer

0 commit comments

Comments
 (0)