(#22) Add Data Modular.

This commit is contained in:
MrKBear 2022-01-28 08:41:22 +08:00
parent f2f68c1f4a
commit 2fd3f5a0db
2 changed files with 109 additions and 35 deletions

View File

@ -32,11 +32,6 @@ interface ILoginOutput {
*/
actualName: string;
/**
*
*/
isSubscribeWxAccount: boolean;
/**
* session
*/

View File

@ -1,12 +1,46 @@
import { Data } from "../core/Data";
import { Storage } from "../core/Storage";
import { Login, ILoginOutput } from "../api/Login";
/**
*
*/
enum LoginStatus {
/**
*
*/
verified = 1,
/**
*
*
*/
invalid = 2,
/**
*
*/
none = 3
}
/**
* API
*/
type ILoginApiData = {
[P in keyof ILoginOutput]: {
type: ILoginOutput[P];
getAsync: () => Promise<ILoginOutput[P]>;
}
}
/**
* Storage
*/
type IStudentInfoStorageData = ILoginOutput & {
[P in keyof IStudentInfoData]: IStudentInfoData[P]["type"];
};
/**
*
*/
@ -27,49 +61,94 @@ type IStudentInfoData = {
};
/**
*
*
*
*/
idCardLast6: {
type: string
};
loginStatus: {
type: LoginStatus
}
/**
* 使
*
*
*/
eduService: {
type: string
};
lastLoginTime: {
type: number
}
/**
*
*
*
*/
actualName: {
type: string
};
/**
*
*/
isSubscribeWxAccount: {
isUserInfoChange: {
type: boolean
};
/**
* session
*/
eduSession: {
type: string
};
}
}
/**
*
*/
class StudentInfo extends Data<IStudentInfoData> {
class StudentInfo extends Data<IStudentInfoData & ILoginApiData> {
/**
*
*/
private eduStorage = new Storage<IStudentInfoStorageData>("StudentInfo", {
idCardLast6: "",
eduService: "",
actualName: "",
eduSession: "",
studentId: "",
password: "",
loginStatus: LoginStatus.none,
lastLoginTime: 0,
isUserInfoChange: false
});
public override onLoad() {
}
/**
*
*/
private async login(): Promise<boolean> {
// 获取账号密码
const stuId = this.eduStorage.get("studentId");
const pwd = this.eduStorage.get("password");
if (!stuId || !pwd) return false;
// 发送请求
const data = await new Login().param({
studentId: stuId,
password: pwd
}).request().wait();
// 请求成功
let res = data.data;
if (res) {
// 保存数据
this.eduStorage.set("actualName", res.actualName);
this.eduStorage.set("eduService", res.eduService);
this.eduStorage.set("eduSession", res.eduSession);
this.eduStorage.set("idCardLast6", res.idCardLast6);
// 记录时间
this.eduStorage.set("lastLoginTime", new Date().getTime());
return true;
} else {
return false;
}
}
/**
*
*/
private async getStatus() {}
}
export { StudentInfo };
export default StudentInfo;