fix 搜索未传递类型的Bug

This commit is contained in:
jxxghp
2023-07-21 11:12:18 +08:00
parent f0438024d2
commit 7da9f53043
4 changed files with 161 additions and 161 deletions

View File

@@ -323,13 +323,17 @@ const openDetailWindow = () => {
// 开始搜索
const handleSearch = () => {
router.push(
`/resource/${
props.media?.tmdb_id
? `tmdb:${props.media?.tmdb_id}`
: `douban:${props.media?.douban_id}`
}`
);
router.push({
path: "/resource",
query: {
keyword: `${
props.media?.tmdb_id
? `tmdb:${props.media?.tmdb_id}`
: `douban:${props.media?.douban_id}`
}`,
type: props.media?.type,
},
});
};
// 装载时检查是否已订阅

View File

@@ -5,11 +5,13 @@ import TorrentCardListView from "@/views/discover/TorrentCardListView.vue";
const route = useRoute();
// 查询TMDBID或标题
const keyword = route.params?.keyword?.toString() ?? "";
const keyword = route.query?.keyword?.toString() ?? "";
// 查询类型
const type = route.query?.type?.toString() ?? "";
</script>
<template>
<div>
<TorrentCardListView :keyword="keyword" />
<TorrentCardListView :keyword="keyword" :type="type" />
</div>
</template>

View File

@@ -33,14 +33,6 @@ const router = createRouter({
requiresAuth: true,
},
},
{
path: 'resource/:keyword+',
component: () => import('../pages/resource.vue'),
props: true,
meta: {
requiresAuth: true,
},
},
{
path: 'subscribe-movie',
component: () => import('../pages/subscribe-movie.vue'),

View File

@@ -1,33 +1,36 @@
<script lang="ts" setup>
import { isIntersected } from '@/@core/utils'
import api from '@/api'
import { Context } from '@/api/types'
import TorrentCard from '@/components/cards/TorrentCard.vue'
import NoDataFound from '@/components/NoDataFound.vue'
import store from '@/store'
import { isIntersected } from "@/@core/utils";
import api from "@/api";
import { Context } from "@/api/types";
import TorrentCard from "@/components/cards/TorrentCard.vue";
import NoDataFound from "@/components/NoDataFound.vue";
import store from "@/store";
// 定义输入参数
const props = defineProps({
// 关键字或TMDBID
keyword: String,
})
// 类型
type: String,
});
// 数据列表
const dataList = ref<Context[]>([])
const dataList = ref<Context[]>([]);
// 分组后的数据列表
const groupedDataList = computed(() => {
return groupByTitleAndSize(dataList.value)
})
return groupByTitleAndSize(dataList.value);
});
// 是否刷新过
const isRefreshed = ref(false)
const isRefreshed = ref(false);
// 加载进度文本
const progressText = ref('')
const progressText = ref("");
// 加载进度
const progressValue = ref(0)
const progressValue = ref(0);
// 加载进度SSE
const progressEventSource = ref<EventSource>()
const progressEventSource = ref<EventSource>();
// 过滤表单
const filterForm = reactive({
@@ -43,216 +46,234 @@ const filterForm = reactive({
freeState: [] as string[],
// 质量
edition: [] as string[],
})
});
// 获取站点过滤选项
const getSiteFilterOptions = computed(() => {
const options: string[] = []
dataList.value.forEach(data => {
const options: string[] = [];
dataList.value.forEach((data) => {
if (data.torrent_info?.site_name && !options.includes(data.torrent_info?.site_name)) {
options.push(data.torrent_info?.site_name)
options.push(data.torrent_info?.site_name);
}
})
return options
})
});
return options;
});
// 获取季过滤选项
const getSeasonFilterOptions = computed(() => {
const options: string[] = []
dataList.value.forEach(data => {
if (data.meta_info.season_episode && !options.includes(data.meta_info.season_episode)) {
options.push(data.meta_info.season_episode)
const options: string[] = [];
dataList.value.forEach((data) => {
if (
data.meta_info.season_episode &&
!options.includes(data.meta_info.season_episode)
) {
options.push(data.meta_info.season_episode);
}
})
return options
})
});
return options;
});
// 获取制作组过滤选项
const getReleaseGroupFilterOptions = computed(() => {
const options: string[] = []
dataList.value.forEach(data => {
const options: string[] = [];
dataList.value.forEach((data) => {
if (data.meta_info.resource_team && !options.includes(data.meta_info.resource_team)) {
options.push(data.meta_info.resource_team)
options.push(data.meta_info.resource_team);
}
})
return options
})
});
return options;
});
// 获取视频编码过滤选项
const getVideoCodeFilterOptions = computed(() => {
const options: string[] = []
dataList.value.forEach(data => {
const options: string[] = [];
dataList.value.forEach((data) => {
if (data.meta_info.video_encode && !options.includes(data.meta_info.video_encode)) {
options.push(data.meta_info.video_encode)
options.push(data.meta_info.video_encode);
}
})
return options
})
});
return options;
});
// 获取促销状态过滤选项
const getFreeStateFilterOptions = computed(() => {
const options: string[] = []
dataList.value.forEach(data => {
if (data.torrent_info.volume_factor && !options.includes(data.torrent_info.volume_factor)) {
options.push(data.torrent_info.volume_factor)
const options: string[] = [];
dataList.value.forEach((data) => {
if (
data.torrent_info.volume_factor &&
!options.includes(data.torrent_info.volume_factor)
) {
options.push(data.torrent_info.volume_factor);
}
})
return options
})
});
return options;
});
// 获取质量过滤选项
const getEditionFilterOptions = computed(() => {
const options: string[] = []
dataList.value.forEach(data => {
const options: string[] = [];
dataList.value.forEach((data) => {
if (data.meta_info.edition && !options.includes(data.meta_info.edition)) {
options.push(data.meta_info.edition)
options.push(data.meta_info.edition);
}
})
return options
})
});
return options;
});
// 按过滤项过滤卡片
const filterTorrentsCard = (data: Context) => {
// 当前分组的所有数据
const items: Context[] = groupedDataList.value.get(`${data.torrent_info.title}_${data.torrent_info.size}`) ?? []
const items: Context[] =
groupedDataList.value.get(`${data.torrent_info.title}_${data.torrent_info.size}`) ??
[];
// 站点名称、促销状态
let site_names = []
let volume_factors = []
for (const { torrent_info } of items) {
site_names.push(torrent_info.site_name)
volume_factors.push(torrent_info.volume_factor)
let site_names = [];
let volume_factors = [];
for (const { torrent_info } of items) {
site_names.push(torrent_info.site_name);
volume_factors.push(torrent_info.volume_factor);
}
const { meta_info } = data
const { meta_info } = data;
// 季、制作组、视频编码
const { season_episode, resource_team, video_encode } = meta_info
const { season_episode, resource_team, video_encode } = meta_info;
// 站点过滤
if (filterForm.site.length > 0 && !isIntersected(filterForm.site, site_names)) {
return false
return false;
}
// 促销状态过滤
if (filterForm.freeState.length > 0 && !isIntersected(filterForm.freeState, volume_factors)) {
return false
if (
filterForm.freeState.length > 0 &&
!isIntersected(filterForm.freeState, volume_factors)
) {
return false;
}
// 季过滤
if (filterForm.season.length > 0 && !filterForm.season.includes(season_episode)) {
return false
return false;
}
// 制作组过滤
if (filterForm.releaseGroup.length > 0 && !filterForm.releaseGroup.includes(resource_team || '')) {
return false
if (
filterForm.releaseGroup.length > 0 &&
!filterForm.releaseGroup.includes(resource_team || "")
) {
return false;
}
// 视频编码过滤
if (filterForm.videoCode.length > 0 && !filterForm.videoCode.includes(video_encode || '')) {
return false
if (
filterForm.videoCode.length > 0 &&
!filterForm.videoCode.includes(video_encode || "")
) {
return false;
}
// 质量过滤
if (filterForm.edition.length > 0 && !filterForm.edition.includes(meta_info.edition)) {
return false
return false;
}
return true
}
return true;
};
// 获取订阅列表数据
const fetchData = async () => {
try {
let keyword = props.keyword?.toString() ?? ''
let keyword = props.keyword ?? "";
let mtype = props.type ?? "";
if (!keyword) {
// 查询上次搜索结果
dataList.value = await api.get('search/last')
dataList.value = await api.get("search/last");
} else {
startLoadingProgress()
startLoadingProgress();
// 优先按TMDBID精确查询
if (props.keyword?.startsWith('tmdb:') || props.keyword?.startsWith('douban:')) {
dataList.value = await api.get(`search/media/${props.keyword}`)
if (props.keyword?.startsWith("tmdb:") || props.keyword?.startsWith("douban:")) {
dataList.value = await api.get(`search/media/${props.keyword}`, {
params: {
mtype,
},
});
} else {
// 按标题模糊查询
dataList.value = await api.get(`search/title/${props.keyword}`)
dataList.value = await api.get(`search/title/${props.keyword}`);
}
stopLoadingProgress()
stopLoadingProgress();
}
isRefreshed.value = true
isRefreshed.value = true;
} catch (error) {
console.error(error)
console.error(error);
}
}
};
// 按标题和大小分组
const groupByTitleAndSize = (contextArray: Context[]): Map<string, Context[]> => {
const groupMap = new Map<string, Context[]>()
const groupMap = new Map<string, Context[]>();
for (const context of contextArray) {
const { torrent_info } = context
const key = `${torrent_info.title}_${torrent_info.size}`
const { torrent_info } = context;
const key = `${torrent_info.title}_${torrent_info.size}`;
if (groupMap.has(key)) {
// 已存在相同标题和大小的分组,将当前上下文信息添加到分组中
const group = groupMap.get(key)
group?.push(context)
const group = groupMap.get(key);
group?.push(context);
} else {
// 创建新的分组,并将当前上下文信息添加到分组中
groupMap.set(key, [context])
groupMap.set(key, [context]);
}
}
return groupMap
}
return groupMap;
};
// 获取每个分组的第一个数据
const getFirstContexts = computed(() => {
const firstContexts: Context[] = []
const firstContexts: Context[] = [];
groupedDataList.value.forEach(group => {
groupedDataList.value.forEach((group) => {
if (group.length > 0) {
firstContexts.push(group[0])
firstContexts.push(group[0]);
}
})
});
return firstContexts
})
return firstContexts;
});
// 使用SSE监听加载进度
const startLoadingProgress = () => {
progressText.value = '正在搜索,请稍候...'
const token = store.state.auth.token
progressText.value = "正在搜索,请稍候...";
const token = store.state.auth.token;
progressEventSource.value = new EventSource(
`${import.meta.env.VITE_API_BASE_URL}system/progress/search?token=${token}`,
)
progressEventSource.value.onmessage = event => {
const progress = JSON.parse(event.data)
`${import.meta.env.VITE_API_BASE_URL}system/progress/search?token=${token}`
);
progressEventSource.value.onmessage = (event) => {
const progress = JSON.parse(event.data);
if (progress) {
progressText.value = progress.text
progressValue.value = progress.value
progressText.value = progress.text;
progressValue.value = progress.value;
}
}
}
};
};
// 停止监听加载进度
const stopLoadingProgress = () => {
progressEventSource.value?.close()
}
progressEventSource.value?.close();
};
// 加载时获取数据
onBeforeMount(fetchData)
onBeforeMount(fetchData);
</script>
<template>
<VCard class="bg-transparent mb-3 pt-2 shadow-none">
<VRow>
<VCol
v-if="getSiteFilterOptions.length > 0"
cols="6"
md=""
>
<VCol v-if="getSiteFilterOptions.length > 0" cols="6" md="">
<VSelect
v-model="filterForm.site"
:items="getSiteFilterOptions"
@@ -263,11 +284,7 @@ onBeforeMount(fetchData)
multiple
/>
</VCol>
<VCol
v-if="getSeasonFilterOptions.length > 0"
cols="6"
md=""
>
<VCol v-if="getSeasonFilterOptions.length > 0" cols="6" md="">
<VSelect
v-model="filterForm.season"
:items="getSeasonFilterOptions"
@@ -278,11 +295,7 @@ onBeforeMount(fetchData)
multiple
/>
</VCol>
<VCol
v-if="getReleaseGroupFilterOptions.length > 0"
cols="6"
md=""
>
<VCol v-if="getReleaseGroupFilterOptions.length > 0" cols="6" md="">
<VSelect
v-model="filterForm.releaseGroup"
:items="getReleaseGroupFilterOptions"
@@ -293,11 +306,7 @@ onBeforeMount(fetchData)
multiple
/>
</VCol>
<VCol
v-if="getEditionFilterOptions.length > 0"
cols="6"
md=""
>
<VCol v-if="getEditionFilterOptions.length > 0" cols="6" md="">
<VSelect
v-model="filterForm.edition"
:items="getEditionFilterOptions"
@@ -308,11 +317,7 @@ onBeforeMount(fetchData)
multiple
/>
</VCol>
<VCol
v-if="getVideoCodeFilterOptions.length > 0"
cols="6"
md=""
>
<VCol v-if="getVideoCodeFilterOptions.length > 0" cols="6" md="">
<VSelect
v-model="filterForm.videoCode"
:items="getVideoCodeFilterOptions"
@@ -323,11 +328,7 @@ onBeforeMount(fetchData)
multiple
/>
</VCol>
<VCol
v-if="getFreeStateFilterOptions.length > 0"
cols="6"
md=""
>
<VCol v-if="getFreeStateFilterOptions.length > 0" cols="6" md="">
<VSelect
v-model="filterForm.freeState"
:items="getFreeStateFilterOptions"
@@ -359,16 +360,17 @@ onBeforeMount(fetchData)
></VProgressCircular>
<span>{{ progressText }}</span>
</div>
<div
class="grid gap-3 grid-torrent-card items-start"
v-if="dataList.length > 0"
>
<div class="grid gap-3 grid-torrent-card items-start" v-if="dataList.length > 0">
<TorrentCard
v-for="data in getFirstContexts"
v-show="filterTorrentsCard(data)"
:key="data.torrent_info.title"
:torrent="data"
:more="groupedDataList.get(`${data.torrent_info.title}_${data.torrent_info.size}`)?.slice(1)"
:more="
groupedDataList
.get(`${data.torrent_info.title}_${data.torrent_info.size}`)
?.slice(1)
"
/>
</div>
<NoDataFound