(#28)Add Schedule API

This commit is contained in:
海洋201-胡昌宏 2022-01-20 22:19:10 +08:00
parent f11eb63ee1
commit 4da257c2e2
2 changed files with 39 additions and 34 deletions

View File

@ -1,4 +1,5 @@
import { API, HTTPMethod, IParamSetting, GeneralCallbackResult} from "../core/Api";
import { HTTPMethod, IParamSetting } from "../core/Api";
import { EduBase } from "./EduBase";
interface IScheduleInput {
@ -36,7 +37,7 @@ interface IClassData {
week: string;
}
interface IScheduleOutput {
type IScheduleOutput = {
/**
*
@ -49,38 +50,15 @@ interface IScheduleOutput {
index: number;
}[];
interface IScheduleEvent {
/**
* session
*/
expire: GeneralCallbackResult;
/**
*
*/
unauthorized: GeneralCallbackResult;
/**
*
*/
error: GeneralCallbackResult;
/**
*
*/
badData: GeneralCallbackResult;
}
/**
* Schedule API
* session与semester
* API
* JSON文件
*/
class Schedlue extends API<IScheduleInput, IScheduleOutput, IScheduleEvent> {
class Schedlue extends EduBase<IScheduleInput, IScheduleOutput> {
public override baseUrl: string = "jwc.2333.pub";
public override baseUrl: string = "https://jwc.2333.pub";
public override url = "/course_timetable";
@ -102,7 +80,31 @@ class Schedlue extends API<IScheduleInput, IScheduleOutput, IScheduleEvent> {
super();
this.initDebugLabel("Schedule");
this.addFailedCallBack();
this.useEduCallback((data) => {
const res: IScheduleOutput = [];
for( let i = 0; i < data.length; i++ ) {
const classList: IClassData[] = [];
const CTTDetails = data[i].CTTDetails ?? [];
for( let j = 0; j < CTTDetails.length; j++ ) {
classList.push({
name: CTTDetails[j].Name,
room: CTTDetails[j].Room,
teacher: CTTDetails[j].Teacher,
week: CTTDetails[j].Week,
})
}
res.push({
classList,
index: data[i].Id
})
}
return res;
});
}
}

View File

@ -1,5 +1,6 @@
import { Modular, Manager, ILifetime } from "../../core/Module";
import { Login } from "../../api/Login";
import { Schedlue } from "../../api/Schedule"
import { Storage } from "../../core/Storage";
/**
@ -28,12 +29,14 @@ implements Partial<ILifetime> {
s.set("be", 12);
}, 1000)
new Login().param({studentId: "2017060129", password: "hch2000210%"})
.request().wait({
ok: (w) => {console.log("ok", w)},
no: (w) => {console.log("no", w)},
done: (w) => {console.log("done", w)}
});
// new Login().param({studentId: "2017060129", password: ""})
// .request().wait({
// ok: (w) => {console.log("ok", w)},
// no: (w) => {console.log("no", w)},
// done: (w) => {console.log("done", w)}
// });
// new Schedlue().param({cookie:"C729D1AB1B17077485ACCD9279135C22",semester:"2020-2021-2"})
// .request()
}
}