feat: add multi-account log center
This commit is contained in:
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user