Skip to content

Commit fc2dedb

Browse files
committed
feat(clients): 添加考试成绩获取
1 parent 18864f5 commit fc2dedb

File tree

4 files changed

+254
-5
lines changed

4 files changed

+254
-5
lines changed

clients/course-client.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import type { AxiosInstance } from 'axios';
22
import axios from 'axios';
33
import { useCookie } from '@/utils/use-cookie';
44
import type HUST from '..';
5-
import { getPhysicsCourseGrades, getPhysicsCourseSchedule as getPhysicsCourseSchedule } from './course/physics';
6-
import { getNormalCourseSchedule } from './course/course';
5+
import {
6+
getPhysicsCourseGrades,
7+
getPhysicsCourseSchedule as getPhysicsCourseSchedule,
8+
} from './course/physics';
9+
import {
10+
getNormalCourseGrades,
11+
getNormalCourseSchedule,
12+
} from './course/course';
713

814
export default class CourseClient {
915
protected readonly axios: AxiosInstance;
@@ -40,4 +46,29 @@ export default class CourseClient {
4046
getNormalCourseSchedule(this.axios, semesterId),
4147
);
4248
}
43-
}
49+
50+
async getNormalCourseGrades(
51+
semesterId: string,
52+
{
53+
all,
54+
pageNumber,
55+
pageSize,
56+
}: {
57+
all?: boolean;
58+
pageNumber?: number;
59+
pageSize?: number;
60+
} = {
61+
all: false,
62+
pageNumber: 1,
63+
pageSize: 20,
64+
},
65+
) {
66+
if (all) {
67+
pageNumber = 1;
68+
pageSize = 100;
69+
}
70+
return await this.hust.handleRequest(() =>
71+
getNormalCourseGrades(this.axios, semesterId, pageNumber, pageSize),
72+
);
73+
}
74+
}

clients/course/course.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type {
2+
NormalCourseGrade,
3+
NormalCourseGradesResponse,
24
NormalCourseSchedule,
35
NormalCourseScheduleResponse,
46
} from '@/types/clients/course/course';
@@ -157,3 +159,44 @@ export async function getNormalCourseSchedule(
157159
throw e;
158160
}
159161
}
162+
163+
export async function getNormalCourseGrades(
164+
axios: AxiosInstance,
165+
semesterId: string,
166+
pageNumber: number = 1,
167+
pageSize: number = 20,
168+
): Promise<NormalCourseGrade[]> {
169+
const params = new URLSearchParams();
170+
params.append('XQH', semesterId);
171+
params.append('pageNum', String(pageNumber));
172+
params.append('pageSize', String(pageSize));
173+
const url = `https://hubs.hust.edu.cn/student/gradeSelect/queryResults?${params.toString()}`;
174+
175+
try {
176+
const response = await axios.get(url);
177+
if (response.status !== 200) {
178+
throw new Error(
179+
`Error fetching course grades for semester ${semesterId}.`,
180+
);
181+
}
182+
const data: NormalCourseGradesResponse = response.data;
183+
184+
return data.list.map((item) => ({
185+
className: item.BJMC,
186+
scoreType: item.CJLX,
187+
courseId: item.KCBH,
188+
courseName: item.KCMC,
189+
studentId: item.XH,
190+
score: item.XSCJ,
191+
hundredScore: item.BFCJ,
192+
evaluationStatus: item.SFPJ,
193+
studentName: item.XM,
194+
semesterId: item.XQH,
195+
totalCredits: item.ZXF,
196+
schoolName: item.YXSMC,
197+
}));
198+
} catch (e) {
199+
console.error('CourseClient.getNormalCourseGrades error on fetching', e);
200+
throw e;
201+
}
202+
}

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ console.log('Initializing HUST SDK...');
267267
const res = await hust.news.getNewsList();
268268
console.log('News List:', res);
269269

270-
const res2 = await hust.course.getNormalCourseSchedule('20242');
271-
console.log('Course Schedule:', res2);
270+
const res2 = await hust.course.getNormalCourseGrades('20241', { all: true });
271+
console.log('Course Grades:', res2);
272272

273273
console.log(`initialized after ${new Date().getTime() - now.getTime()}ms`);

types/clients/course/course.ts

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,179 @@ export type NormalCourseSchedule = CourseSchedule & {
139139
* 学期号
140140
*/
141141
semesterId: string;
142+
}
143+
144+
export type NormalCourseGradesResponseItem = {
145+
/**
146+
* 百分成绩
147+
*/
148+
BFCJ: number;
149+
/**
150+
* 班级名称
151+
*/
152+
BJMC: string;
153+
/**
154+
* 成绩类型
155+
*/
156+
CJLX: string;
157+
/**
158+
* ?
159+
*/
160+
DFFSDM: string;
161+
/**
162+
* ?
163+
*/
164+
HDCJFS: string;
165+
/**
166+
* 课程编号
167+
*/
168+
KCBH: string;
169+
/**
170+
* 课程名称
171+
*/
172+
KCMC: string;
173+
/**
174+
* ?
175+
*/
176+
KGZT: string;
177+
/**
178+
* ?
179+
*/
180+
KSQKZCM: string;
181+
/**
182+
* 行编号
183+
*/
184+
PAGEHELPER_ROW_ID: number;
185+
/**
186+
* 行编号
187+
*/
188+
RANK: number;
189+
/**
190+
* 身份 ID?
191+
*/
192+
SFID: string;
193+
/**
194+
* ?
195+
*/
196+
SFJRJQ: string;
197+
/**
198+
* 是否评价
199+
*/
200+
SFPJ: string;
201+
/**
202+
* 学号
203+
*/
204+
XH: string;
205+
/**
206+
* ?
207+
*/
208+
XKXZDM: string;
209+
/**
210+
* 姓名
211+
*/
212+
XM: string;
213+
/**
214+
* 学期
215+
*/
216+
XQ: string;
217+
/**
218+
* 学期号
219+
*/
220+
XQH: string;
221+
/**
222+
* 学生成绩
223+
*/
224+
XSCJ: string;
225+
/**
226+
* 院系名称
227+
*/
228+
YXSMC: string;
229+
/**
230+
* 总学分
231+
*/
232+
ZXF: number;
233+
}
234+
235+
export type NormalCourseGradesResponse = {
236+
/**
237+
* 结束行号
238+
*/
239+
endRow: number;
240+
/**
241+
* 是否有下一页
242+
*/
243+
hasNextPage: boolean;
244+
/**
245+
* 是否有上一页
246+
*/
247+
hasPreviousPage: boolean;
248+
/**
249+
* 是否为第一页
250+
*/
251+
isFirstPage: boolean;
252+
/**
253+
* 是否为最后一页
254+
*/
255+
isLastPage: boolean;
256+
list: NormalCourseGradesResponseItem[];
257+
/**
258+
* 第一页页码
259+
*/
260+
navigateFirstPage: number;
261+
/**
262+
* 最后一页页码
263+
*/
264+
navigateLastPage: number;
265+
/**
266+
* 可导航页码列表
267+
*/
268+
navigatepageNums: number[];
269+
navigatePages: number;
270+
/**
271+
* 下一页页码
272+
*/
273+
nextPage: number;
274+
/**
275+
* 页码
276+
*/
277+
pageNum: number;
278+
/**
279+
* 总页数
280+
*/
281+
pages: number;
282+
/**
283+
* 单页数据量
284+
*/
285+
pageSize: number;
286+
/**
287+
* 上一页页码
288+
*/
289+
prePage: number;
290+
/**
291+
* 单页数据量
292+
*/
293+
size: number;
294+
/**
295+
* 起始行号
296+
*/
297+
startRow: number;
298+
/**
299+
* 科目门数
300+
*/
301+
total: number;
302+
}
303+
304+
export type NormalCourseGrade = {
305+
className: string;
306+
scoreType: string;
307+
courseId: string;
308+
courseName: string;
309+
studentId: string;
310+
score: string;
311+
hundredScore: number;
312+
evaluationStatus: string;
313+
studentName: string;
314+
semesterId: string;
315+
totalCredits: number;
316+
schoolName: string;
142317
}

0 commit comments

Comments
 (0)