From 4f7b452ce7fa4a61b9d64a591cc714314eaeb348 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Tue, 19 May 2026 20:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20=E4=BC=98=E5=8C=96=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=8F=82=E6=95=B0=E5=A4=84=E7=90=86=EF=BC=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=A7=92=E8=89=B2=E5=92=8C=E6=AD=A6=E5=99=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/WIKI/Character.vue | 18 +++++++++++++----- src/pages/WIKI/Weapon.vue | 18 +++++++++++++----- src/router/index.ts | 4 ++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/pages/WIKI/Character.vue b/src/pages/WIKI/Character.vue index cdee9f9c..e07d7a9a 100644 --- a/src/pages/WIKI/Character.vue +++ b/src/pages/WIKI/Character.vue @@ -31,8 +31,8 @@ import TwcCharacter from "@comp/pageWiki/twc-character.vue"; import TwcListItem from "@comp/pageWiki/twc-list-item.vue"; import TwoSelectC, { type SelectedCValue } from "@comp/pageWiki/two-select-c.vue"; import { toObcPage } from "@utils/TGWindow.js"; -import { onBeforeMount, ref, shallowRef, watch } from "vue"; -import { useRoute } from "vue-router"; +import { ref, shallowRef, watch } from "vue"; +import { useRoute, useRouter } from "vue-router"; import { AppCharacterData } from "@/data/index.js"; @@ -44,7 +44,8 @@ const appCData = AppCharacterData.sort( b.id - a.id, ); -const id = (useRoute().params?.id ?? 0).toString(); +const route = useRoute(); +const router = useRouter(); const showSelect = ref(false); const resetSelect = ref(false); const cardsInfo = shallowRef>(appCData); @@ -63,7 +64,7 @@ const curItem = shallowRef({ nameCard: "", }); -onBeforeMount(() => { +function loadCurItem(id: string): void { if (id === "0") { curItem.value = cardsInfo.value[0]; return; @@ -75,7 +76,13 @@ onBeforeMount(() => { } showSnackbar.warn(`角色 ${id} 不存在`); curItem.value = cardsInfo.value[0]; -}); +} + +watch( + () => route.params.id, + (newId) => loadCurItem((newId ?? 0).toString()), + { immediate: true }, +); watch( () => resetSelect.value, @@ -112,6 +119,7 @@ async function switchC(item: TGApp.App.Character.WikiBriefInfo): Promise { return; } curItem.value = item; + await router.replace({ params: { id: item.id.toString() } }); } async function toOuter(item?: TGApp.App.Character.WikiBriefInfo): Promise { diff --git a/src/pages/WIKI/Weapon.vue b/src/pages/WIKI/Weapon.vue index 5d4dcd35..5acefa44 100644 --- a/src/pages/WIKI/Weapon.vue +++ b/src/pages/WIKI/Weapon.vue @@ -30,8 +30,8 @@ import TwcListItem from "@comp/pageWiki/twc-list-item.vue"; import TwcWeapon from "@comp/pageWiki/twc-weapon.vue"; import TwoSelectW, { type SelectedWValue } from "@comp/pageWiki/two-select-w.vue"; import { toObcPage } from "@utils/TGWindow.js"; -import { onBeforeMount, ref, shallowRef, watch } from "vue"; -import { useRoute } from "vue-router"; +import { ref, shallowRef, watch } from "vue"; +import { useRoute, useRouter } from "vue-router"; import { AppWeaponData } from "@/data/index.js"; @@ -41,7 +41,8 @@ const appWData = AppWeaponData.sort((a, b) => { return b.id - a.id; }); -const id = (useRoute().params?.id ?? 0).toString(); +const route = useRoute(); +const router = useRouter(); const showSelect = ref(false); const resetSelect = ref(false); const cardsInfo = shallowRef>(appWData); @@ -53,7 +54,7 @@ const curItem = shallowRef({ weapon: "", }); -onBeforeMount(() => { +function loadCurItem(id: string): void { if (id === "0") { curItem.value = cardsInfo.value[0]; return; @@ -65,7 +66,13 @@ onBeforeMount(() => { } showSnackbar.warn(`武器 ${id} 不存在`); curItem.value = cardsInfo.value[0]; -}); +} + +watch( + () => route.params.id, + (newId) => loadCurItem((newId ?? 0).toString()), + { immediate: true }, +); watch( () => resetSelect.value, @@ -78,6 +85,7 @@ watch( function switchW(item: TGApp.App.Weapon.WikiBriefInfo): void { curItem.value = item; + router.replace({ params: { id: item.id.toString() } }); } function handleSelectW(val: SelectedWValue) { diff --git a/src/router/index.ts b/src/router/index.ts index 2d21969a..7e017386 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,6 @@ /** * 路由入口 - * @since Beta v0.9.1 + * @since Beta v0.10.2 */ import { createRouter, createWebHistory } from "vue-router"; @@ -9,7 +9,7 @@ import routes from "./routes.js"; const router = createRouter({ history: createWebHistory(), routes: routes }); // 只有在特定页面忽略参数变化 -const ignoreRoutes: ReadonlyArray = ["酒馆", "话题", "实用脚本"]; +const ignoreRoutes: ReadonlyArray = ["酒馆", "话题", "实用脚本", "角色图鉴", "武器图鉴"]; // TODO:路由重构 解决路由重复问题 router.afterEach((to, from) => {