️ 优化咨讯页版块跳转,记忆当前类型

This commit is contained in:
目棃
2024-02-24 16:18:13 +08:00
parent bf66b4eee0
commit c9fbddcf5d
4 changed files with 70 additions and 30 deletions

View File

@@ -2,13 +2,15 @@
<TOverlay v-model="visible" hide :to-click="onCancel" blur-val="20px"> <TOverlay v-model="visible" hide :to-click="onCancel" blur-val="20px">
<div class="toc-box"> <div class="toc-box">
<div class="toc-top"> <div class="toc-top">
<div class="toc-title">请选择要跳转的频道</div> <div class="toc-title">
<span>请选择要跳转的频道</span>
</div>
<div class="toc-list"> <div class="toc-list">
<div <div
v-for="(item, index) in channelList" v-for="(item, index) in channelList"
:key="index" :key="index"
class="toc-list-item" :class="props.gid === item.gid ? 'toc-list-item active' : 'toc-list-item'"
@click="toChannel(item.link)" @click="toChannel(item)"
> >
<img :src="item.icon" alt="icon" /> <img :src="item.icon" alt="icon" />
<span>{{ item.title }}</span> <span>{{ item.title }}</span>
@@ -27,9 +29,13 @@
import { computed } from "vue"; import { computed } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { useAppStore } from "../../store/modules/app";
import showSnackbar from "../func/snackbar";
import TOverlay from "../main/t-overlay.vue"; import TOverlay from "../main/t-overlay.vue";
interface ToChannelProps { interface ToChannelProps {
gid?: string;
curType?: string;
modelValue: boolean; modelValue: boolean;
} }
@@ -38,7 +44,7 @@ type ToChannelEmits = (e: "update:modelValue", value: boolean) => void;
interface ToChannelItem { interface ToChannelItem {
title: string; title: string;
icon: string; icon: string;
link: string; gid: string;
} }
const props = withDefaults(defineProps<ToChannelProps>(), { const props = withDefaults(defineProps<ToChannelProps>(), {
@@ -53,42 +59,43 @@ const visible = computed({
}, },
}); });
const router = useRouter(); const router = useRouter();
const appStore = useAppStore();
const channelList: ToChannelItem[] = [ const channelList: ToChannelItem[] = [
{ {
title: "原神", title: "原神",
icon: "/platforms/mhy/ys.webp", icon: "/platforms/mhy/ys.webp",
link: "/news/2", gid: "2",
}, },
{ {
title: "崩坏:星穹铁道", title: "崩坏:星穹铁道",
icon: "/platforms/mhy/sr.webp", icon: "/platforms/mhy/sr.webp",
link: "/news/6", gid: "6",
}, },
{ {
title: "崩坏3", title: "崩坏3",
icon: "/platforms/mhy/bh3.webp", icon: "/platforms/mhy/bh3.webp",
link: "/news/1", gid: "1",
}, },
{ {
title: "崩坏2", title: "崩坏2",
icon: "/platforms/mhy/bh2.webp", icon: "/platforms/mhy/bh2.webp",
link: "/news/3", gid: "3",
}, },
{ {
title: "未定事件簿", title: "未定事件簿",
icon: "/platforms/mhy/wd.webp", icon: "/platforms/mhy/wd.webp",
link: "/news/4", gid: "4",
}, },
{ {
title: "绝区零", title: "绝区零",
icon: "/platforms/mhy/zzz.webp", icon: "/platforms/mhy/zzz.webp",
link: "/news/8", gid: "8",
}, },
{ {
title: "大别野", title: "大别野",
icon: "/platforms/mhy/dby.webp", icon: "/platforms/mhy/dby.webp",
link: "/news/5", gid: "5",
}, },
]; ];
@@ -96,14 +103,24 @@ function onCancel(): void {
visible.value = false; visible.value = false;
} }
async function toChannel(link: string): Promise<void> { async function toChannel(item: ToChannelItem): Promise<void> {
visible.value = false; if (props.gid === item.gid) {
await router.push(link).then(() => { showSnackbar({
window.scrollTo(0, 0); text: "当前已经在该频道",
color: "warn",
}); });
setTimeout(() => { return;
window.location.reload(); }
}, 300); visible.value = false;
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);
} }
</script> </script>
<style lang="css" scoped> <style lang="css" scoped>
@@ -114,7 +131,7 @@ async function toChannel(link: string): Promise<void> {
.toc-top { .toc-top {
padding: 10px; padding: 10px;
border-radius: 5px; border-radius: 5px;
background: var(--box-bg-1); background: var(--app-page-bg);
} }
.toc-title { .toc-title {
@@ -134,14 +151,20 @@ async function toChannel(link: string): Promise<void> {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: start; justify-content: start;
border: 1px solid var(--common-shadow-2); border: 1px solid var(--common-shadow-1);
border-radius: 5px; border-radius: 5px;
background: var(--box-bg-2); background: var(--box-bg-1);
color: var(--box-text-2); color: var(--box-text-1);
cursor: pointer; cursor: pointer;
transition: all 0.5s linear; transition: all 0.5s linear;
} }
.toc-list-item.active {
border: 1px solid var(--common-shadow-1);
background: var(--box-bg-2);
color: var(--box-text-2);
}
.toc-list-item img { .toc-list-item img {
width: 45px; width: 45px;
height: 45px; height: 45px;

View File

@@ -85,11 +85,11 @@
</div> </div>
</v-window-item> </v-window-item>
</v-window> </v-window>
<ToChannel v-model="showList" /> <ToChannel v-model="showList" :gid="gid" />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { nextTick, onMounted, ref } from "vue"; import { nextTick, onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import showSnackbar from "../../components/func/snackbar"; import showSnackbar from "../../components/func/snackbar";
@@ -97,6 +97,7 @@ import ToChannel from "../../components/overlay/to-channel.vue";
import ToLoading from "../../components/overlay/to-loading.vue"; import ToLoading from "../../components/overlay/to-loading.vue";
import TpAvatar from "../../components/post/tp-avatar.vue"; import TpAvatar from "../../components/post/tp-avatar.vue";
import Mys from "../../plugins/Mys"; import Mys from "../../plugins/Mys";
import { useAppStore } from "../../store/modules/app";
import TGLogger from "../../utils/TGLogger"; import TGLogger from "../../utils/TGLogger";
import { createPost } from "../../utils/TGWindow"; import { createPost } from "../../utils/TGWindow";
@@ -129,6 +130,7 @@ const loadingTitle = ref<string>("正在加载");
const loadingSub = ref<boolean>(false); const loadingSub = ref<boolean>(false);
// UI 数据 // UI 数据
const appStore = useAppStore();
const tab = ref<NewsKey>("notice"); const tab = ref<NewsKey>("notice");
const showList = ref<boolean>(false); const showList = ref<boolean>(false);
const tabValues = ref<Array<NewsKey>>(["notice", "activity", "news"]); const tabValues = ref<Array<NewsKey>>(["notice", "activity", "news"]);
@@ -160,8 +162,19 @@ const rawData = ref<RawData>({
onMounted(async () => { onMounted(async () => {
await TGLogger.Info(`[News][${gid}][onMounted] 打开咨讯页面`); await TGLogger.Info(`[News][${gid}][onMounted] 打开咨讯页面`);
const typeList = ["notice", "activity", "news"];
const curType = appStore.recentNewsType;
if (typeList.includes(curType)) {
tab.value = <NewsKey>curType;
} else {
tab.value = "notice"; tab.value = "notice";
await firstLoad("notice"); appStore.recentNewsType = "notice";
}
await firstLoad(tab.value);
});
watch(tab, (val) => {
appStore.recentNewsType = val;
}); });
async function firstLoad(key: NewsKey): Promise<void> { async function firstLoad(key: NewsKey): Promise<void> {

View File

@@ -1,7 +1,7 @@
/** /**
* @file router/modules/main.ts * @file router/modules/main.ts
* @description 主路由模块 * @description 主路由模块
* @since Beta v0.3.7 * @since Beta v0.4.4
*/ */
const mainRoutes = [ const mainRoutes = [
@@ -16,7 +16,7 @@ const mainRoutes = [
component: async () => await import("../../pages/common/Announcements.vue"), component: async () => await import("../../pages/common/Announcements.vue"),
}, },
{ {
path: "/news/:gid", path: "/news/:gid/:type?",
name: "咨讯", name: "咨讯",
component: async () => await import("../../pages/common/News.vue"), component: async () => await import("../../pages/common/News.vue"),
}, },

View File

@@ -1,7 +1,7 @@
/** /**
* @file store/modules/app.ts * @file store/modules/app.ts
* @description App store module * @description App store module
* @since Beta v0.4.3 * @since Beta v0.4.4
*/ */
import { path } from "@tauri-apps/api"; import { path } from "@tauri-apps/api";
@@ -48,6 +48,8 @@ export const useAppStore = defineStore(
const server = ref<SERVER>(SERVER.CN_ISLAND); const server = ref<SERVER>(SERVER.CN_ISLAND);
// 语言 // 语言
const lang = ref<string>("zh-cn"); const lang = ref<string>("zh-cn");
// 最近的咨讯类型
const recentNewsType = ref("notice");
// 初始化 // 初始化
function init(): void { function init(): void {
@@ -58,6 +60,7 @@ export const useAppStore = defineStore(
sidebar.collapse = true; sidebar.collapse = true;
server.value = SERVER.CN_ISLAND; server.value = SERVER.CN_ISLAND;
lang.value = "zh-cn"; lang.value = "zh-cn";
recentNewsType.value = "notice";
initDevice(); initDevice();
} }
@@ -83,6 +86,7 @@ export const useAppStore = defineStore(
logDir, logDir,
server, server,
lang, lang,
recentNewsType,
init, init,
changeTheme, changeTheme,
}; };
@@ -107,7 +111,7 @@ export const useAppStore = defineStore(
{ {
key: "theme", key: "theme",
storage: window.localStorage, storage: window.localStorage,
paths: ["theme", "server", "lang"], paths: ["theme", "server", "lang", "recentNewsType"],
}, },
{ {
key: "deviceInfo", key: "deviceInfo",