feat: 保持浏览器登录,并显示我的学时里的本月学时
This commit is contained in:
+26
-3
@@ -1,20 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
import { darkTheme, dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui";
|
||||
import LoginView from "./features/auth/LoginView.vue";
|
||||
import Shell from "./shell/Shell.vue";
|
||||
import { isDark, themeOverrides } from "./shared/theme";
|
||||
|
||||
const ready = ref(false);
|
||||
const employeeId = ref("");
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await fetch("/api/session");
|
||||
if (response.ok) {
|
||||
const payload = await response.json();
|
||||
employeeId.value = String(payload.employee_id || "");
|
||||
}
|
||||
} finally {
|
||||
ready.value = true;
|
||||
}
|
||||
});
|
||||
|
||||
async function exitSystem() {
|
||||
await fetch("/api/logout", { method: "POST" });
|
||||
employeeId.value = "";
|
||||
}
|
||||
|
||||
async function revokeAccount() {
|
||||
await fetch("/api/revoke", { method: "POST" });
|
||||
employeeId.value = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
|
||||
<n-message-provider class="app-root">
|
||||
<n-dialog-provider>
|
||||
<div class="app-root">
|
||||
<div v-if="ready" class="app-root">
|
||||
<LoginView v-if="!employeeId" @success="employeeId = $event" />
|
||||
<Shell v-else :employee-id="employeeId" @logout="employeeId = ''" />
|
||||
<Shell v-else :employee-id="employeeId" @logout="exitSystem" @revoke="revokeAccount" />
|
||||
</div>
|
||||
</n-dialog-provider>
|
||||
</n-message-provider>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NTooltip } from "naive-ui";
|
||||
import { NAlert, NButton, NCheckbox, NIcon, NInput, NTooltip } from "naive-ui";
|
||||
import { ChevronForward, MoonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { isDark, toggleTheme } from "../../shared/theme";
|
||||
|
||||
@@ -18,6 +18,7 @@ const emit = defineEmits<{ success: [employeeId: string] }>();
|
||||
const employeeId = ref("");
|
||||
const password = ref("");
|
||||
const submitting = ref(false);
|
||||
const manualJigsaw = ref(false);
|
||||
const errorText = ref("");
|
||||
const attemptId = ref("");
|
||||
const jigsaw = ref<JigsawPuzzle | null>(null);
|
||||
@@ -52,7 +53,11 @@ async function submit() {
|
||||
const response = await fetch("/api/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ employee_id: employeeId.value.trim(), password: password.value }),
|
||||
body: JSON.stringify({
|
||||
employee_id: employeeId.value.trim(),
|
||||
password: password.value,
|
||||
manual_jigsaw: manualJigsaw.value,
|
||||
}),
|
||||
});
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
@@ -136,6 +141,10 @@ function onPointerUp() {
|
||||
<label for="password">密码</label>
|
||||
<n-input id="password" v-model:value="password" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" :disabled="!!jigsaw || submitting" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<span></span>
|
||||
<n-checkbox v-model:checked="manualJigsaw" :disabled="!!jigsaw || submitting">手动滑动验证码</n-checkbox>
|
||||
</div>
|
||||
<div v-if="jigsaw" class="jigsaw-block">
|
||||
<p>拖动滑块完成拼图</p>
|
||||
<div class="jigsaw" :style="{ width: jigsaw.width + 'px', height: jigsaw.height + 'px' }">
|
||||
|
||||
@@ -14,6 +14,7 @@ interface HomeProfile {
|
||||
level: string;
|
||||
year_score: string;
|
||||
month_score: string;
|
||||
month_hours: string;
|
||||
total_hours: string;
|
||||
total_score: string;
|
||||
today_hours: string | number | null;
|
||||
@@ -35,6 +36,7 @@ const facts = computed(() => {
|
||||
return [
|
||||
{ label: "本年学分", value: current.year_score },
|
||||
{ label: "本月学分", value: current.month_score },
|
||||
{ label: "本月学时", value: current.month_hours },
|
||||
{ label: "累计学时", value: current.total_hours },
|
||||
{ label: "累计学分", value: current.total_score },
|
||||
{ label: "今日学时", value: current.today_hours ?? "—" },
|
||||
@@ -51,7 +53,7 @@ async function load() {
|
||||
const current = ++requestId;
|
||||
loading.value = profile.value === null;
|
||||
try {
|
||||
const response = await fetch(`/api/home?employee_id=${encodeURIComponent(props.employeeId)}`);
|
||||
const response = await fetch("/api/home");
|
||||
const payload = await response.json().catch(() => ({}));
|
||||
if (current !== requestId) return;
|
||||
if (!response.ok) {
|
||||
|
||||
+17
-10
@@ -1,13 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from "vue";
|
||||
import { NButton, NIcon, NLayout, NLayoutSider, NMenu, NTooltip } from "naive-ui";
|
||||
import { NButton, NDropdown, NIcon, NLayout, NLayoutSider, NMenu, NTooltip } from "naive-ui";
|
||||
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { isDark, toggleTheme } from "../shared/theme";
|
||||
import { navOptions, type PageKey } from "./navigation";
|
||||
import HomeView from "../features/home/HomeView.vue";
|
||||
|
||||
const props = defineProps<{ employeeId: string }>();
|
||||
const emit = defineEmits<{ logout: [] }>();
|
||||
const emit = defineEmits<{ logout: []; revoke: [] }>();
|
||||
const page = ref<PageKey>("home");
|
||||
const collapsed = ref(window.innerWidth < 800);
|
||||
|
||||
@@ -18,9 +18,19 @@ function onResize() {
|
||||
onMounted(() => window.addEventListener("resize", onResize));
|
||||
onUnmounted(() => window.removeEventListener("resize", onResize));
|
||||
|
||||
const logoutOptions = [
|
||||
{ label: "退出当前系统", key: "logout" },
|
||||
{ label: "注销当前账号", key: "revoke" },
|
||||
];
|
||||
|
||||
function onMenu(key: string) {
|
||||
if (key === "home") page.value = key;
|
||||
}
|
||||
|
||||
function onLogout(key: string) {
|
||||
if (key === "revoke") emit("revoke");
|
||||
else emit("logout");
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -64,14 +74,11 @@ function onMenu(key: string) {
|
||||
</template>
|
||||
{{ isDark ? "切换到日间" : "切换到夜间" }}
|
||||
</n-tooltip>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-button class="logout-btn" quaternary circle size="small" aria-label="退出" @click="emit('logout')">
|
||||
<template #icon><n-icon><LogOutOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</template>
|
||||
退出
|
||||
</n-tooltip>
|
||||
<n-dropdown trigger="hover" 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>
|
||||
</n-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</n-layout-sider>
|
||||
|
||||
Reference in New Issue
Block a user