Compare commits

..

No commits in common. "master" and "dev-sanaesy" have entirely different histories.

24 changed files with 216 additions and 1335 deletions

View File

@ -1,95 +0,0 @@
import { API, IAnyData, GeneralCallbackResult } from "../core/Api";
import { EventType, Emitter } from "../core/Emitter";
type 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 as Emitter<IAnyData>).emit("badData", { errMsg });
}
if (isSuccess) switch (info.code) {
case (1):
res = parseFunction(info.data);
errMsg = info.err_msg ?? "Success";
(this as Emitter<IAnyData>).emit("ok", res!);
break;
case (2):
isSuccess = false;
errMsg = info.err_msg ?? "Session Expire";
(this as Emitter<IAnyData>).emit("expire", { errMsg });
break;
case (3):
isSuccess = false;
errMsg = info.err_msg ?? "Unauthorized";
(this as Emitter<IAnyData>).emit("unauthorized", { errMsg });
break;
case (4):
isSuccess = false;
errMsg = info.err_msg ?? "Error";
(this as Emitter<IAnyData>).emit("error", { errMsg });
break;
}
if (!isSuccess) (this as Emitter<IAnyData>).emit("no", { errMsg });
(this as Emitter<IAnyData>).emit("done", { errMsg, data: res });
});
}
}
export { EduBase };
export default EduBase;

View File

@ -1,5 +1,4 @@
import { HTTPMethod, IParamSetting } from "../core/Api";
import { EduBase } from "./EduBase";
import { API, HTTPMethod, IParamSetting, GeneralCallbackResult } from "../core/Api";
interface ILoginInput {
@ -32,18 +31,46 @@ interface ILoginOutput {
*/
actualName: string;
/**
*
*/
isSubscribeWxAccount: boolean;
/**
* session
*/
eduSession: string;
}
interface ILoginEvent {
/**
* session
*/
expire: GeneralCallbackResult;
/**
*
*/
unauthorized: GeneralCallbackResult;
/**
*
*/
error: GeneralCallbackResult;
/**
*
*/
badData: GeneralCallbackResult;
}
/**
* Login API
* API
* session
*/
class Login extends EduBase<ILoginInput, ILoginOutput> {
class Login extends API<ILoginInput, ILoginOutput, ILoginEvent> {
public override url: string = "/login";
@ -65,13 +92,57 @@ class Login extends EduBase<ILoginInput, ILoginOutput> {
super();
this.initDebugLabel("Login");
this.useEduCallback((data) => ({
idCardLast6: data.idCard,
eduService: data.ip,
actualName: data.name,
isSubscribeWxAccount: data.official,
eduSession: data.session
}));
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 });
});
}
}

View File

@ -1,110 +0,0 @@
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;

View File

@ -16,14 +16,10 @@ $black-filter: brightness(0) opacity(.65);
$white-filter: brightness(100) opacity(.65);
$blue-filter: opacity(1);
@mixin container {
width: 88%;
padding: 0 6%;
}
// 页面容器外边距
view.container {
@include container;
width: 88%;
padding: 0 6%;
}
// 带阴影的 card

View File

@ -1,9 +1,9 @@
import { IAppAPIParam, IAnyData } from "./core/Api";
import { IAppAPIParam } from "./core/Api";
import { IAppStorageParam, Storage, IStorageData } from "./core/Storage";
import { Logger, LevelLogLabel, LifeCycleLogLabel } from "./core/Logger";
App<IAppAPIParam & IAppStorageParam & IAnyData>({
App<IAppAPIParam & IAppStorageParam>({
/**
* API

View File

@ -1,4 +1,4 @@
import { Emitter, EventType, EventMixin } from "./Emitter";
import { Emitter, EventType } from "./Emitter";
import { API_FAILED_SHOW_MESSAGE } from "./Config";
import { Logger, LogLabel, LevelLogLabel, colorRadio, StatusLabel } from "./Logger";
interface IAppAPIParam {
@ -156,20 +156,28 @@ class API<
O extends IAnyData = IAnyData,
E extends Record<EventType, any> = Record<EventType, any>,
U extends IAnyData = IAnyData
> extends Emitter<EventMixin<IAPIEvent<I, O> & IAPIResultEvent<O, U>, E>> {
> extends Emitter <
{
// 这个复杂的泛型是为了 MixIn 用户自定义事件类型
// 懂得如何使用就可以了
// 不要试图去理解下面这三行代码,真正的恶魔在等着你
[P in (keyof (IAPIEvent<I, O> & IAPIResultEvent<O, U>) | keyof E)] :
P extends keyof IAPIEvent<I, O> ? IAPIEvent<I, O>[P] :
P extends keyof IAPIResultEvent<O, U> ? IAPIResultEvent<O, U>[P] : E[P]
}
> {
/**
*
*/
public static defaultLogLabel:LogLabel = new LogLabel(
`API:API`, colorRadio(200, 120, 222)
);
/**
* URL
* TODO: 这里可能涉及负载均衡
*/
public baseUrl: string = "https://jwc.nogg.cn";
public static get baseUrl():string {
return "https://jwc.nogg.cn";
}
public static defaultLogLabel:LogLabel = new LogLabel(
`API:API`, colorRadio(200, 120, 222)
);
/**
* Logger 使
@ -307,11 +315,11 @@ class API<
}
// 触发数据初始化事件
(this as Emitter<IAnyData>).emit("initData", this.data);
this.emit("initData", this.data);
// 重置请求数据
const requestData:IWxRequestOption<O> = this.requestData = {
url: this.baseUrl + this.url,
url: API.baseUrl + this.url,
data: {}, header: {},
timeout: this.timeout,
method: this.method,
@ -334,7 +342,7 @@ class API<
}
// 触发数据解析
(this as Emitter<IAnyData>).emit("parseRequestData", this.data);
this.emit("parseRequestData", this.data);
// 数据收集
for (let key in this.params) {
@ -452,18 +460,18 @@ class API<
let request = () => {
// 触发请求发送事件
(this as Emitter<IAnyData>).emit("request", this.requestData!)
this.emit("request", this.requestData!)
wx.request<O>({
...this.requestData!,
success: (e) => {
(this as Emitter<IAnyData>).emit("success", e);
this.emit("success", e);
},
fail: (e) => {
(this as Emitter<IAnyData>).emit("fail", e);
this.emit("fail", e);
},
complete: (e) => {
(this as Emitter<IAnyData>).emit("complete", e);
this.emit("complete", e);
}
});
}
@ -481,12 +489,12 @@ class API<
// 使用上次请求结果
if (this.policy === RequestPolicy.useLastRequest) {
lastAPI.on("success", (e) => {
(this as Emitter<IAnyData>).emit("success", e as SuccessCallbackResult<O>);
(this as Emitter<IAnyData>).emit("complete", {errMsg: e.errMsg});
this.emit("success", e as SuccessCallbackResult<O>);
this.emit("complete", {errMsg: e.errMsg});
});
lastAPI.on("fail", (e) => {
(this as Emitter<IAnyData>).emit("fail", e);
(this as Emitter<IAnyData>).emit("complete", {errMsg: e.errMsg});
this.emit("fail", e);
this.emit("complete", {errMsg: e.errMsg});
});
}
@ -596,8 +604,8 @@ class API<
*/
public addFailedCallBack(): this {
this.on("fail", (e) => {
(this as Emitter<IAnyData>).emit("no", e as any);
(this as Emitter<IAnyData>).emit("done", e as any);
this.emit("no", e as any);
this.emit("done", e as any);
});
return this;
}
@ -689,4 +697,4 @@ enum HTTPMethod {
}
export default API;
export { API, IParamSetting, IAppAPIParam, IAnyData, ICallBack, HTTPMethod, RequestPolicy, GeneralCallbackResult }
export { API, IParamSetting, IAppAPIParam, ICallBack, HTTPMethod, RequestPolicy, GeneralCallbackResult }

View File

@ -1,277 +0,0 @@
import { Storage } from "./Storage";
/**
*
*/
interface IDataParamSettingItem {
/**
*
*/
type: any;
/**
*
*/
get?: ((...P: any) => this["type"]) | INone;
/**
*
*/
set?: ((...P: [this["type"], ...any]) => any) | INone;
/**
*
*/
getAsync?: ((...P: any) => Promise<this["type"]>) | INone;
/**
*
*/
setAsync?: ((...P: [this["type"], ...any]) => Promise<any>) | INone;
}
/**
*
*/
interface IDataParamSetting {
[x: string]: IDataParamSettingItem
}
type INone = undefined | void;
/**
*
*/
type IRegistryItem<S extends IDataParamSettingItem> = {
/**
*
*/
get: S["get"];
/**
*
*/
getAsync: S["getAsync"] extends Function ? S["getAsync"] :
S["get"] extends ((...P: any) => S["type"]) ? (...param: Parameters<S["get"]>) => Promise<S["type"]> : INone;
/**
*
*/
set: S["set"];
/**
*
*/
setAsync: S["setAsync"] extends Function ? S["setAsync"] :
S["set"] extends ((...P: [S["type"], ...any]) => any) ? (...param: Parameters<S["set"]>) => Promise<ReturnType<S["set"]>> : INone;
}
/**
*
*/
type IRegistry<D extends IDataParamSetting> = {
[P in keyof D]: IRegistryItem<D[P]>;
}
type IRegistryPartial<D extends IDataParamSetting> = {
[P in keyof D]?: Partial<IRegistryItem<D[P]>>;
}
type IAutoSelect<IF extends boolean, A, B> = IF extends true ? A : B;
/**
* Core
*
* 使
* ```typescript
* class TestData extends Data<{
* test: {
* type: number
* get: () => number,
* set: (val: number) => void,
* getAsync: () => Promise<number>
* }
* }> {
* public onLoad() {
* let dataObject = {key: 1}
* this.getter("test", () => 1);
* this.registerKeyFromObject(dataObject, "test", "key");
* }
* }
* ```
*/
class Data<D extends IDataParamSetting> {
/**
* getter setter
*/
private registryList: IRegistryPartial<D> = {};
/**
*
*/
public onLoad(): any {};
/**
* Setter
* @param key
* @param setter Setter
* @param isAsync
*/
protected setter<KEY extends keyof D> (key: KEY, setter: IRegistryItem<D[KEY]>["set"]): this
protected setter<KEY extends keyof D> (key: KEY, setter: IRegistryItem<D[KEY]>["setAsync"], isAsync: true): this
protected setter<
KEY extends keyof D,
ASYNC extends boolean
> (
key: KEY,
setter: IAutoSelect<ASYNC, IRegistryItem<D[KEY]>["setAsync"], IRegistryItem<D[KEY]>["set"]>,
isAsync?: ASYNC
): this {
// 如果此键值不存在,新建
if (!this.registryList[key]) this.registryList[key] = {};
// 设置异步 setter
if (isAsync) this.registryList[key]!.setAsync = setter as IRegistryItem<D[KEY]>["setAsync"];
// 设置同步 setter
else this.registryList[key]!.set = setter as IRegistryItem<D[KEY]>["set"];
return this;
}
/**
* Getter
* @param key
* @param getter Getter
* @param isAsync
*/
protected getter<KEY extends keyof D> (key: KEY, getter: IRegistryItem<D[KEY]>["get"]): this
protected getter<KEY extends keyof D> (key: KEY, getter: IRegistryItem<D[KEY]>["getAsync"], isAsync: true): this
protected getter<
KEY extends keyof D,
ASYNC extends boolean
> (
key: KEY,
getter: IAutoSelect<ASYNC, IRegistryItem<D[KEY]>["getAsync"], IRegistryItem<D[KEY]>["get"]>,
isAsync?: ASYNC
): this {
// 如果此键值不存在,新建
if (!this.registryList[key]) this.registryList[key] = {};
// 设置异步 getter
if (isAsync) this.registryList[key]!.getAsync = getter as IRegistryItem<D[KEY]>["getAsync"];
// 设置同步 getter
else this.registryList[key]!.get = getter as IRegistryItem<D[KEY]>["get"];
return this;
}
/**
* Data
* @param key Data
* @param keyFromObject
* @param object
*/
protected registerKeyFromObject<
KEY extends keyof D,
F extends string,
O extends {[K in F]: D[KEY]["type"]}
> (object: O, key: KEY, keyFromObject: F = key as any) {
// 注册同步获取
this.getter(key, () => {
return object[keyFromObject]
});
// 注册同步设置
this.setter(key, (data: any) => {
object[keyFromObject] = data
})
}
/**
* Storage key
* @param key Data
* @param keyFromStorage StorageKey
*/
protected registerKeyFromStorage<
KEY extends keyof D,
F extends string,
S extends Storage<{[K in F]: D[KEY]["type"]}>
> (storage: S, key: KEY, keyFromStorage: F = key as any) {
// 同步获取
this.getter(key, () => {
return storage.get(keyFromStorage);
});
// 同步设置
this.setter(key, (data: any) => {
storage.set(keyFromStorage, data);
});
// 异步设置
this.setter(key, (async (data: any) => {
await storage.set(keyFromStorage, data);
}) as any, true);
}
/**
*
* @returns
*/
public export(): IRegistry<D> {
this.autoFillFunction();
return this.registryList as IRegistry<D>;
}
/**
*
*
*
* export
*/
protected autoFillFunction(): void {
// 填充函数
const fillFunction = <KEY extends keyof D>(key: KEY): void => {
const item = this.registryList[key] as IRegistryItem<D[KEY]>;
if (!item) return;
// 检验 getter
if (item.get && !item.getAsync) {
item.getAsync = this.syncFn2AsyncFn(item.get) as any;
}
// 检验 setter
if (item.set && !item.setAsync) {
item.setAsync = this.syncFn2AsyncFn(item.set) as any;
}
}
// 在注册表中查找
for (const key in this.registryList) fillFunction(key);
}
/**
*
* @param fn
*/
protected syncFn2AsyncFn<F extends (...p: any) => any> (fn: F): (...param: Parameters<F>) => ReturnType<F> {
const asyncFn = async (...param: [D]) => {
return fn(...param);
};
return asyncFn as any;
}
}
export { Data };
export default Data;

View File

@ -13,21 +13,6 @@ export type EventHandlerMap<Events extends Record<EventType, any>> = Map<
EventHandlerList<Events[keyof Events]>
>;
// Emitter function type
type IEmitParamType<E extends Record<EventType, any>, K extends keyof E> =
E[K] extends ( undefined | void ) ? [type: K] : [type: K, evt: E[K]];
// Mixin to event object
export type EventMixin<A extends Record<EventType, any>, B extends Record<EventType, any>> = {
[P in (keyof A | keyof B)] :
P extends (keyof A & keyof B) ?
A[P] :
P extends keyof A ?
A[P] :
P extends keyof B ? B[P] :
never;
}
export class Emitter<Events extends Record<EventType, any>> {
/**
@ -89,8 +74,7 @@ export class Emitter<Events extends Record<EventType, any>> {
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
* @memberOf mitt
*/
public emit<Key extends keyof Events>(...param: IEmitParamType<Events, Key>): this {
const [ type, evt ] = param;
emit<Key extends keyof Events>(type: Key, evt: Events[Key]) {
let handlers = this.all!.get(type);
if (handlers) {
(handlers as EventHandlerList<Events[keyof Events]>)
@ -99,6 +83,5 @@ export class Emitter<Events extends Record<EventType, any>> {
handler(evt!);
});
}
return this;
}
}

View File

@ -491,27 +491,6 @@ 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}

View File

@ -1,154 +0,0 @@
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"];
};
/**
*
*/
type IStudentInfoData = {
/**
*
*/
studentId: {
type: string,
};
/**
*
*/
password: {
type: string
};
/**
*
*/
loginStatus: {
type: LoginStatus
}
/**
*
*
*/
lastLoginTime: {
type: number
}
/**
*
*
*/
isUserInfoChange: {
type: boolean
}
}
/**
*
*/
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;

View File

@ -1,99 +0,0 @@
@import "../app.scss";
view.mask {
position: fixed;
width: 100%;
height: 100%;
background-color: rgba($color: #000000, $alpha: .2);
z-index: 1;
}
view.layer {
position: fixed;
@include container;
height: 100%;
z-index: 2;
justify-content: center;
align-items: center;
}
view.occlude {
position: fixed;
width: 100%;
height: 100%;
z-index: 3;
}
view.mask.block, view.layer.block, view.occlude.block {
display: flex;
}
view.mask.none, view.layer.none, view.occlude.none {
display: none;
}
view.mask.show-fade, view.layer.show-fade, view.occlude.show-fade {
animation: show-fade .1s cubic-bezier(0, 0, 1, 1) both;
opacity: 1;
}
view.mask.hide-fade, view.layer.hide-fade, view.occlude.hide-fade {
animation: hide-fade .1s cubic-bezier(0, 0, 1, 1) both;
opacity: 0;
}
view.mask.show-scale, view.layer.show-scale, view.occlude.show-scale {
animation: show-scale .3s cubic-bezier(.1, .9, .2, 1) both,
show-fade .1s cubic-bezier(0, 0, 1, 1) both;
transform: scale3d(1, 1, 1);
opacity: 1;
}
view.mask.hide-scale, view.layer.hide-scale, view.occlude.hide-scale {
animation: hide-scale .3s cubic-bezier(.1, .9, .2, 1) both,
hide-fade .1s cubic-bezier(0, 0, 1, 1) both;
transform: scale3d(.9, .9, 1);
opacity: 0;
}
@media (prefers-color-scheme: dark) {
view.mask {
background-color: rgba($color: #000000, $alpha: .5);
}
}
@keyframes show-fade{
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes hide-fade{
from {
opacity: 1;
}
to {
opacity: 0;
}
}
@keyframes show-scale{
from {
transform: scale3d(1.15, 1.15, 1);
}
to {
transform: scale3d(1, 1, 1);
}
}
@keyframes hide-scale{
from {
transform: scale3d(1, 1, 1);
}
to {
transform: scale3d(.9, .9, 1);
}
}

View File

@ -1,309 +0,0 @@
import { IAnyData } from "../core/Api";
import { Emitter } from "../core/Emitter";
import { Modular, Manager } from "../core/Module";
/**
*
*/
enum AnimateType {
fade = 1,
scale = 2,
none = 3,
}
/**
*
*/
class DisplayLayer {
/**
*
*/
public get className(): string {
let res = this.isDisplay ? "block" : "none";
switch (this.animateType) {
case AnimateType.fade:
res += " mask";
break;
case AnimateType.scale:
res += " layer";
break;
case AnimateType.none:
res += " occlude";
break;
}
switch (this.animateType) {
case AnimateType.fade:
res += this.isShow ? " show-fade" : " hide-fade";
break;
case AnimateType.scale:
res += this.isShow ? " show-scale" : " hide-scale";
break;
case AnimateType.none:
break;
}
return res;
}
/**
* Layer 使 key
*/
public key: string = "";
/**
* 使
*/
public animateType: AnimateType = AnimateType.scale;
/**
*
*/
public get animateTime(): number {
switch (this.animateType) {
case AnimateType.fade:
return 100;
case AnimateType.scale:
return 300;
case AnimateType.none:
return -1;
}
};
/**
*
*/
public isDisplay: boolean = false;
/**
*
*/
public isShow: boolean = false;
/**
*
*/
public disappearTimer?: number;
}
/**
*
*/
type IPopupLayerEvent<L extends string> = {
/**
*
*/
clickMask: void
/**
*
*/
show: L;
/**
*
*/
hide: L;
/**
*
*/
change: Readonly<DisplayLayer>;
}
type commonLayerType = "mask" | "occlude";
/**
*
*/
class PopupLayer<
L extends string,
M extends Manager = Manager
> extends Modular<M, {}, IPopupLayerEvent<L | commonLayerType>> {
/**
*
*/
public autoCloseOnClick: boolean = true;
/**
*
*/
public showOccludeWhenHide: boolean = true;
/**
* Layer
*/
public hideOtherWhenShow: boolean = true;
/**
*
*/
private layers: Map<L | commonLayerType, DisplayLayer> = new Map();
/**
*
* @param key
*/
public initLayers(key: L[]) {
for (let i = 0; i < key.length; i++) {
this.render(this.getDisplayLayer(key[i]));
}
}
public onLoad(): void {
this.on("show", this.handleShowLayer);
this.on("hide", this.handleHideLayer);
this.setFunc(this.handleClickMask, "clickMask");
// 添加蒙版层
const maskLayer = this.getDisplayLayer("mask");
maskLayer.animateType = AnimateType.fade;
this.render(maskLayer);
// 添加遮蔽层
const occludeLayer = this.getDisplayLayer("occlude");
occludeLayer.animateType = AnimateType.none;
this.render(occludeLayer);
}
/**
* Layers
*/
private render(layer: DisplayLayer) {
this.setData({ [`${ layer.key }$className`]: layer.className });
}
/**
*
*/
private getDisplayLayer<K extends L | commonLayerType>(e: K): DisplayLayer {
let displayLayer = this.layers.get(e);
if (!displayLayer) {
displayLayer = new DisplayLayer();
displayLayer.key = e;
this.layers.set(e, displayLayer);
}
return displayLayer;
}
/**
*
*/
private handleClickMask = () => {
if (!this.autoCloseOnClick) return;
// 关闭全部开启的层
this.layers.forEach((layer) => {
if (layer.isShow) (this as Emitter<IAnyData>).emit("hide", layer.key);
});
// 关闭蒙版
(this as Emitter<IAnyData>).emit("hide", "mask");
}
/**
*
*/
private handleShowLayer = <K extends L | commonLayerType>(e: K) => {
let displayLayer = this.getDisplayLayer(e);
// 阻止未发生的变化
if (displayLayer.isShow) return;
// 关闭其他层
if (e !== "mask" && e !== "occlude" && this.hideOtherWhenShow) {
this.layers.forEach((layer) => {
if (layer.key === "mask" || layer.key === "occlude") return;
if (layer.isShow) {
(this as Emitter<IAnyData>).emit("hide", layer.key);
}
});
}
// 显示蒙版
if (e !== "mask" && e !== "occlude")
(this as Emitter<IAnyData>).emit("show", "mask");
// 取消消失定时
displayLayer.disappearTimer &&
clearTimeout(displayLayer.disappearTimer);
displayLayer.isShow = true;
displayLayer.isDisplay = true;
this.render(displayLayer);
this.emit("change", displayLayer);
};
/**
*
*/
private handleHideLayer = <K extends L | commonLayerType>(e: K) => {
let displayLayer = this.getDisplayLayer(e);
// 阻止未发生的变化
if (!displayLayer.isShow) return;
if (displayLayer.animateTime <= 0) {
displayLayer.isShow = false;
displayLayer.isDisplay = false;
this.render(displayLayer);
} else {
displayLayer.isShow = false;
this.render(displayLayer);
// 开启遮蔽
if (this.showOccludeWhenHide) {
(this as Emitter<IAnyData>).emit("show", "occlude");
}
displayLayer.disappearTimer = setTimeout(() => {
displayLayer.isDisplay = false;
this.render(displayLayer);
// 取消 timer
displayLayer.disappearTimer = undefined;
// 检测是否关闭遮蔽
let needOcclude = true;
this.layers.forEach((layer) => {
if (layer === displayLayer) return;
if (layer.disappearTimer) needOcclude = false;
});
// 关闭遮蔽
if (needOcclude && this.showOccludeWhenHide) {
(this as Emitter<IAnyData>).emit("hide", "occlude");
}
}, displayLayer.animateTime);
}
// 关闭蒙版
if (e !== "mask" && e !== "occlude") {
let needMask = true;
this.layers.forEach((layer) => {
if (layer === displayLayer) return;
if (layer.isShow) needMask = false;
});
if (needMask) (this as Emitter<IAnyData>).emit("hide", "mask");
}
this.emit("change", displayLayer);
}
}
export { PopupLayer };
export default PopupLayer;

View File

@ -1,7 +1,7 @@
@import "./UserCard.scss";
@import "./MainFunction.scss";
@import "./FunctionList.scss";
@import "../../modular/PopupLayer.scss";
view.container{
padding-top: 50rpx;

View File

@ -2,37 +2,9 @@ import { Manager } from "../../core/Module";
import { UserCard } from "./UserCard";
import { MainFunction } from "./MainFunction";
import { FunctionList } from "./FunctionList";
import { PopupLayer } from "../../modular/PopupLayer";
import { TestLayerA } from "./TestLayerA";
(async () => {
// 初始化页面
const { manager, query } = await Manager.PageAsync();
// 添加弹出层 Modular
const popupLayer: PopupLayer<"layerA" | "layerB"> = manager.addModule(PopupLayer, "mask") as any;
// 添加 UserCard Modular
const userCard = manager.addModule(UserCard, "userCard");
//#region test layer
popupLayer.initLayers(["layerA", "layerB"]);
const testLayerA = manager.addModule(TestLayerA, "testLayerA");
userCard.on("clickChangeTheme", () => {
popupLayer.emit("show", "layerA");
})
testLayerA.on("click", () => {
popupLayer.emit("show", "layerB");
})
//#endregion
// 添加 MainFunction Modular
Manager.Page((manager) => {
manager.addModule(UserCard, "userCard");
manager.addModule(MainFunction, "mainFunction");
// 添加 FunctionList Modular
manager.addModule(FunctionList, "functionList");
// 初始化全部 Modular
await manager.loadAllModule(query);
})();
});

View File

@ -1,18 +1,3 @@
<!-- 层遮蔽层 -->
<view class="{{ mask$occlude$className }}" bindtap="mask$clickMask"></view>
<!-- 蒙版 -->
<view class="{{ mask$mask$className }}" bindtap="mask$clickMask"></view>
<!-- 层A -->
<view class="{{ mask$layerA$className }}" bindtap="mask$clickMask">
<view class="card" style="height: 300px; line-height: 300px; text-align:center" catchtap="testLayerA$click">layerA(点击显示layerB)</view>
</view>
<!-- 层B -->
<view class="{{ mask$layerB$className }}" bindtap="mask$clickMask">
<view class="card" style="height: 200px; line-height: 200px; text-align:center" catchtap>layerB</view>
</view>
<!-- 顶部的阴影 -->
<view class="top-shadow"></view>
@ -29,9 +14,7 @@
<!-- 主题变换按钮 -->
<view class="theme">
<view bindtap="userCard$changeTheme">
<image class="icon-sub" src="../../image/account/Account_Theme.svg" />
</view>
<image class="icon-sub" src="../../image/account/Account_Theme.svg" />
</view>
<!-- 用户昵称 -->
@ -44,7 +27,7 @@
<view class="name">秦浩轩</view>
<view class="certified">
<view class="certifi-info">已认证</view>
<image class="text-icon" src="../../image/account/Account_OK.svg"></image>
<view class="text-icon"></view>
</view>
</view>
@ -57,27 +40,74 @@
</view>
<!--主要功能-->
<view class="card main-function">
<!--每个功能的容器-->
<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 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="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>
</view>
</view>
<!-- 功能列表 -->
<view class="card function-list">
<view class="function">
<view>
<image class="icon func-icon" src="../../image/account/Account_Sponsor.svg" />
<view>赞助计划</view>
<image class="icon-sub arrow" src="../../image/account/Account_Arrow.svg" />
</view>
</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>
<view class="function">
<view>
<image class="icon func-icon" src="../../image/account/Account_PubilcAccount.svg" />
<view>公众号</view>
<image class="icon-sub arrow" src="../../image/account/Account_Arrow.svg" />
</view>
</view>
<view class="function">
<view>
<image class="icon func-icon" src="../../image/account/Account_FAQ.svg" />
<view>自助问答</view>
<image class="icon-sub arrow" src="../../image/account/Account_Arrow.svg" />
</view>
</view>
<view class="function">
<view>
<image class="icon func-icon" src="../../image/account/Account_AboutUs.svg" />
<view>关于我们</view>
<image class="icon-sub arrow" src="../../image/account/Account_Arrow.svg" />
</view>
</view>
<view class="function">
<view style="border-bottom: 0px;">
<image class="icon func-icon" src="../../image/account/Account_Support.svg" />
<view>联系客服</view>
<image class="icon-sub arrow" src="../../image/account/Account_Arrow.svg" />
</view>
</view>

View File

@ -1,31 +1,6 @@
import { Modular, Manager } from "../../core/Module";
interface IFunctionListItem {
/**
*
*/
displayName: string;
/**
*
*/
iconUrl: string;
}
class FunctionList<M extends Manager> extends Modular<M> {
public static readonly functionList: IFunctionListItem[] = [
{ displayName: "赞助计划", iconUrl: "Sponsor" },
{ displayName: "公众号", iconUrl: "PubilcAccount" },
{ displayName: "自助问答", iconUrl: "FAQ" },
{ displayName: "关于我们", iconUrl: "AboutUs" },
{ displayName: "联系客服", iconUrl: "Support" }
];
public data = {
functionList: FunctionList.functionList
};
public override onLoad() {
// Do something

View File

@ -1,30 +1,6 @@
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

View File

@ -1,26 +0,0 @@
import { Modular, Manager } from "../../core/Module";
type IUserCardEvent = {
/**
*
*/
click: void;
}
class TestLayerA<M extends Manager> extends Modular<M, {}, IUserCardEvent> {
public override onLoad() {
this.setFunc(this.handleClick, "click");
}
/**
*
*/
private handleClick() {
this.emit("click");
}
}
export { TestLayerA };
export default TestLayerA;

View File

@ -27,17 +27,9 @@ view.user-card {
display: flex;
justify-content: flex-end;
view {
image {
width: 23px;
height: 23px;
padding: 20px;
margin: -20px;
border-radius: 20px;
image {
width: 100%;
height: 100%;
}
}
}
@ -49,7 +41,6 @@ view.user-card {
text-overflow: ellipsis;
}
// 学生信息
view.student {
display: flex;
align-items: center;
@ -66,10 +57,8 @@ view.user-card {
justify-content: center;
align-items: center;
image.text-icon {
margin-left: .25em;
width: 10px;
height: 10px;
view.text-icon {
margin-left: .3em;
}
}
}

View File

@ -1,24 +1,9 @@
import { Modular, Manager } from "../../core/Module";
type IUserCardEvent = {
/**
*
*/
clickChangeTheme: void;
}
class UserCard<M extends Manager> extends Modular<M, {}, IUserCardEvent> {
public override onLoad() {
this.setFunc(this.handleChangeTheme, "changeTheme");
}
class UserCard<M extends Manager> extends Modular<M> {
/**
*
*/
private handleChangeTheme() {
this.emit("clickChangeTheme");
public override onLoad() {
// Do something
}
}

View File

@ -1,6 +1,5 @@
import { Modular, Manager, ILifetime } from "../../core/Module";
import { Login } from "../../api/Login";
import { Schedlue } from "../../api/Schedule"
import { Storage } from "../../core/Storage";
/**
@ -29,14 +28,12 @@ implements Partial<ILifetime> {
s.set("be", 12);
}, 1000)
// 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()
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)}
});
}
}

View File

@ -6,17 +6,7 @@ import { TestCore } from "./TestCore";
* 使 Manager
* Modular Manager
*/
(async () => {
// 初始化页面
const { manager, query } = await Manager.PageAsync();
// 添加 StatusBar Modular
Manager.Page((manager)=>{
manager.addModule(StatusBar, "statusBar");
// 添加 TestCore Modular
manager.addModule(TestCore, "testCore");
// 初始化全部 Modular
await manager.loadAllModule(query);
})()
})

View File

@ -1,8 +1,7 @@
{
"description": "项目配置文件详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"description": "项目配置文件",
"packOptions": {
"ignore": [],
"include": []
"ignore": []
},
"miniprogramRoot": "miniprogram/",
"compileType": "miniprogram",
@ -47,16 +46,13 @@
"useCompilerPlugins": [
"typescript",
"sass"
],
"useStaticServer": true
]
},
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"appid": "wx7d809f5e8955843d",
"condition": {},
"srcMiniprogramRoot": "miniprogram/",
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
"scripts": {
"beforeCompile": ""
},
"condition": {}
}

View File

@ -1,5 +1,14 @@
{
"condition": {
"plugin": {
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [
{
@ -10,10 +19,5 @@
}
]
}
},
"projectname": "mini-dlpu-v3",
"setting": {
"compileHotReLoad": true
},
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html"
}
}