From c50d6627b08565c0de46f29943bb02869315a4ae Mon Sep 17 00:00:00 2001 From: Hakadao Date: Mon, 20 May 2024 18:26:41 +0800 Subject: [PATCH] refactor(VideoCard): update video card props (#777) * refactor: update video card props * refactor(VideoCard): rename `uri` to `url` * chore(VideoCard): fix typo in comment --- src/components/VideoCard/VideoCard.vue | 198 +++++++----------- .../views/Favorites/Favorites.vue | 28 +-- .../views/Home/components/Following.vue | 24 ++- .../views/Home/components/ForYou.vue | 68 +++--- .../views/Home/components/Ranking.vue | 31 +-- .../Home/components/SubscribedSeries.vue | 26 +-- .../views/Home/components/Trending.vue | 30 +-- 7 files changed, 192 insertions(+), 213 deletions(-) diff --git a/src/components/VideoCard/VideoCard.vue b/src/components/VideoCard/VideoCard.vue index cf64b1cd2b..1eec9248b8 100644 --- a/src/components/VideoCard/VideoCard.vue +++ b/src/components/VideoCard/VideoCard.vue @@ -7,8 +7,20 @@ import { calcCurrentTime, calcTimeSince, numFormatter } from '~/utils/dataFormat import { getCSRF, removeHttpFromUrl } from '~/utils/main' import Tooltip from '../Tooltip.vue' +import VideoCardSkeleton from './VideoCardSkeleton.vue' interface Props { + skeleton?: boolean + video?: Video + showWatcherLater?: boolean + horizontal?: boolean + showPreview?: boolean + moreBtn?: boolean + moreBtnActive?: boolean + removed?: boolean +} + +interface Video { id: number duration?: number durationStr?: string @@ -17,7 +29,7 @@ interface Props { cover: string author?: string authorFace?: string - /** If you set the `authorUrl`, clicking the author's name or avatar will navigate to this url */ + /** After set the `authorUrl`, clicking the author's name or avatar will navigate to this url. It won't be affected by mid */ authorUrl?: string mid?: number view?: number @@ -28,25 +40,19 @@ interface Props { capsuleText?: string bvid?: string aid?: number - uri?: string + /** After set the `url`, clicking the video will navigate to this url. It won't be affected by aid, bvid or epid */ + url?: string /** If you want to show preview video, you should set the cid value */ cid?: number epid?: number followed?: boolean - horizontal?: boolean tag?: string rank?: number - topRightContent?: boolean - showPreview?: boolean - moreBtn?: boolean - moreBtnActive?: boolean - removed?: boolean type?: 'horizontal' | 'vertical' | 'bangumi' } const props = withDefaults(defineProps(), { - topRightContent: true, - type: 'horizontal', + showWatcherLater: true, }) const emit = defineEmits<{ @@ -61,23 +67,27 @@ const api = useApiClient() const isClick = ref(false) const videoUrl = computed(() => { - if (!isClick.value) + if (!isClick.value || !props.video) return undefined - if (props.bvid || props.aid) - return `https://www.bilibili.com/video/${props.bvid ?? `av${props.aid}`}` - else if (props.epid) - return `https://www.bilibili.com/bangumi/play/ep${props.epid}` - else if (props.uri) - return props.uri + + if (props.video.url) + return props.video.url + else if (props.video.bvid || props.video.aid) + return `https://www.bilibili.com/video/${props.video.bvid ?? `av${props.video.aid}`}` + else if (props.video.epid) + return `https://www.bilibili.com/bangumi/play/ep${props.video.epid}` else return '' }) const authorJumpUrl = computed(() => { - if (props.authorUrl) - return props.authorUrl - else if (props.mid) - return `//space.bilibili.com/${props.mid}` + if (!props.video) + return + + if (props.video.authorUrl) + return props.video.authorUrl + else if (props.video.mid) + return `//space.bilibili.com/${props.video.mid}` else return '' }) @@ -97,11 +107,14 @@ const mouseLeaveTimeOut = ref() const previewVideoUrl = ref('') watch(() => isHover.value, (newValue) => { + if (!props.video) + return + if (props.showPreview && settings.value.enableVideoPreview) { - if (newValue && !previewVideoUrl.value && props.cid) { + if (newValue && !previewVideoUrl.value && props.video.cid) { api.video.getVideoPreview({ - bvid: props.bvid, - cid: props.cid, + bvid: props.video.bvid, + cid: props.video.cid, }).then((res: VideoPreviewResult) => { if (res.code === 0) previewVideoUrl.value = res.data.durl[0].url @@ -111,9 +124,12 @@ watch(() => isHover.value, (newValue) => { }) function toggleWatchLater() { + if (!props.video) + return + if (!isInWatchLater.value) { api.watchlater.saveToWatchLater({ - aid: props.id, + aid: props.video.id, csrf: getCSRF(), }) .then((res) => { @@ -123,7 +139,7 @@ function toggleWatchLater() { } else { api.watchlater.removeFromWatchLater({ - aid: props.id, + aid: props.video.id, csrf: getCSRF(), }) .then((res) => { @@ -185,7 +201,7 @@ function handleUndo() {