From df3201945ee32eb8fc1744112618a25e87af48d7 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 15 Nov 2026 00:48:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=80=83=E8=AF=95=E5=92=8C=E5=9F=B9?= =?UTF-8?q?=E8=AE=AD=E7=8B=AC=E7=AB=8B=E6=88=90=E9=A1=B5=E5=B9=B6=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/features/exams/ExamsView.vue | 215 ++++++++++++++++++ web/src/features/trainings/TrainingsView.vue | 224 +++++++++++++++++++ web/src/shell/Shell.vue | 37 ++- web/src/shell/navigation.ts | 6 +- 4 files changed, 476 insertions(+), 6 deletions(-) create mode 100644 web/src/features/exams/ExamsView.vue create mode 100644 web/src/features/trainings/TrainingsView.vue diff --git a/web/src/features/exams/ExamsView.vue b/web/src/features/exams/ExamsView.vue new file mode 100644 index 0000000..42369ce --- /dev/null +++ b/web/src/features/exams/ExamsView.vue @@ -0,0 +1,215 @@ + + + diff --git a/web/src/features/trainings/TrainingsView.vue b/web/src/features/trainings/TrainingsView.vue new file mode 100644 index 0000000..27774c4 --- /dev/null +++ b/web/src/features/trainings/TrainingsView.vue @@ -0,0 +1,224 @@ + + + diff --git a/web/src/shell/Shell.vue b/web/src/shell/Shell.vue index cdc8e64..d01b090 100644 --- a/web/src/shell/Shell.vue +++ b/web/src/shell/Shell.vue @@ -5,18 +5,42 @@ import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons import { isDark, toggleTheme } from "../shared/theme"; import { navOptions, type PageKey } from "./navigation"; import HomeView from "../features/home/HomeView.vue"; +import ExamsView from "../features/exams/ExamsView.vue"; +import TrainingsView from "../features/trainings/TrainingsView.vue"; const props = defineProps<{ employeeId: string }>(); const emit = defineEmits<{ logout: []; revoke: [] }>(); -const page = ref("home"); +const page = ref(pageFromHash()); const collapsed = ref(window.innerWidth < 800); +function pageFromHash(): PageKey { + const name = window.location.hash.replace(/^#\/?/, ""); + if (name === "exams" || name === "trainings" || name === "home") return name; + return "home"; +} + +function remember(next: PageKey) { + const hash = `#/${next}`; + if (window.location.hash !== hash) history.replaceState(null, "", hash); +} + +function onHashChange() { + page.value = pageFromHash(); +} + function onResize() { if (window.innerWidth < 800) collapsed.value = true; } -onMounted(() => window.addEventListener("resize", onResize)); -onUnmounted(() => window.removeEventListener("resize", onResize)); +onMounted(() => { + remember(page.value); + window.addEventListener("resize", onResize); + window.addEventListener("hashchange", onHashChange); +}); +onUnmounted(() => { + window.removeEventListener("resize", onResize); + window.removeEventListener("hashchange", onHashChange); +}); const logoutOptions = [ { label: "退出当前系统", key: "logout" }, @@ -24,7 +48,10 @@ const logoutOptions = [ ]; function onMenu(key: string) { - if (key === "home") page.value = key; + if (key === "home" || key === "exams" || key === "trainings") { + page.value = key; + remember(key); + } } function onLogout(key: string) { @@ -84,6 +111,8 @@ function onLogout(key: string) { + + diff --git a/web/src/shell/navigation.ts b/web/src/shell/navigation.ts index 0f9b41f..c2bebef 100644 --- a/web/src/shell/navigation.ts +++ b/web/src/shell/navigation.ts @@ -1,14 +1,16 @@ import type { Component } from "vue"; import { h } from "vue"; import { NIcon } from "naive-ui"; -import { HomeOutline } from "@vicons/ionicons5"; +import { HomeOutline, ReaderOutline, SchoolOutline } from "@vicons/ionicons5"; function renderIcon(icon: Component) { return () => h(NIcon, null, { default: () => h(icon) }); } -export type PageKey = "home"; +export type PageKey = "home" | "exams" | "trainings"; export const navOptions = [ { label: "首页", key: "home" as const, icon: renderIcon(HomeOutline) }, + { label: "我的考试", key: "exams" as const, icon: renderIcon(ReaderOutline) }, + { label: "线上培训", key: "trainings" as const, icon: renderIcon(SchoolOutline) }, ];