fix: 整理首页、登录和管理端的交互

This commit is contained in:
2026-11-16 03:18:08 +08:00
parent c9f70ad455
commit 2fb40c37ae
19 changed files with 1117 additions and 423 deletions
+37 -11
View File
@@ -13,28 +13,57 @@ const props = defineProps<{ employeeId: string }>();
const emit = defineEmits<{ logout: []; revoke: [] }>();
const page = ref<PageKey>(pageFromHash());
const collapsed = ref(window.innerWidth < 800);
const holdOpen = ref(false);
const pages = new Set<PageKey>(["home", "history", "exams", "trainings"]);
function hashName() {
return window.location.hash.replace(/^#\/?/, "");
}
function pageFromHash(): PageKey {
const name = window.location.hash.replace(/^#\/?/, "");
const name = hashName();
if (name === "exams" || name === "trainings" || name === "history" || name === "home") return name;
return "home";
}
function remember(next: PageKey) {
function knownHash(name: string) {
return pages.has(name as PageKey);
}
function show(next: PageKey) {
page.value = next;
const hash = `#/${next}`;
if (window.location.hash !== hash) history.replaceState(null, "", hash);
if (window.location.hash !== hash) window.location.hash = hash;
}
function onHashChange() {
const name = hashName();
if (name && !knownHash(name)) {
history.replaceState(null, "", "#/home");
page.value = "home";
return;
}
page.value = pageFromHash();
}
function onResize() {
if (holdOpen.value) return;
if (window.innerWidth < 800) collapsed.value = true;
}
function onCollapse() {
collapsed.value = true;
holdOpen.value = false;
}
function onExpand() {
collapsed.value = false;
holdOpen.value = true;
}
onMounted(() => {
remember(page.value);
const name = hashName();
if (!name || !knownHash(name)) history.replaceState(null, "", "#/home");
window.addEventListener("resize", onResize);
window.addEventListener("hashchange", onHashChange);
});
@@ -49,10 +78,7 @@ const logoutOptions = [
];
function onMenu(key: string) {
if (key === "home" || key === "history" || key === "exams" || key === "trainings") {
page.value = key;
remember(key);
}
if (key === "home" || key === "history" || key === "exams" || key === "trainings") show(key);
}
function onLogout(key: string) {
@@ -72,8 +98,8 @@ function onLogout(key: string) {
show-trigger
:native-scrollbar="false"
:content-style="{ height: '100%', display: 'flex', flexDirection: 'column' }"
@collapse="collapsed = true"
@expand="collapsed = false"
@collapse="onCollapse"
@expand="onExpand"
>
<div class="sider-body">
<div class="sider-brand" :class="{ compact: collapsed }">
@@ -102,7 +128,7 @@ function onLogout(key: string) {
</template>
{{ isDark ? "切换到日间" : "切换到夜间" }}
</n-tooltip>
<n-dropdown trigger="hover" placement="top-end" :options="logoutOptions" @select="onLogout">
<n-dropdown trigger="click" placement="top-end" :options="logoutOptions" @select="onLogout">
<n-button class="logout-btn" quaternary circle size="small" aria-label="退出">
<template #icon><n-icon><LogOutOutline /></n-icon></template>
</n-button>