feat: 考试和培训独立成页并加入导航
This commit is contained in:
+33
-4
@@ -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<PageKey>("home");
|
||||
const page = ref<PageKey>(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) {
|
||||
</n-layout-sider>
|
||||
<n-layout class="content" :native-scrollbar="false" content-style="height: 100%; min-height: 0; overflow: hidden; display: flex; flex-direction: column;">
|
||||
<HomeView v-if="page === 'home'" :employee-id="props.employeeId" />
|
||||
<ExamsView v-else-if="page === 'exams'" />
|
||||
<TrainingsView v-else />
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user