10 Commits
12 changed files with 247 additions and 314 deletions
+95
View File
@@ -0,0 +1,95 @@
import { API, IAnyData, GeneralCallbackResult } from "../core/Api";
import { EventType } from "../core/Emitter";
interface ILoginEvent {
/**
* session 过期
*/
expire: GeneralCallbackResult;
/**
* 登录失败
*/
unauthorized: GeneralCallbackResult;
/**
* 未知的问题
*/
error: GeneralCallbackResult;
/**
* 数据损坏或丢失
*/
badData: GeneralCallbackResult;
}
/**
* 教务处基础 API
* @template I API 输入数据
* @template O API 输出数据
* @template E API 中的事件
* @template U 用户自定义的输出数据
*/
abstract class EduBase<
I extends IAnyData = IAnyData,
O extends IAnyData = IAnyData,
E extends Record<EventType, any> = {}
> extends API<I, O, {
[P in (keyof ILoginEvent | keyof E)]: P extends keyof ILoginEvent ? ILoginEvent[P] : E[P]
}> {
protected useEduCallback(
parseFunction: (data: any) => O
): void {
this.addFailedCallBack();
this.on("success", (data) => {
let isSuccess = true;
let errMsg = "";
let res: O | undefined;
const info: any = data.data;
// 数据缺失检测
if(!info) {
isSuccess = false;
errMsg = "Bad Data";
this.emit("badData", { errMsg });
}
if (isSuccess) switch (info.code) {
case (1):
res = parseFunction(info.data);
errMsg = info.err_msg ?? "Success";
this.emit("ok", res!);
break;
case (2):
isSuccess = false;
errMsg = info.err_msg ?? "Session Expire";
this.emit("expire", { errMsg });
break;
case (3):
isSuccess = false;
errMsg = info.err_msg ?? "Unauthorized";
this.emit("unauthorized", { errMsg });
break;
case (4):
isSuccess = false;
errMsg = info.err_msg ?? "Error";
this.emit("error", { errMsg });
break;
}
if (!isSuccess) this.emit("no", { errMsg });
this.emit("done", { errMsg, data: res });
});
}
}
export { EduBase };
export default EduBase;
+10 -76
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 ILoginInput { interface ILoginInput {
@@ -42,35 +43,12 @@ interface ILoginOutput {
eduSession: string; eduSession: string;
} }
interface ILoginEvent {
/**
* session 过期
*/
expire: GeneralCallbackResult;
/**
* 登录失败
*/
unauthorized: GeneralCallbackResult;
/**
* 未知的问题
*/
error: GeneralCallbackResult;
/**
* 数据损坏或丢失
*/
badData: GeneralCallbackResult;
}
/** /**
* Login API * Login API
* 此 API 用来向教务处发起登录请求 * 此 API 用来向教务处发起登录请求
* 请求成功后将获得教务处返回的 session * 请求成功后将获得教务处返回的 session
*/ */
class Login extends API<ILoginInput, ILoginOutput, ILoginEvent> { class Login extends EduBase<ILoginInput, ILoginOutput> {
public override url: string = "/login"; public override url: string = "/login";
@@ -92,57 +70,13 @@ class Login extends API<ILoginInput, ILoginOutput, ILoginEvent> {
super(); super();
this.initDebugLabel("Login"); this.initDebugLabel("Login");
this.addFailedCallBack(); this.useEduCallback((data) => ({
idCardLast6: data.idCard,
this.on("success", (data) => { eduService: data.ip,
actualName: data.name,
let isSuccess = true; isSubscribeWxAccount: data.official,
let errMsg = ""; eduSession: data.session
let res: ILoginOutput | undefined; }));
const info: any = data.data;
// 数据缺失检测
if(!info) {
isSuccess = false;
errMsg = "Bad Data";
this.emit("badData", { errMsg });
}
if (isSuccess) switch (info.code) {
case (1):
res = {
idCardLast6: info.data.idCard,
eduService: info.data.ip,
actualName: info.data.name,
isSubscribeWxAccount: info.data.official,
eduSession: info.data.session
};
errMsg = info.err_msg ?? "Success";
this.emit("ok", res);
break;
case (2):
isSuccess = false;
errMsg = info.err_msg ?? "Session Expire";
this.emit("expire", { errMsg });
break;
case (3):
isSuccess = false;
errMsg = info.err_msg ?? "Unauthorized";
this.emit("unauthorized", { errMsg });
break;
case (4):
isSuccess = false;
errMsg = info.err_msg ?? "Error";
this.emit("error", { errMsg });
break;
}
if (!isSuccess) this.emit("no", { errMsg });
this.emit("done", { errMsg, data: res });
});
} }
} }
+58 -23
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 { interface IScheduleInput {
@@ -13,32 +14,41 @@ interface IScheduleInput {
semester: string; semester: string;
} }
interface IScheduleOutput { interface IClassData {
}
interface IScheduleEvent {
/** /**
* session 过期 * 课程名字
*/ */
expire: GeneralCallbackResult; name: string;
/** /**
* 登录失败 * 上课地点
*/ */
unauthorized: GeneralCallbackResult; room?: string;
/** /**
* 未知的问题 * 课程老师
*/ */
error: GeneralCallbackResult; teacher?: string;
/** /**
* 数据损坏或丢失 *
*/ */
badData: GeneralCallbackResult; week: string;
} }
type IScheduleOutput = {
/**
* 课程列表
*/
classList: IClassData[];
/**
* 稀疏矩阵编号
*/
index: number;
}[];
/** /**
* Schedule API * Schedule API
@@ -46,9 +56,7 @@ interface IScheduleEvent {
* 此 API 用来向教务处发起获取课程表的请求 * 此 API 用来向教务处发起获取课程表的请求
* 请求成功后将获得教务处返回的课程表JSON文件 * 请求成功后将获得教务处返回的课程表JSON文件
*/ */
class Schedlue extends API<IScheduleInput, IScheduleOutput, IScheduleEvent> { class Schedlue extends EduBase<IScheduleInput, IScheduleOutput> {
public override baseUrl: string = "jwc.2333.pub";
public override url = "/course_timetable"; public override url = "/course_timetable";
@@ -70,6 +78,33 @@ class Schedlue extends API<IScheduleInput, IScheduleOutput, IScheduleEvent> {
super(); super();
this.initDebugLabel("Schedule"); 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;
});
} }
} }
export { Schedlue };
export default Schedlue;
+1 -1
View File
@@ -698,4 +698,4 @@ enum HTTPMethod {
} }
export default API; export default API;
export { API, IParamSetting, IAppAPIParam, ICallBack, HTTPMethod, RequestPolicy, GeneralCallbackResult } export { API, IParamSetting, IAppAPIParam, IAnyData, ICallBack, HTTPMethod, RequestPolicy, GeneralCallbackResult }
+37
View File
@@ -1,3 +1,4 @@
@import "../../app.scss";
view.mask { view.mask {
position: fixed; position: fixed;
@@ -6,3 +7,39 @@ view.mask {
background-color: rgba($color: #000000, $alpha: .2); background-color: rgba($color: #000000, $alpha: .2);
z-index: 1; z-index: 1;
} }
view.mask.block {
display: block;
}
view.mask.none {
display: none;
}
view.mask.show {
animation: show .1s cubic-bezier(0, 0, 1, 1) both;
opacity: 1;
}
view.mask.hide {
animation: hide .1s cubic-bezier(0, 0, 1, 1) both;
opacity: 0;
}
@keyframes show{
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes hide{
from {
opacity: 1;
}
to {
opacity: 0;
}
}
+23 -2
View File
@@ -2,6 +2,11 @@ import { Modular, Manager } from "../../core/Module";
class Mask<M extends Manager> extends Modular<M> { class Mask<M extends Manager> extends Modular<M> {
/**
* 动画运行时间
*/
public static readonly animateTime: number = 100;
public data? = { public data? = {
/** /**
@@ -9,6 +14,11 @@ class Mask<M extends Manager> extends Modular<M> {
*/ */
zIndex: 1, zIndex: 1,
/**
* 蒙版是否显示
*/
isDisplay: false,
/** /**
* 蒙版是否显示 * 蒙版是否显示
*/ */
@@ -21,14 +31,25 @@ class Mask<M extends Manager> extends Modular<M> {
* 显示蒙版 * 显示蒙版
*/ */
public showMask() { public showMask() {
this.setData({ isShow: true }); this.setData({
isShow: true,
isDisplay: true
});
} }
/** /**
* 隐藏蒙版 * 隐藏蒙版
*/ */
public hideMask() { public hideMask() {
this.setData({ isShow: false }); this.setData({
isShow: false
});
this.disappearTimer = setTimeout(() => {
this.setData({
isDisplay: false
});
}, Mask.animateTime);
} }
public override onLoad() { public override onLoad() {
-66
View File
@@ -1,66 +0,0 @@
// pages/Account/Account.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
+2 -1
View File
@@ -1,5 +1,6 @@
<!-- 蒙版 --> <!-- 蒙版 -->
<view class="mask" bindtap="mask$handleClickMask" style="display:{{mask$isShow ? 'block' : 'none'}}"></view> <view class="mask {{ mask$isShow ? 'show' : 'hide' }} {{ mask$isDisplay ? 'block' : 'none' }}"
bindtap="mask$handleClickMask"></view>
<!-- 顶部的阴影 --> <!-- 顶部的阴影 -->
<view class="top-shadow"></view> <view class="top-shadow"></view>
@@ -1,66 +0,0 @@
// pages/Information/Information.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
+9 -6
View File
@@ -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: "2017060129", password: "hch2000210%"}) // 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()
} }
} }
-66
View File
@@ -1,66 +0,0 @@
// pages/Timetable/Timetable.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
+9 -4
View File
@@ -25,6 +25,7 @@
"checkSiteMap": true, "checkSiteMap": true,
"uploadWithSourceMap": true, "uploadWithSourceMap": true,
"compileHotReLoad": false, "compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true, "useMultiFrameRuntime": true,
"useApiHook": true, "useApiHook": true,
"useApiHostProcess": true, "useApiHostProcess": true,
@@ -34,14 +35,18 @@
"outputPath": "" "outputPath": ""
}, },
"enableEngineNative": false, "enableEngineNative": false,
"bundle": false,
"useIsolateContext": false, "useIsolateContext": false,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false, "userConfirmedBundleSwitch": false,
"packNpmManually": false, "packNpmManually": false,
"packNpmRelationList": [], "packNpmRelationList": [],
"minifyWXSS": true "minifyWXSS": true,
"disableUseStrict": false,
"minifyWXML": true,
"showES6CompileOption": false,
"useCompilerPlugins": [
"typescript",
"sass"
]
}, },
"simulatorType": "wechat", "simulatorType": "wechat",
"simulatorPluginLibVersion": {}, "simulatorPluginLibVersion": {},