From 5d2014516d9eb3c869936d2a233fca29ee2b8a78 Mon Sep 17 00:00:00 2001
From: hnu202326010131 <2950457847@qq.com>
Date: Thu, 8 Jan 2026 10:39:59 +0000
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=BC=94=E7=A4=BA?=
=?UTF-8?q?=E8=B4=A6=E5=8F=B7=E9=80=BB=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0?=
=?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=E6=8F=90=E7=A4=BA=EF=BC=8C?=
=?UTF-8?q?=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=90=8E=E7=AB=AF=E5=BC=82=E5=B8=B8?=
=?UTF-8?q?=E6=97=B6=E7=9A=84=E8=87=AA=E5=8A=A8=E7=99=BB=E5=87=BA=E7=AB=9E?=
=?UTF-8?q?=E4=BA=89=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
frontend-vue/src/app/lib/api.ts | 8 ++++++++
frontend-vue/src/app/stores/auth.ts | 21 ++++++++++++++++++-
frontend-vue/src/app/views/Login.vue | 30 +++++++++++++++++++++++++++-
3 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/frontend-vue/src/app/lib/api.ts b/frontend-vue/src/app/lib/api.ts
index e8745c0..b84b22c 100644
--- a/frontend-vue/src/app/lib/api.ts
+++ b/frontend-vue/src/app/lib/api.ts
@@ -140,6 +140,14 @@ api.interceptors.response.use(
if (status === 401) {
const auth = useAuthStore()
+ const url = error.config?.url || ''
+ // 如果是演示 Token,或者是一些基础检查接口,不触发自动登出
+ if (auth.token?.startsWith('demo.') || url.includes('/v1/health') || url.includes('/v1/auth/me')) {
+ return Promise.reject({
+ ...error,
+ friendlyMessage: '鉴权失效 (演示模式或基础接口)'
+ })
+ }
const current = window.location.hash.startsWith('#') ? window.location.hash.slice(1) : window.location.hash
auth.logout()
if (!window.location.hash.includes('login')) {
diff --git a/frontend-vue/src/app/stores/auth.ts b/frontend-vue/src/app/stores/auth.ts
index c7943c9..40c2ee5 100644
--- a/frontend-vue/src/app/stores/auth.ts
+++ b/frontend-vue/src/app/stores/auth.ts
@@ -58,6 +58,16 @@ export const useAuthStore = defineStore('auth', {
},
async login(username: string, password: string) {
try {
+ // 特例处理演示账号:账号密码均为 123 时,直接以管理员身份登录
+ if (username === '123' && password === '123') {
+ const token = makeDemoToken()
+ this.user = { id: 888, username: 'demo-admin', role: 'admin' }
+ this.token = token
+ this.refreshToken = 'demo-refresh-token'
+ this.persist()
+ return { ok: true, role: 'admin' }
+ }
+
const r: any = await AuthService.login({ username, password })
const token = r?.token
const refreshToken = r?.refreshToken || r?.refresh_token || r?.tokens?.refresh || null
@@ -95,6 +105,15 @@ export const useAuthStore = defineStore('auth', {
return { ok: false, message: e.friendlyMessage || '注册失败' }
}
},
- logout() { this.user = null; this.token = null; this.refreshToken = null; this.persist() }
+ logout() {
+ // 如果是演示账号,忽略来自 API 拦截器的登出请求,防止在后端异常时被强制踢出
+ if (this.token?.startsWith('demo.')) {
+ return
+ }
+ this.user = null;
+ this.token = null;
+ this.refreshToken = null;
+ this.persist()
+ }
}
})
diff --git a/frontend-vue/src/app/views/Login.vue b/frontend-vue/src/app/views/Login.vue
index 578cd5f..9524bcb 100644
--- a/frontend-vue/src/app/views/Login.vue
+++ b/frontend-vue/src/app/views/Login.vue
@@ -56,6 +56,11 @@
还没有账号?