20 Commits
Author SHA1 Message Date
TamakoStar 529011b0dd (#28)Add Schedule API 2022-01-20 23:47:02 +08:00
TamakoStar 4da257c2e2 (#28)Add Schedule API 2022-01-20 22:19:10 +08:00
TamakoStar f11eb63ee1 Merge branch 'master' into dev-tamako 2022-01-20 21:45:30 +08:00
MrKBear 49c4f7f0d4 Merge pull request '(#52) Add EduBase API' (#53) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/mini-dlpu-v3/pulls/53
2022-01-20 21:43:41 +08:00
MrKBear 4158887d2e (#52) Add EduBase API 2022-01-20 21:42:44 +08:00
MrKBear a8e16f5972 (#28) Add output data mod 2022-01-20 20:57:41 +08:00
TamakoStar d9825d6d68 (#28)Add a api frame (incomplete file) 2022-01-20 20:38:57 +08:00
TamakoStar fab73f00ab Merge branch 'master' into dev-tamako 2022-01-20 20:33:02 +08:00
TamakoStar edb26b3d8b Merge branch 'dev-tamako' of http://git.mrkbear.com/MrKBear/mini-dlpu-v3 into dev-tamako 2022-01-20 20:31:52 +08:00
TamakoStar 443f82ea75 (#28)Add a api frame (incomplete file) 2022-01-20 20:30:36 +08:00
TamakoStar 75adb97abb (#28)Add a api frame (incomplete file) 2022-01-20 20:17:32 +08:00
MrKBear b36996e352 Merge pull request '(#35) Add mask show hide motion' (#50) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/mini-dlpu-v3/pulls/50
2022-01-20 17:20:42 +08:00
MrKBear 6bef08f12e (#35) Add mask show hide motion 2022-01-20 17:18:44 +08:00
MrKBear 1f24a59bd9 Merge pull request '(#48) Core Api baseUrl param can be overridden' (#49) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/mini-dlpu-v3/pulls/49
2022-01-20 16:11:42 +08:00
MrKBear 14d0c9c123 (#48) Core Api baseUrl param can be overridden 2022-01-20 16:10:55 +08:00
MrKBear b99a3412e2 Merge pull request '(#37) Optimize Account page' (#47) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/mini-dlpu-v3/pulls/47
2022-01-20 13:27:16 +08:00
MrKBear 63300f68f8 (#37) Optimize Account page 2022-01-20 13:26:24 +08:00
MrKBear acf4f94798 Merge pull request '(#45) Optimize Modular loading performance' (#46) from dev-mrkbear into master
Reviewed-on: http://git.mrkbear.com/MrKBear/mini-dlpu-v3/pulls/46
2022-01-20 11:53:14 +08:00
MrKBear 87f4d220e5 (#45) Optimize Modular loading performance 2022-01-20 11:52:10 +08:00
TamakoStar 7a5d43281b Add Schedule Api file 2022-01-17 22:52:51 +08:00
13 changed files with 386 additions and 145 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 {
@@ -42,35 +43,12 @@ interface ILoginOutput {
eduSession: string;
}
interface ILoginEvent {
/**
* session 过期
*/
expire: GeneralCallbackResult;
/**
* 登录失败
*/
unauthorized: GeneralCallbackResult;
/**
* 未知的问题
*/
error: GeneralCallbackResult;
/**
* 数据损坏或丢失
*/
badData: GeneralCallbackResult;
}
/**
* Login API
* 此 API 用来向教务处发起登录请求
* 请求成功后将获得教务处返回的 session
*/
class Login extends API<ILoginInput, ILoginOutput, ILoginEvent> {
class Login extends EduBase<ILoginInput, ILoginOutput> {
public override url: string = "/login";
@@ -92,57 +70,13 @@ class Login extends API<ILoginInput, ILoginOutput, ILoginEvent> {
super();
this.initDebugLabel("Login");
this.addFailedCallBack();
this.on("success", (data) => {
let isSuccess = true;
let errMsg = "";
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 });
});
this.useEduCallback((data) => ({
idCardLast6: data.idCard,
eduService: data.ip,
actualName: data.name,
isSubscribeWxAccount: data.official,
eduSession: data.session
}));
}
}
+110
View 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;
+9 -8
View File
@@ -168,17 +168,18 @@ class API<
> {
/**
* 基础 URL
* TODO: 这里可能涉及负载均衡
* 默认调试标签
*/
public static get baseUrl():string {
return "https://jwc.nogg.cn";
}
public static defaultLogLabel:LogLabel = new LogLabel(
`API:API`, colorRadio(200, 120, 222)
);
/**
* 基础 URL
* TODO: 这里可能涉及负载均衡
*/
public baseUrl: string = "https://jwc.nogg.cn";
/**
* Logger 使用的标签
*/
@@ -319,7 +320,7 @@ class API<
// 重置请求数据
const requestData:IWxRequestOption<O> = this.requestData = {
url: API.baseUrl + this.url,
url: this.baseUrl + this.url,
data: {}, header: {},
timeout: this.timeout,
method: this.method,
@@ -697,4 +698,4 @@ enum HTTPMethod {
}
export default API;
export { API, IParamSetting, IAppAPIParam, ICallBack, HTTPMethod, RequestPolicy, GeneralCallbackResult }
export { API, IParamSetting, IAppAPIParam, IAnyData, ICallBack, HTTPMethod, RequestPolicy, GeneralCallbackResult }
+21
View File
@@ -491,6 +491,27 @@ class Manager<WXC extends AnyWXContext = AnyWXContext> {
})
}
/**
* 异步页面加载
*
* *注意*
* 页面模块加载后,必须手动执行 loadAllModule
* loadAllModule Modular 才会真正的被加载
* 模块加载后可以处理逻辑绑定
*/
public static async PageAsync(): Promise<{
manager: Manager<AnyWXContext>,
query: Record<string, string | undefined>
}> {
return new Promise((solve) => {
Page({
async onLoad(query) {
let manager = new Manager(this);
await solve({ manager, query });
}
})
});
}
}
export { Manager, Modular, AnyWXContext, WXContext, ILifetime}
+37
View File
@@ -1,3 +1,4 @@
@import "../../app.scss";
view.mask {
position: fixed;
@@ -6,3 +7,39 @@ view.mask {
background-color: rgba($color: #000000, $alpha: .2);
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> {
/**
* 动画运行时间
*/
public static readonly animateTime: number = 100;
public data? = {
/**
@@ -9,6 +14,11 @@ class Mask<M extends Manager> extends Modular<M> {
*/
zIndex: 1,
/**
* 蒙版是否显示
*/
isDisplay: false,
/**
* 蒙版是否显示
*/
@@ -21,14 +31,25 @@ class Mask<M extends Manager> extends Modular<M> {
* 显示蒙版
*/
public showMask() {
this.setData({ isShow: true });
this.setData({
isShow: true,
isDisplay: true
});
}
/**
* 隐藏蒙版
*/
public hideMask() {
this.setData({ isShow: false });
this.setData({
isShow: false
});
this.disappearTimer = setTimeout(() => {
this.setData({
isDisplay: false
});
}, Mask.animateTime);
}
public override onLoad() {
+16 -2
View File
@@ -4,9 +4,23 @@ import { MainFunction } from "./MainFunction";
import { FunctionList } from "./FunctionList";
import { Mask } from "../../modular/Mask/Mask";
Manager.Page((manager) => {
(async () => {
// 初始化页面
const { manager, query } = await Manager.PageAsync();
// 添加蒙版 Modular
const mask = manager.addModule(Mask, "mask");
// 添加 UserCard Modular
manager.addModule(UserCard, "userCard", { mask });
// 添加 MainFunction Modular
manager.addModule(MainFunction, "mainFunction");
// 添加 FunctionList Modular
manager.addModule(FunctionList, "functionList");
});
// 初始化全部 Modular
await manager.loadAllModule(query);
})();
+16 -30
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>
@@ -44,42 +45,27 @@
</view>
<!--主要功能-->
<view class="card main-function"><!--四个功能合在一起的容器-->
<view class="branch-funtion">
<view><!--每个功能的容器-->
<image class="icon" src="../../image/account/Account_UserInfo.svg"></image><!--每个功能的图片-->
<view>账号信息</view><!--每个功能的文字-->
</view>
</view>
<view class="card main-function">
<view class="branch-funtion">
<view>
<image class="icon" src="../../image/account/Account_DateList.svg"></image>
<view>课表缓存</view>
</view>
</view>
<view class="branch-funtion">
<view>
<image class="icon" src="../../image/account/Account_Customer.svg"></image>
<view>功能定制</view>
</view>
</view>
<view class="branch-funtion">
<view style="border-right: 0px;">
<image class="icon" src="../../image/account/Account_Settings.svg"></image>
<view>更多设置</view>
<!--每个功能的容器-->
<view class="branch-funtion" wx:for="{{ mainFunction$mainFunctionList }}" wx:key="index">
<view style="{{ index == (mainFunction$mainFunctionList - 1) ? 'border-bottom: 0px' : '' }}">
<!--每个功能的图片-->
<image class="icon" src="../../image/account/Account_{{ item.iconUrl }}.svg"></image>
<!--每个功能的文字-->
<view>{{ item.displayName }}</view>
</view>
</view>
</view>
<!-- 功能列表 -->
<view class="card function-list">
<view class="function" wx:for="{{functionList$functionList}}" wx:for-index="index" wx:key="id">
<view style="{{item.id == (functionList$functionList.length - 1) ? 'border-bottom: 0px' : ''}}">
<image class="icon func-icon" src="../../image/account/Account_{{item.iconUrl}}.svg" />
<view>{{item.displayName}}</view>
<!-- 每一行 -->
<view class="function" wx:for="{{ functionList$functionList }}" wx:key="index">
<view style="{{ index == (functionList$functionList.length - 1) ? 'border-bottom: 0px' : '' }}">
<image class="icon func-icon" src="../../image/account/Account_{{ item.iconUrl }}.svg" />
<view>{{ item.displayName }}</view>
<image class="icon-sub arrow" src="../../image/account/Account_Arrow.svg" />
</view>
</view>
+3 -18
View File
@@ -2,11 +2,6 @@ import { Modular, Manager } from "../../core/Module";
interface IFunctionListItem {
/**
* id
*/
id?: number
/**
* 显示名称
*/
@@ -18,10 +13,6 @@ interface IFunctionListItem {
iconUrl: string;
}
interface IFunctionListData {
functionList?: IFunctionListItem[];
};
class FunctionList<M extends Manager> extends Modular<M> {
public static readonly functionList: IFunctionListItem[] = [
@@ -32,18 +23,12 @@ class FunctionList<M extends Manager> extends Modular<M> {
{ displayName: "联系客服", iconUrl: "Support" }
];
public data: IFunctionListData = {
functionList: undefined
public data = {
functionList: FunctionList.functionList
};
public override onLoad() {
console.log(FunctionList.functionList)
this.setData({
functionList: FunctionList.functionList.map((value, index) => {
value.id = index;
return value;
})
})
// Do something
}
}
+24
View File
@@ -1,7 +1,31 @@
import { Modular, Manager } from "../../core/Module";
interface IMainFunctionItem {
/**
* 显示名称
*/
displayName: string;
/**
* 图标路径
*/
iconUrl: string;
}
class MainFunction<M extends Manager> extends Modular<M> {
public static readonly MainFunctionList: IMainFunctionItem[] = [
{ displayName: "账号信息", iconUrl: "UserInfo" },
{ displayName: "课表缓存", iconUrl: "DateList" },
{ displayName: "功能定制", iconUrl: "Customer" },
{ displayName: "更多设置", iconUrl: "Settings" }
];
public data? = {
mainFunctionList: MainFunction.MainFunctionList
}
public override onLoad() {
// Do something
}
+9 -6
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: "1806240113", password: "qazxsw123"})
.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()
}
}
+12 -2
View File
@@ -6,7 +6,17 @@ import { TestCore } from "./TestCore";
* 此页面使用 Manager 进行模块化管理
* 若要添加先功能请先定义 Modular 并添加至 Manager
*/
Manager.Page((manager)=>{
(async () => {
// 初始化页面
const { manager, query } = await Manager.PageAsync();
// 添加 StatusBar Modular
manager.addModule(StatusBar, "statusBar");
// 添加 TestCore Modular
manager.addModule(TestCore, "testCore");
})
// 初始化全部 Modular
await manager.loadAllModule(query);
})()