diff --git a/src/App.vue b/src/App.vue index 56c38c0d..17ed114a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -212,11 +212,13 @@ async function handleDeepLink(payload: string): Promise { } if (payload.startsWith("router?path=")) { const routerPath = payload.replace("router?path=", ""); - if (router.currentRoute.value.path === routerPath) { + const curPath = router.currentRoute.value.path; + if (curPath === routerPath) { showSnackbar.warn("已在当前页面!", 3000); return; } - await router.push(routerPath); + await router.push({ path: routerPath, query: {} }); + window.location.pathname = routerPath; return; } } diff --git a/src/pages/common/PostForum.vue b/src/pages/common/PostForum.vue index 8d2ea8f1..82919ddb 100644 --- a/src/pages/common/PostForum.vue +++ b/src/pages/common/PostForum.vue @@ -122,7 +122,7 @@ import showSnackbar from "@comp/func/snackbar.js"; import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue"; import Mys from "@Mys/index.js"; import { onMounted, ref, shallowRef, watch } from "vue"; -import { useRoute } from "vue-router"; +import { useRoute, useRouter } from "vue-router"; import TGLogger from "@/utils/TGLogger.js"; import { createPost } from "@/utils/TGWindow.js"; @@ -139,7 +139,8 @@ const sortOrderList: Array> = [ { text: "热门", value: 3 }, ]; -const { gid, forum } = useRoute().params; +const route = useRoute(); +const router = useRouter(); const curGid = ref(2); const curSortType = ref(1); const search = ref(""); @@ -153,6 +154,9 @@ const posts = shallowRef>([]); onMounted(async () => { await showLoading.start("正在加载帖子数据"); await loadForums(); + let { gid, forum } = route.query; + if (!gid) gid = route.params.gid; + if (!forum) forum = route.params.forum; if (gid && typeof gid === "string") curGid.value = Number(gid); if (forum && typeof forum === "string") { selectedForum.value = getForum(curGid.value, Number(forum)); @@ -264,6 +268,11 @@ async function getCurrentPosts( async function freshPostData(): Promise { if (!selectedForum.value) return; + await router.push({ + name: "酒馆", + params: route.params, + query: { gid: curGid.value, forum: selectedForum.value.value }, + }); await showLoading.start(`正在刷新${getGameLabel(curGid.value)}帖子`); const gameLabel = getGameLabel(curGid.value); const forumLabel = getForum(curGid.value, selectedForum.value.value).text; diff --git a/src/pages/common/PostTopic.vue b/src/pages/common/PostTopic.vue index 67baa49a..f8989608 100644 --- a/src/pages/common/PostTopic.vue +++ b/src/pages/common/PostTopic.vue @@ -4,7 +4,7 @@
- {{ topicInfo.topic.name }}({{ topic }}) + {{ topicInfo.topic.name }}({{ curTopic }}) {{ topicInfo.topic.desc }}
@@ -92,7 +92,7 @@ import showSnackbar from "@comp/func/snackbar.js"; import VpOverlaySearch from "@comp/viewPost/vp-overlay-search.vue"; import Mys from "@Mys/index.js"; import { computed, onMounted, ref, shallowRef, watch } from "vue"; -import { useRoute } from "vue-router"; +import { useRoute, useRouter } from "vue-router"; import { createPost } from "@/utils/TGWindow.js"; import { getGameIcon } from "@/utils/toolFunc.js"; @@ -100,11 +100,13 @@ import { getGameIcon } from "@/utils/toolFunc.js"; type SortSelect = { text: string; value: number }; type PostMiniData = { isLast: boolean; lastId: string; total: number }; -const { gid, topic } = <{ gid: string; topic: string }>useRoute().params; +const route = useRoute(); +const router = useRouter(); const showSearch = ref(false); -const curGid = ref(Number(gid)); +const curGid = ref(0); const curSortType = ref<0 | 1 | 2>(0); const search = ref(""); +const curTopic = ref(""); const postRaw = shallowRef({ isLast: false, lastId: "", total: 0 }); const topicInfo = shallowRef(); const posts = shallowRef>([]); @@ -125,6 +127,13 @@ const sortList = computed>(() => { }); onMounted(async () => { + let { gid, topic } = route.query; + if (!gid) gid = route.params.gid; + if (!topic) topic = route.params.topic; + if (!gid || typeof gid !== "string") gid = "0"; + if (!topic || typeof topic !== "string") topic = "0"; + curGid.value = Number(gid); + curTopic.value = topic; await showLoading.start(`正在加载话题${topic}信息`); const info = await Mys.Post.getTopicFullInfo(gid, topic); if ("retcode" in info) { @@ -154,8 +163,13 @@ watch( async function firstLoad(): Promise { await showLoading.start(`正在加载话题${topicInfo.value?.topic.name}信息`); + await router.push({ + name: "话题", + params: route.params, + query: { gid: curGid.value, topic: curTopic.value }, + }); document.documentElement.scrollTo({ top: 0, behavior: "smooth" }); - const postList = await Mys.Post.getTopicPostList(curGid.value, topic, curSortType.value); + const postList = await Mys.Post.getTopicPostList(curGid.value, curTopic.value, curSortType.value); if ("retcode" in postList) { await showLoading.end(); showSnackbar.error(`[${postList.retcode}] ${postList.message}`); @@ -182,7 +196,7 @@ async function freshPostData(): Promise { const pageSize = mod20 === 0 ? 20 : 20 - mod20; const postList = await Mys.Post.getTopicPostList( curGid.value, - topic, + curTopic.value, curSortType.value, postRaw.value.lastId, pageSize, diff --git a/src/router/index.ts b/src/router/index.ts index 0c094716..c79c65b0 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,7 +1,7 @@ /** * @file router index.ts * @description 路由入口 - * @since Beta v0.3.3 + * @since Beta v0.6.8 */ import { createRouter, createWebHistory } from "vue-router"; @@ -12,7 +12,8 @@ const router = createRouter({ history: createWebHistory(), routes: routes }); // 解决路由重复问题 router.afterEach((to, from) => { - if (from.name === to.name && from.fullPath !== to.fullPath) { + if (from.name === to.name) { + if (from.query !== to.query) return; window.location.reload(); } });