feat: add multi-account log center

This commit is contained in:
2026-03-27 17:55:01 +08:00
parent 45d4f2b008
commit 58d551eda6
8 changed files with 509 additions and 106 deletions

View File

@@ -4,6 +4,22 @@ import type { CourseKind, RecordItem, RecordType } from "~/service/wk";
import type { CourseType } from "~/types/Course";
import type { userInfoType } from "~/types/Userinfo";
const withLogTimestamp = (message: string) => {
if (/^\[\d{2}:\d{2}:\d{2}\]\s/.test(message)) {
return message;
}
const now = new Date();
const timestamp = now.toLocaleTimeString("zh-CN", {
hour12: false,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
return `[${timestamp}] ${message}`;
};
export type AccountAuth = {
password: string;
token: string;
@@ -37,6 +53,7 @@ type AccountState = {
setAccountRunningStudy: (accountId: string, value: boolean) => void;
appendStudyLog: (accountId: string, message: string) => void;
clearStudyLogs: (accountId: string) => void;
clearAllStudyLogs: () => void;
upsertAccount: (account: AccountItem) => void;
removeAccount: (accountId: string) => void;
};
@@ -70,7 +87,10 @@ export const accountStore = createStore<AccountState>()(
set((state) => ({
studyLogsMap: {
...state.studyLogsMap,
[accountId]: [...(state.studyLogsMap[accountId] ?? []), message],
[accountId]: [
...(state.studyLogsMap[accountId] ?? []),
withLogTimestamp(message),
],
},
})),
clearStudyLogs: (accountId) =>
@@ -80,6 +100,10 @@ export const accountStore = createStore<AccountState>()(
[accountId]: [],
},
})),
clearAllStudyLogs: () =>
set({
studyLogsMap: {},
}),
upsertAccount: (account) =>
set((state) => ({
accounts: [