From c9fbddcf5dee85cae7cbc0578696311f7446b4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sat, 24 Feb 2024 16:18:13 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=92=A8=E8=AE=AF=E9=A1=B5=E7=89=88=E5=9D=97=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=EF=BC=8C=E8=AE=B0=E5=BF=86=E5=BD=93=E5=89=8D=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/overlay/to-channel.vue | 67 ++++++++++++++++++--------- src/pages/common/News.vue | 21 +++++++-- src/router/modules/main.ts | 4 +- src/store/modules/app.ts | 8 +++- 4 files changed, 70 insertions(+), 30 deletions(-) diff --git a/src/components/overlay/to-channel.vue b/src/components/overlay/to-channel.vue index f11e06bf..e7e2dd66 100644 --- a/src/components/overlay/to-channel.vue +++ b/src/components/overlay/to-channel.vue @@ -2,13 +2,15 @@
-
请选择要跳转的频道
+
+ 请选择要跳转的频道 +
icon {{ item.title }} @@ -27,9 +29,13 @@ import { computed } from "vue"; import { useRouter } from "vue-router"; +import { useAppStore } from "../../store/modules/app"; +import showSnackbar from "../func/snackbar"; import TOverlay from "../main/t-overlay.vue"; interface ToChannelProps { + gid?: string; + curType?: string; modelValue: boolean; } @@ -38,7 +44,7 @@ type ToChannelEmits = (e: "update:modelValue", value: boolean) => void; interface ToChannelItem { title: string; icon: string; - link: string; + gid: string; } const props = withDefaults(defineProps(), { @@ -53,42 +59,43 @@ const visible = computed({ }, }); const router = useRouter(); +const appStore = useAppStore(); const channelList: ToChannelItem[] = [ { title: "原神", icon: "/platforms/mhy/ys.webp", - link: "/news/2", + gid: "2", }, { title: "崩坏:星穹铁道", icon: "/platforms/mhy/sr.webp", - link: "/news/6", + gid: "6", }, { title: "崩坏3", icon: "/platforms/mhy/bh3.webp", - link: "/news/1", + gid: "1", }, { title: "崩坏2", icon: "/platforms/mhy/bh2.webp", - link: "/news/3", + gid: "3", }, { title: "未定事件簿", icon: "/platforms/mhy/wd.webp", - link: "/news/4", + gid: "4", }, { title: "绝区零", icon: "/platforms/mhy/zzz.webp", - link: "/news/8", + gid: "8", }, { title: "大别野", icon: "/platforms/mhy/dby.webp", - link: "/news/5", + gid: "5", }, ]; @@ -96,14 +103,24 @@ function onCancel(): void { visible.value = false; } -async function toChannel(link: string): Promise { +async function toChannel(item: ToChannelItem): Promise { + if (props.gid === item.gid) { + showSnackbar({ + text: "当前已经在该频道", + color: "warn", + }); + return; + } visible.value = false; - await router.push(link).then(() => { - window.scrollTo(0, 0); - }); - setTimeout(() => { - window.location.reload(); - }, 300); + let link = `/news/${item.gid}/{type}`; + const typeList = ["notice", "news", "activity"]; + if (typeList.includes(appStore.recentNewsType)) { + link = link.replace("{type}", appStore.recentNewsType); + } else { + link = link.replace("{type}", "notice"); + appStore.recentNewsType = "notice"; + } + await router.push(link); }