From 8f4d3d2285e4ce18be4e2d16d47e069f03529c8f Mon Sep 17 00:00:00 2001 From: BTMuli Date: Wed, 25 Jun 2025 23:05:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20=E8=AF=9D=E9=A2=98=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B5=E8=A7=A6=E5=BA=95=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/common/PostTopic.vue | 39 ++++++++++++++++------------------ src/router/index.ts | 2 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/pages/common/PostTopic.vue b/src/pages/common/PostTopic.vue index e599d08d..4353953a 100644 --- a/src/pages/common/PostTopic.vue +++ b/src/pages/common/PostTopic.vue @@ -72,7 +72,7 @@ 刷新 @@ -84,12 +84,6 @@ -
- - 已加载:{{ posts.length }}, - {{ postRaw.isLast ? "已加载完毕" : "加载更多" }} - -
@@ -101,6 +95,7 @@ import showLoading from "@comp/func/loading.js"; import showSnackbar from "@comp/func/snackbar.js"; import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue"; import VpOverlayUser from "@comp/viewPost/vp-overlay-user.vue"; +import { usePageReachBottom } from "@hooks/reachBottom.js"; import postReq from "@req/postReq.js"; import topicReq from "@req/topicReq.js"; import useBBSStore from "@store/bbs.js"; @@ -116,6 +111,8 @@ type GameList = TGApp.BBS.Topic.GameInfo & { icon?: string }; const route = useRoute(); const router = useRouter(); +const { isReachBottom } = usePageReachBottom(); + const curGid = ref(0); const curSortType = ref<0 | 1 | 2>(0); const curTopic = ref(""); @@ -126,6 +123,7 @@ const curUid = ref(""); const showUser = ref(false); const isReq = ref(false); +const firstLoad = ref(false); const { gameList } = storeToRefs(useBBSStore()); const postRaw = shallowRef({ isLast: false, lastId: "", total: 0 }); const topicInfo = shallowRef(); @@ -169,22 +167,30 @@ onMounted(async () => { if (tmpGame === undefined) tmpGame = info.game_info_list[0]; const gameFind = gameList.value.find((i) => i.id === tmpGame?.id); curGame.value = { ...tmpGame, icon: gameFind?.app_icon }; - await firstLoad(); + await freshPostData(); + firstLoad.value = true; }); +watch( + () => isReachBottom.value, + async () => { + if (!isReachBottom.value || !firstLoad.value) return; + await loadMore(); + }, +); watch( () => curGame.value, async () => { if (curGame.value) curGid.value = curGame.value.id; - await firstLoad(); + await freshPostData(); }, ); watch( () => curSortType.value, - async () => await firstLoad(), + async () => await freshPostData(), ); -async function firstLoad(): Promise { +async function freshPostData(): Promise { if (isReq.value) return; isReq.value = true; await showLoading.start(`正在加载话题${topicInfo.value?.topic.name}信息`); @@ -212,7 +218,7 @@ async function firstLoad(): Promise { showSnackbar.success(`加载了 ${postList.posts.length} 条帖子`); } -async function freshPostData(): Promise { +async function loadMore(): Promise { if (isReq.value) return; isReq.value = true; if (showSearch.value) showSearch.value = false; @@ -349,15 +355,6 @@ function handleUserClick(user: TGApp.BBS.Post.User, gid: number): void { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); } -.load-more { - display: flex; - align-items: center; - justify-content: center; - margin: 10px; - font-family: var(--font-title); - transition: all 0.3s linear; -} - .select-item { position: relative; display: flex; diff --git a/src/router/index.ts b/src/router/index.ts index d5b573d7..ffe649ef 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -12,7 +12,7 @@ const router = createRouter({ history: createWebHistory(), routes: routes }); // 只有在特定页面忽略参数变化 const ignoreRoutes: ReadonlyArray = ["酒馆", "话题"]; -// 解决路由重复问题 +// TODO:路由重构 解决路由重复问题 router.afterEach((to, from) => { if (from.name === to.name) { if (from.query !== to.query && ignoreRoutes.includes(from.name?.toString() ?? "")) return;