fix: 登录失效后回到登录页并只提示一次

This commit is contained in:
2026-10-25 07:37:08 +08:00
parent 07180b162b
commit 8a23318862
3 changed files with 18 additions and 2 deletions
+15 -1
View File
@@ -5,15 +5,29 @@ import LoginView from "./features/auth/LoginView.vue";
import Shell from "./shell/Shell.vue";
import type { UserInfo } from "./features/auth/api";
import { isDark, themeOverrides } from "./shared/theme";
import { clearUnauthorized, setUnauthorizedHandler } from "./shared/http";
const user = ref<UserInfo | null>(null);
const authNotice = ref("");
setUnauthorizedHandler(() => {
if (!user.value) return;
user.value = null;
authNotice.value = "登录已失效,请重新登录";
});
function onSuccess(next: UserInfo) {
authNotice.value = "";
clearUnauthorized();
user.value = next;
}
</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">
<div class="app-root">
<LoginView v-if="!user" @success="user = $event" />
<LoginView v-if="!user" :notice="authNotice" @success="onSuccess" />
<Shell v-else :user="user" @logout="user = null" />
</div>
</n-message-provider>
+2
View File
@@ -6,6 +6,7 @@ import { ApiError } from "../../shared/http";
import { loadCaptcha, loadSaved, login, refreshCaptcha, resumeSaved, sendSms, type UserInfo } from "./api";
import { isDark, toggleTheme } from "../../shared/theme";
defineProps<{ notice?: string }>();
const emit = defineEmits<{ success: [user: UserInfo] }>();
const ready = ref(false);
@@ -186,6 +187,7 @@ onUnmounted(stopCountdown);
</div>
</div>
<n-alert v-if="notice" type="warning" style="margin-bottom: 12px">{{ notice }}</n-alert>
<n-spin :show="!ready && !offline">
<n-alert v-if="!ready" type="warning" style="margin-bottom: 12px">连接失败,正在重试。</n-alert>
<n-alert v-else-if="offline" type="warning" style="margin-bottom: 12px">{{ offline }}</n-alert>
@@ -59,7 +59,7 @@ async function refresh() {
jobs.value = result.jobs;
lastError = "";
} catch (error) {
if (!(error instanceof ApiError) || error.status === 0) return;
if (!(error instanceof ApiError) || error.status === 0 || error.status === 401) return;
if (error.message === lastError) return;
lastError = error.message;
message.error(error.message);