立项配置页初步优化

This commit is contained in:
Cheng Zhou
2026-02-24 16:53:22 +08:00
parent 0693f09b1d
commit 8f3f717e48
124 changed files with 12519 additions and 2954 deletions
+8
View File
@@ -4,8 +4,10 @@ import { login as apiLogin, fetchMe } from "../api/auth";
import { setToken, clearToken, getToken } from "../utils/auth";
import type { UserInfo } from "../types/api";
import { useStudyStore } from "./study";
import { useSessionStore } from "./session";
export const useAuthStore = defineStore("auth", () => {
const LAST_LOGIN_EMAIL_KEY = "ctms_last_login_email";
const token = ref<string | null>(getToken());
const user = ref<UserInfo | null>(null);
const loading = ref(false);
@@ -17,6 +19,9 @@ export const useAuthStore = defineStore("auth", () => {
const { data } = await apiLogin({ email, password });
token.value = data.access_token;
setToken(data.access_token);
// 避免锁屏态下 fetchMe 被请求拦截
useSessionStore().unlock();
localStorage.setItem(LAST_LOGIN_EMAIL_KEY, email);
await fetchMeAction();
forceLogin.value = false;
} finally {
@@ -27,6 +32,9 @@ export const useAuthStore = defineStore("auth", () => {
const fetchMeAction = async () => {
const { data } = await fetchMe();
user.value = data;
if (data?.email) {
localStorage.setItem(LAST_LOGIN_EMAIL_KEY, data.email);
}
return data;
};
+9 -1
View File
@@ -6,7 +6,9 @@ export type LockReason = "idle" | "extend_failed" | "token_invalid";
export const useSessionStore = defineStore("session", () => {
const locked = ref(false);
const lockReason = ref<LockReason | null>(null);
const lockEmail = ref<string>("");
const unlockAttempts = ref(0);
const lockAutoLogoutDeadlineAt = ref(0);
const lastUserActiveAt = ref(Date.now());
const lastNetworkActiveAt = ref(Date.now());
const lastExtendAt = ref(0);
@@ -19,14 +21,18 @@ export const useSessionStore = defineStore("session", () => {
lastNetworkActiveAt.value = ts;
};
const lock = (reason: LockReason) => {
const lock = (reason: LockReason, email?: string, autoLogoutDeadlineAt?: number) => {
locked.value = true;
lockReason.value = reason;
lockEmail.value = (email || "").trim();
lockAutoLogoutDeadlineAt.value = autoLogoutDeadlineAt || 0;
};
const unlock = () => {
locked.value = false;
lockReason.value = null;
lockEmail.value = "";
lockAutoLogoutDeadlineAt.value = 0;
unlockAttempts.value = 0;
};
@@ -41,6 +47,8 @@ export const useSessionStore = defineStore("session", () => {
return {
locked,
lockReason,
lockEmail,
lockAutoLogoutDeadlineAt,
unlockAttempts,
lastUserActiveAt,
lastNetworkActiveAt,