From 6b8cbe0e57b570bb4d7a2454d27d6ca875a849d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Fri, 8 Nov 2024 21:37:20 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E8=B0=83=E6=95=B4=E5=B8=96?= =?UTF-8?q?=E5=AD=90=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/common/Posts.vue | 85 +++++++++----------------------------- 1 file changed, 19 insertions(+), 66 deletions(-) diff --git a/src/pages/common/Posts.vue b/src/pages/common/Posts.vue index 83f7ee8f..584be904 100644 --- a/src/pages/common/Posts.vue +++ b/src/pages/common/Posts.vue @@ -141,41 +141,13 @@ const forumDbyList: SortSelect[] = [ { text: "公告", value: 36 }, ]; const sortGameList: SortSelectGame[] = [ - { - gid: 2, - forum: forumYsList, - text: "原神", - }, - { - gid: 6, - forum: forumSrList, - text: "崩坏:星穹铁道", - }, - { - gid: 8, - forum: forumZzzList, - text: "绝区零", - }, - { - gid: 1, - forum: forumBh3List, - text: "崩坏3", - }, - { - gid: 3, - forum: forumBh2List, - text: "崩坏2", - }, - { - gid: 4, - forum: forumWdList, - text: "未定事件簿", - }, - { - gid: 5, - forum: forumDbyList, - text: "大别野", - }, + { gid: 2, forum: forumYsList, text: "原神" }, + { gid: 6, forum: forumSrList, text: "崩坏:星穹铁道" }, + { gid: 8, forum: forumZzzList, text: "绝区零" }, + { gid: 1, forum: forumBh3List, text: "崩坏3" }, + { gid: 3, forum: forumBh2List, text: "崩坏2" }, + { gid: 4, forum: forumWdList, text: "未定事件簿" }, + { gid: 5, forum: forumDbyList, text: "大别野" }, ]; // 路由 @@ -184,17 +156,13 @@ const forum = useRoute().params.forum; function getGameForums(gid: number): SortSelect[] { const game = sortGameList.find((item) => item.gid === gid); - if (game) { - return game.forum; - } + if (game) return game.forum; return []; } function getGameLabel(gid: number): string { const game = sortGameList.find((item) => item.gid === gid); - if (game) { - return game.text; - } + if (game) return game.text; return ""; } @@ -240,16 +208,10 @@ watch( async (newVal: number) => { const forums = getGameForums(newVal); const forumFind = forums.find((item) => item.text === curForumLabel.value); - if (forumFind) { - curForum.value = forumFind.value; - } else { - curForum.value = forums[0].value; - } + if (forumFind) curForum.value = forumFind.value; + else curForum.value = forums[0].value; await nextTick(); - showSnackbar({ - text: `已将分区切换到 ${getGameLabel(newVal)}`, - color: "success", - }); + showSnackbar({ text: `已将分区切换到 ${getGameLabel(newVal)}`, color: "success" }); }, ); watch( @@ -268,13 +230,10 @@ watch( ); watch( () => curSortType.value, - async (newVal) => { + async () => { await freshPostData(); - const sortLabel = getSortLabel(newVal); - showSnackbar({ - text: `已将排序切换到 ${sortLabel}`, - color: "success", - }); + const sortLabel = getSortLabel(curSortType.value); + showSnackbar({ text: `已将排序切换到 ${sortLabel}`, color: "success" }); }, ); @@ -287,7 +246,7 @@ async function freshPostData(): Promise { ); loading.value = true; loadingTitle.value = `正在加载 ${gameLabel}-${forumLabel}-${sortLabel} 数据`; - const postsGet = await Mys.Post.getForumPostList(curForum.value, curSortType.value, 12); + const postsGet = await Mys.Post.getForumPostList(curForum.value, curSortType.value); posts.value = postsGet.list; await nextTick(); loading.value = false; @@ -296,18 +255,12 @@ async function freshPostData(): Promise { // 查询帖子 function searchPost(): void { if (search.value === "") { - showSnackbar({ - text: "请输入搜索内容", - color: "error", - }); + showSnackbar({ text: "请输入搜索内容", color: "error" }); return; } const numCheck = Number(search.value); - if (isNaN(numCheck)) { - showSearch.value = true; - } else { - createPost(search.value); - } + if (isNaN(numCheck)) showSearch.value = true; + else createPost(search.value); }