Reviewed-on: http://git.mrkbear.com/MrKBear/mini-dlpu-v3/pulls/51
This commit is contained in:
commit
96b3414d22
110
miniprogram/api/Schedule.ts
Normal file
110
miniprogram/api/Schedule.ts
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
import { HTTPMethod, IParamSetting } from "../core/Api";
|
||||||
|
import { EduBase } from "./EduBase";
|
||||||
|
|
||||||
|
interface IScheduleInput {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* session
|
||||||
|
*/
|
||||||
|
cookie: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 学期
|
||||||
|
*/
|
||||||
|
semester: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IClassData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 课程名字
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上课地点
|
||||||
|
*/
|
||||||
|
room?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 课程老师
|
||||||
|
*/
|
||||||
|
teacher?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 周数
|
||||||
|
*/
|
||||||
|
week: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type IScheduleOutput = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 课程列表
|
||||||
|
*/
|
||||||
|
classList: IClassData[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 稀疏矩阵编号
|
||||||
|
*/
|
||||||
|
index: number;
|
||||||
|
}[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedule API
|
||||||
|
* 需要session与semester
|
||||||
|
* 此 API 用来向教务处发起获取课程表的请求
|
||||||
|
* 请求成功后将获得教务处返回的课程表JSON文件
|
||||||
|
*/
|
||||||
|
class Schedlue extends EduBase<IScheduleInput, IScheduleOutput> {
|
||||||
|
|
||||||
|
public override url = "/course_timetable";
|
||||||
|
|
||||||
|
public override method: HTTPMethod = HTTPMethod.GET;
|
||||||
|
|
||||||
|
public override params: IParamSetting<IScheduleInput> = {
|
||||||
|
|
||||||
|
cookie: {
|
||||||
|
mapKey: "cookie",
|
||||||
|
isHeader: true
|
||||||
|
},
|
||||||
|
|
||||||
|
semester: {
|
||||||
|
mapKey: "semester",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
super();
|
||||||
|
this.initDebugLabel("Schedule");
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Schedlue };
|
||||||
|
export default Schedlue;
|
@ -1,5 +1,6 @@
|
|||||||
import { Modular, Manager, ILifetime } from "../../core/Module";
|
import { Modular, Manager, ILifetime } from "../../core/Module";
|
||||||
import { Login } from "../../api/Login";
|
import { Login } from "../../api/Login";
|
||||||
|
import { Schedlue } from "../../api/Schedule"
|
||||||
import { Storage } from "../../core/Storage";
|
import { Storage } from "../../core/Storage";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,12 +29,14 @@ implements Partial<ILifetime> {
|
|||||||
s.set("be", 12);
|
s.set("be", 12);
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
// new Login().param({studentId: "1806240113", password: ""})
|
// new Login().param({studentId: "2017060129", password: ""})
|
||||||
// .request().wait({
|
// .request().wait({
|
||||||
// ok: (w) => {console.log("ok", w)},
|
// ok: (w) => {console.log("ok", w)},
|
||||||
// no: (w) => {console.log("no", w)},
|
// no: (w) => {console.log("no", w)},
|
||||||
// done: (w) => {console.log("done", w)}
|
// done: (w) => {console.log("done", w)}
|
||||||
// });
|
// });
|
||||||
|
// new Schedlue().param({cookie:"C729D1AB1B17077485ACCD9279135C22",semester:"2020-2021-2"})
|
||||||
|
// .request()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user