mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-28 19:47:49 +08:00
fix search loading
This commit is contained in:
@@ -27,3 +27,11 @@
|
|||||||
inset-inline-start: 50%;
|
inset-inline-start: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.top-centered {
|
||||||
|
position: absolute;
|
||||||
|
inset-block-start: 20%;
|
||||||
|
inset-inline-start: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import api from "@/api";
|
|||||||
import { Context } from "@/api/types";
|
import { Context } from "@/api/types";
|
||||||
import TorrentCard from "@/components/cards/TorrentCard.vue";
|
import TorrentCard from "@/components/cards/TorrentCard.vue";
|
||||||
import NoDataFound from "@/components/NoDataFound.vue";
|
import NoDataFound from "@/components/NoDataFound.vue";
|
||||||
|
import store from "@/store";
|
||||||
|
|
||||||
// 定义输入参数
|
// 定义输入参数
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -20,6 +21,13 @@ const groupedDataList = computed(() => {
|
|||||||
// 是否刷新过
|
// 是否刷新过
|
||||||
const isRefreshed = ref(false);
|
const isRefreshed = ref(false);
|
||||||
|
|
||||||
|
// 加载进度文本
|
||||||
|
const progressText = ref("");
|
||||||
|
// 加载进度
|
||||||
|
const progressValue = ref(0);
|
||||||
|
// 加载进度SSE
|
||||||
|
const progressEventSource = ref<EventSource>();
|
||||||
|
|
||||||
// 获取订阅列表数据
|
// 获取订阅列表数据
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -28,6 +36,7 @@ const fetchData = async () => {
|
|||||||
// 查询上次搜索结果
|
// 查询上次搜索结果
|
||||||
dataList.value = await api.get("search/last");
|
dataList.value = await api.get("search/last");
|
||||||
} else {
|
} else {
|
||||||
|
startLoadingProgress();
|
||||||
// 优先按TMDBID精确查询
|
// 优先按TMDBID精确查询
|
||||||
if (props.keyword?.startsWith("tmdb:") || props.keyword?.startsWith("douban:")) {
|
if (props.keyword?.startsWith("tmdb:") || props.keyword?.startsWith("douban:")) {
|
||||||
dataList.value = await api.get(`search/media/${props.keyword}`);
|
dataList.value = await api.get(`search/media/${props.keyword}`);
|
||||||
@@ -35,6 +44,7 @@ const fetchData = async () => {
|
|||||||
// 按标题模糊查询
|
// 按标题模糊查询
|
||||||
dataList.value = await api.get(`search/title/${props.keyword}`);
|
dataList.value = await api.get(`search/title/${props.keyword}`);
|
||||||
}
|
}
|
||||||
|
stopLoadingProgress();
|
||||||
}
|
}
|
||||||
isRefreshed.value = true;
|
isRefreshed.value = true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -76,6 +86,26 @@ const getFirstContexts = computed(() => {
|
|||||||
return firstContexts;
|
return firstContexts;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 使用SSE监听加载进度
|
||||||
|
const startLoadingProgress = () => {
|
||||||
|
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);
|
||||||
|
console.log(progress);
|
||||||
|
progressText.value = progress.text;
|
||||||
|
progressValue.value = progress.value;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// 停止监听加载进度
|
||||||
|
const stopLoadingProgress = () => {
|
||||||
|
progressEventSource.value?.close();
|
||||||
|
};
|
||||||
|
|
||||||
// 加载时获取数据
|
// 加载时获取数据
|
||||||
onBeforeMount(fetchData);
|
onBeforeMount(fetchData);
|
||||||
</script>
|
</script>
|
||||||
@@ -83,10 +113,23 @@ onBeforeMount(fetchData);
|
|||||||
<template>
|
<template>
|
||||||
<VProgressCircular
|
<VProgressCircular
|
||||||
class="centered"
|
class="centered"
|
||||||
v-if="!isRefreshed"
|
v-if="!isRefreshed && !props.keyword"
|
||||||
indeterminate
|
indeterminate
|
||||||
color="primary"
|
color="primary"
|
||||||
></VProgressCircular>
|
></VProgressCircular>
|
||||||
|
<div
|
||||||
|
class="top-centered mt-12 w-full text-center text-gray-500 text-sm flex flex-col items-center"
|
||||||
|
v-if="!isRefreshed && props.keyword"
|
||||||
|
>
|
||||||
|
<VProgressCircular
|
||||||
|
class="mb-3"
|
||||||
|
color="primary"
|
||||||
|
:model-value="progressValue"
|
||||||
|
size="64"
|
||||||
|
width="7"
|
||||||
|
></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
|
<TorrentCard
|
||||||
v-for="data in getFirstContexts"
|
v-for="data in getFirstContexts"
|
||||||
|
|||||||
Reference in New Issue
Block a user