From 508d376adfa5d14c841139273a30c0e3d39799d4 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 6 Jul 2023 15:39:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E9=98=85=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=AD=98=E5=9C=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 23 +++++ src/components/cards/MediaCard.vue | 138 +++++++++++++++++++++++------ 2 files changed, 135 insertions(+), 26 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index bd59d978..2b490fdd 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -188,15 +188,38 @@ export interface Site { // 正在下载 export interface DownloadingInfo { + // HASH hash?: string + // 种子名称 title?: string + // 识别后的名称 name?: string + // 年份 year?: string + // SXXEXX season_episode?: string + // 大小 size?: number + // 下载进 度 progress?: number + // 状态 state?: string + // 下载速度 dlspeed?: string + // 上传速度 upspeed?: string + // 媒体信息 media: { [key: string]: any } } + + +export interface NotExistMediaInfo { + // 季 + season: number + // 剧集列表 + episodes: number[] + // 总集数 + total_episodes: number + // 开始集 + start_episode: number +} diff --git a/src/components/cards/MediaCard.vue b/src/components/cards/MediaCard.vue index d9b73292..e0bd41a4 100644 --- a/src/components/cards/MediaCard.vue +++ b/src/components/cards/MediaCard.vue @@ -2,7 +2,7 @@ import { formatSeason } from "@/@core/utils/formatters"; import api from "@/api"; import { doneNProgress, startNProgress } from "@/api/nprogress"; -import { MediaInfo, Subscribe, TmdbSeason } from "@/api/types"; +import { MediaInfo, NotExistMediaInfo, Subscribe, TmdbSeason } from "@/api/types"; import { useToast } from "vue-toast-notification"; // 输入参数 @@ -21,8 +21,8 @@ const isImageLoaded = ref(false); // 当前订阅状态 const isSubscribed = ref(false); -// 各季订阅状态 -const seasonsSubscribed = ref<{ [key: number]: boolean }>({}); +// 各季缺失状态:0-已存在 1-部分缺失 2-全部缺失 +const seasonsExisted = ref<{ [key: number]: number }>({}); // 订阅季弹窗 const subscribeSeasonDialog = ref(false); @@ -54,25 +54,45 @@ const handleAddSubscribe = async () => { // 检查是否多季 let season = props.media?.season; if (!season && props.media?.tmdb_id && props.media?.type == "电视剧") { - // TMDB且是电视剧 + // 可能有多季的电视剧 let seasons = await getMediaSeasons(); if (!seasons) { $toast.error(`${props.media?.title} 查询剧集信息失败!`); return; } + seasonInfos.value = seasons; + // 检查各季的缺失状态 + checkSeasonsExists(); if (seasons.length <= 1) { // 只有1季 - addSubscribe(); + if (!seasonsExisted.value[1]) { + $toast.warning(`${props.media?.title} 媒体库中已存在!`); + } else { + addSubscribe(); + } return; } - seasonInfos.value = seasons; - // 检查各季的订阅状态 - checkSeasonsSubscribe(); // 弹出季选择列表,支持多选 subscribeSeasonDialog.value = true; - } else { - // 电影或者只有1季的电视剧直接添加 + } else if (props.media?.type == "电视剧") { + // 只有1季的电视剧 + checkSeasonsExists(); + // 该季存在时提示 + if (!seasonsExisted.value[season || 1]) { + $toast.warning( + `${props.media?.title} ${formatSeason((season ?? 1).toString())} 媒体库中已存在!` + ); + return; + } addSubscribe(season); + } else { + // 电影 + let exists = await checkMovieExists(); + if (exists) { + $toast.warning(`${props.media?.title} 媒体库中已存在!`); + } else { + addSubscribe(); + } } }; @@ -182,20 +202,29 @@ const checkSubscribe = async (season: number = 0) => { return null; }; -// 检查所有季的订阅状态 -const checkSeasonsSubscribe = async () => { +// 检查所有季的缺失状态 +const checkSeasonsExists = async () => { // 开始处理 startNProgress(); try { - seasonInfos.value.forEach(async (season) => { - if (season.season_number === 0) { - return; - } - const result = await checkSubscribe(season.season_number); - if (result) { - seasonsSubscribed.value[season.season_number || 0] = true; - } + const result: NotExistMediaInfo[] = await api.post(`download/notexists`, { + title: props.media?.title, + type: props.media?.type, + tmdb_id: props.media?.tmdb_id, + year: props.media?.year, }); + if (result) { + result.forEach((item) => { + // 0-已存在 1-部分缺失 2-全部缺失 + let state = 0; + if (item.episodes.length == 0) { + state = 2; + } else if (item.episodes.length < item.total_episodes) { + state = 1; + } + seasonsExisted.value[item.season] = state; + }); + } } catch (error) { console.error(error); } @@ -203,6 +232,25 @@ const checkSeasonsSubscribe = async () => { doneNProgress(); }; +// 检查电影是否存在 +const checkMovieExists = async () => { + try { + const result: NotExistMediaInfo[] = await api.post(`download/notexists`, { + title: props.media?.title, + type: props.media?.type, + tmdb_id: props.media?.tmdb_id, + year: props.media?.year, + }); + if (!result || result.length === 0) { + // 没有缺失的就是存在 + return true; + } + return false; + } catch (error) { + console.error(error); + } +}; + // 查询TMDB的所有季信息 const getMediaSeasons = async () => { try { @@ -235,6 +283,36 @@ const getDetailLink = () => { return link; }; +// 计算存在状态的颜色 +const getExistColor = (season: number) => { + let state = seasonsExisted.value[season]; + if (!state) { + return "success"; + } + if (state === 1) { + return "warning"; + } else if (state === 2) { + return "error"; + } else { + return "success"; + } +}; + +// 计算存在状态的文本 +const getExistText = (season: number) => { + let state = seasonsExisted.value[season]; + if (!state) { + return "已存在"; + } + if (state === 1) { + return "部分缺失"; + } else if (state === 2) { + return "缺失"; + } else { + return "已存在"; + } +}; + // 打开详情页 const openDetailWindow = () => { window.open(getDetailLink(), "_blank"); @@ -328,7 +406,11 @@ const seasonsSelected = ref([]); - + ([]); fixed-header show-select :items-per-page="100" - hide-default-footer + density="compact" > - + @@ -351,11 +437,11 @@ const seasonsSelected = ref([]);