fix: 修复问题

- 修复刷课错误不会停止
- 添加课程刷新
- 添加课程列表、记录列表缓存
- 显示当前版本
This commit is contained in:
2026-03-28 19:22:31 +08:00
parent 6325b84ca0
commit 9e7131f210
8 changed files with 347 additions and 32 deletions

View File

@@ -24,7 +24,7 @@ export type LoginReq = {
};
export type LoginData = {
courses: CourseType[];
courses?: CourseType[];
session_id: string;
user: userInfoType;
};
@@ -103,12 +103,32 @@ export type HostRes = ApiResponse<{
list: HostItem[];
}>;
export type VersionData = {
BuildAt: string;
GitAuthor: string;
GitCommit: string;
GitEmail: string;
Version: string;
};
export type VersionRes = ApiResponse<VersionData>;
export type RecordReq = {
course_id: string;
page: number;
record_type?: RecordType;
};
export type CourseReq = {
status: CourseKind;
};
export type CourseData = {
courses: CourseType[];
};
export type CourseRes = ApiResponse<CourseData>;
export type StudyReq = {
node_id: string;
study_id: string;
@@ -131,11 +151,13 @@ export type StudyRunnerPayload = {
intervalSeconds: number;
items: StudyRunnerItem[];
isRunningStudy: Accessor<boolean>;
setIsRunningStudy: () => void;
client: WkClient;
onLog?: (message: string, accoundID: string) => void;
};
export type WkClient = {
courseApi: (payload: CourseReq) => Promise<CourseRes>;
recordApi: (payload: RecordReq) => Promise<RecordRes>;
studyApi: (payload: StudyReq) => Promise<StudyRes>;
logoutApi: () => Promise<LogoutRes>;
@@ -147,6 +169,9 @@ export const loginApi = async (payload: LoginReq) => {
};
const createWkClientFromHttp = (client: HttpClient): WkClient => ({
courseApi(payload) {
return client.post<CourseRes>("/api/v2/course", payload);
},
recordApi(payload) {
return client.post<RecordRes>("/api/v2/record", payload);
},
@@ -189,6 +214,12 @@ export const runStudyQueue = async (_payload: StudyRunnerPayload) => {
study_time: String(currentTime),
status: count === 0 ? 1 : currentTime >= total ? 3 : 2,
});
if (!resp.data.state) {
_payload.onLog?.(`⛔ 自动停止: ${resp.data.msg}`, _payload.accountId);
_payload.setIsRunningStudy();
return;
}
study_id = resp.data.studyId;
if (currentTime === total) break;
@@ -208,3 +239,7 @@ export const runStudyQueue = async (_payload: StudyRunnerPayload) => {
export const hostApi = async () => {
return await http.get<HostRes>("/api/v1/host");
};
export const versionApi = async () => {
return await http.get<VersionRes>("/api/version");
};