修复待看页面点击不刷新问题

This commit is contained in:
2025-09-07 17:09:56 +08:00
parent 1142d55b24
commit 94fb546d2f
2 changed files with 214 additions and 32 deletions
+162 -8
View File
@@ -1,12 +1,5 @@
{
"items": [
{
"id": "1757123368005",
"url": "http://localhost:3001/artist/72143697",
"title": "作者 72143697",
"createdAt": "2025-09-06T01:49:28.005Z",
"updatedAt": "2025-09-06T01:49:28.005Z"
},
{
"id": "1757123801822",
"url": "http://localhost:3001/artist/103047332",
@@ -342,7 +335,168 @@
"title": "作者 117814316",
"createdAt": "2025-09-06T02:01:32.756Z",
"updatedAt": "2025-09-06T02:01:32.756Z"
},
{
"id": "1757134816467",
"url": "http://localhost:3001/artist/36412673",
"title": "作者 36412673",
"createdAt": "2025-09-06T05:00:16.467Z",
"updatedAt": "2025-09-06T05:00:16.467Z"
},
{
"id": "1757134847809",
"url": "http://localhost:3001/artist/8786609",
"title": "作者 8786609",
"createdAt": "2025-09-06T05:00:47.809Z",
"updatedAt": "2025-09-06T05:00:47.809Z"
},
{
"id": "1757134866111",
"url": "http://localhost:3001/artist/105728977",
"title": "作者 105728977",
"createdAt": "2025-09-06T05:01:06.111Z",
"updatedAt": "2025-09-06T05:01:06.111Z"
},
{
"id": "1757134884090",
"url": "http://localhost:3001/artist/52918150",
"title": "作者 52918150",
"createdAt": "2025-09-06T05:01:24.090Z",
"updatedAt": "2025-09-06T05:01:24.090Z"
},
{
"id": "1757134945366",
"url": "http://localhost:3001/artist/30947069",
"title": "作者 30947069",
"createdAt": "2025-09-06T05:02:25.366Z",
"updatedAt": "2025-09-06T05:02:25.366Z"
},
{
"id": "1757134976212",
"url": "http://localhost:3001/artist/104459830",
"title": "作者 104459830",
"createdAt": "2025-09-06T05:02:56.212Z",
"updatedAt": "2025-09-06T05:02:56.212Z"
},
{
"id": "1757135192806",
"url": "http://localhost:3001/artist/115568000",
"title": "作者 115568000",
"createdAt": "2025-09-06T05:06:32.806Z",
"updatedAt": "2025-09-06T05:06:32.806Z"
},
{
"id": "1757148264563",
"url": "http://localhost:3001/artist/109433637",
"title": "作者 109433637",
"createdAt": "2025-09-06T08:44:24.563Z",
"updatedAt": "2025-09-06T08:44:24.563Z"
},
{
"id": "1757148286939",
"url": "http://localhost:3001/artist/89469319",
"title": "作者 89469319",
"createdAt": "2025-09-06T08:44:46.939Z",
"updatedAt": "2025-09-06T08:44:46.939Z"
},
{
"id": "1757148309527",
"url": "http://localhost:3001/artist/43570725",
"title": "作者 43570725",
"createdAt": "2025-09-06T08:45:09.527Z",
"updatedAt": "2025-09-06T08:45:09.527Z"
},
{
"id": "1757148337732",
"url": "http://localhost:3001/artwork/134605714?artistId=114157922&artworkType=art&page=1&returnUrl=/artist/114157922&scrollTop=0",
"title": "作品 134605714 - 第1页",
"createdAt": "2025-09-06T08:45:37.732Z",
"updatedAt": "2025-09-06T08:45:37.732Z"
},
{
"id": "1757148416536",
"url": "http://localhost:3001/artist/75353169",
"title": "作者 75353169",
"createdAt": "2025-09-06T08:46:56.536Z",
"updatedAt": "2025-09-06T08:46:56.536Z"
},
{
"id": "1757148514536",
"url": "http://localhost:3001/artist/109989392?page=1",
"title": "作者 109989392 - 第1页",
"createdAt": "2025-09-06T08:48:34.536Z",
"updatedAt": "2025-09-06T08:48:34.536Z"
},
{
"id": "1757148606603",
"url": "http://localhost:3001/artist/24076060",
"title": "作者 24076060",
"createdAt": "2025-09-06T08:50:06.603Z",
"updatedAt": "2025-09-06T08:50:06.603Z"
},
{
"id": "1757148650070",
"url": "http://localhost:3001/artist/116180859",
"title": "作者 116180859",
"createdAt": "2025-09-06T08:50:50.070Z",
"updatedAt": "2025-09-06T08:50:50.070Z"
},
{
"id": "1757148777962",
"url": "http://localhost:3001/artist/40589862",
"title": "作者 40589862",
"createdAt": "2025-09-06T08:52:57.962Z",
"updatedAt": "2025-09-06T08:52:57.962Z"
},
{
"id": "1757148803009",
"url": "http://localhost:3001/artist/115384269",
"title": "作者 115384269",
"createdAt": "2025-09-06T08:53:23.009Z",
"updatedAt": "2025-09-06T08:53:23.009Z"
},
{
"id": "1757148855942",
"url": "http://localhost:3001/artist/71278415",
"title": "作者 71278415",
"createdAt": "2025-09-06T08:54:15.942Z",
"updatedAt": "2025-09-06T08:54:15.942Z"
},
{
"id": "1757148913189",
"url": "http://localhost:3001/artist/93761289",
"title": "作者 93761289",
"createdAt": "2025-09-06T08:55:13.189Z",
"updatedAt": "2025-09-06T08:55:13.189Z"
},
{
"id": "1757148929478",
"url": "http://localhost:3001/artist/116549618",
"title": "作者 116549618",
"createdAt": "2025-09-06T08:55:29.478Z",
"updatedAt": "2025-09-06T08:55:29.478Z"
},
{
"id": "1757148987777",
"url": "http://localhost:3001/artist/119034168?page=1",
"title": "作者 119034168 - 第1页",
"createdAt": "2025-09-06T08:56:27.777Z",
"updatedAt": "2025-09-06T08:56:27.777Z"
},
{
"id": "1757149119048",
"url": "http://localhost:3001/artist/3969934?page=1",
"title": "作者 3969934 - 第1页",
"createdAt": "2025-09-06T08:58:39.048Z",
"updatedAt": "2025-09-06T08:58:39.048Z"
},
{
"id": "1757149171042",
"url": "http://localhost:3001/artist/9631509",
"title": "作者 9631509",
"createdAt": "2025-09-06T08:59:31.042Z",
"updatedAt": "2025-09-06T08:59:31.043Z"
}
],
"lastUpdated": "2025-09-06T02:01:32.756Z"
"lastUpdated": "2025-09-07T09:03:59.197Z"
}
+50 -22
View File
@@ -289,7 +289,7 @@ const fetchArtistInfo = async () => {
const artistId = parseInt(route.params.id as string);
if (isNaN(artistId)) {
error.value = '无效的作者ID';
return;
return false;
}
// 检查缓存
@@ -297,7 +297,7 @@ const fetchArtistInfo = async () => {
const cached = getCache(cacheKey);
if (cached) {
artist.value = cached;
return;
return true;
}
try {
@@ -309,12 +309,14 @@ const fetchArtistInfo = async () => {
if (response.success && response.data) {
artist.value = response.data;
setCache(cacheKey, response.data);
return true;
} else {
throw new Error(response.error || '获取作者信息失败');
}
} catch (err) {
error.value = err instanceof Error ? err.message : '获取作者信息失败';
console.error('获取作者信息失败:', err);
return false;
} finally {
loading.value = false;
}
@@ -565,20 +567,32 @@ const handleJumpToPage = async () => {
};
// 监听路由变化
watch(() => route.params.id, () => {
// 清除缓存并重新加载
clearCache();
fetchArtistInfo();
watch(() => route.params.id, async (newId, oldId) => {
// 只有当作者ID真正变化时才重新加载
if (newId !== oldId) {
// 清除缓存并重新加载
clearCache();
artworks.value = []; // 立即清空作品列表
currentPage.value = 1; // 重置页码
totalPages.value = 0; // 重置总页数
artworkType.value = 'art'; // 重置作品类型
// 检查是否有返回的页面信息或指定的页码
const returnPage = parseInt(route.query.page as string);
if (returnPage && returnPage > 0) {
currentPage.value = returnPage;
fetchArtworks(returnPage, true);
} else {
fetchArtworks(1);
// 先获取作者信息
const success = await fetchArtistInfo();
// 只有成功获取作者信息后才获取作品
if (success && artist.value) {
// 检查是否有返回的页面信息或指定的页码
const returnPage = parseInt(route.query.page as string);
if (returnPage && returnPage > 0) {
currentPage.value = returnPage;
await fetchArtworks(returnPage, true);
} else {
await fetchArtworks(1);
}
}
}
});
}, { immediate: false });
// 监听URL查询参数变化
watch(() => route.query.page, (newPage) => {
@@ -591,21 +605,35 @@ watch(() => route.query.page, (newPage) => {
}
});
// 监听作者变化,确保作品列表与当前作者同步
watch(() => artist.value?.id, (newArtistId, oldArtistId) => {
if (newArtistId && newArtistId !== oldArtistId) {
// 作者变化时重新获取作品列表
artworks.value = [];
currentPage.value = 1;
totalPages.value = 0;
fetchArtworks(1);
}
}, { immediate: false });
// 组件卸载时清理缓存
onUnmounted(() => {
clearCache();
});
onMounted(async () => {
await fetchArtistInfo();
const success = await fetchArtistInfo();
// 检查是否有返回的页面信息或指定的页码
const returnPage = parseInt(route.query.page as string);
if (returnPage && returnPage > 0) {
currentPage.value = returnPage;
await fetchArtworks(returnPage, true);
} else {
await fetchArtworks(1);
// 只有成功获取作者信息后才获取作品
if (success && artist.value) {
// 检查是否有返回的页面信息或指定的页码
const returnPage = parseInt(route.query.page as string);
if (returnPage && returnPage > 0) {
currentPage.value = returnPage;
await fetchArtworks(returnPage, true);
} else {
await fetchArtworks(1);
}
}
// 恢复滚动位置(延迟执行确保页面内容完全加载)