(#60) Remove mixin generic paradigm. #62
@ -1,7 +1,7 @@
|
|||||||
import { API, IAnyData, GeneralCallbackResult } from "../core/Api";
|
import { API, IAnyData, GeneralCallbackResult } from "../core/Api";
|
||||||
import { EventType } from "../core/Emitter";
|
import { EventType, Emitter } from "../core/Emitter";
|
||||||
|
|
||||||
interface ILoginEvent {
|
type ILoginEvent = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session 过期
|
* session 过期
|
||||||
@ -56,37 +56,37 @@ abstract class EduBase<
|
|||||||
if(!info) {
|
if(!info) {
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
errMsg = "Bad Data";
|
errMsg = "Bad Data";
|
||||||
this.emit("badData", { errMsg });
|
(this as Emitter<IAnyData>).emit("badData", { errMsg });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSuccess) switch (info.code) {
|
if (isSuccess) switch (info.code) {
|
||||||
case (1):
|
case (1):
|
||||||
res = parseFunction(info.data);
|
res = parseFunction(info.data);
|
||||||
errMsg = info.err_msg ?? "Success";
|
errMsg = info.err_msg ?? "Success";
|
||||||
this.emit("ok", res!);
|
(this as Emitter<IAnyData>).emit("ok", res!);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (2):
|
case (2):
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
errMsg = info.err_msg ?? "Session Expire";
|
errMsg = info.err_msg ?? "Session Expire";
|
||||||
this.emit("expire", { errMsg });
|
(this as Emitter<IAnyData>).emit("expire", { errMsg });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (3):
|
case (3):
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
errMsg = info.err_msg ?? "Unauthorized";
|
errMsg = info.err_msg ?? "Unauthorized";
|
||||||
this.emit("unauthorized", { errMsg });
|
(this as Emitter<IAnyData>).emit("unauthorized", { errMsg });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (4):
|
case (4):
|
||||||
isSuccess = false;
|
isSuccess = false;
|
||||||
errMsg = info.err_msg ?? "Error";
|
errMsg = info.err_msg ?? "Error";
|
||||||
this.emit("error", { errMsg });
|
(this as Emitter<IAnyData>).emit("error", { errMsg });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSuccess) this.emit("no", { errMsg });
|
if (!isSuccess) (this as Emitter<IAnyData>).emit("no", { errMsg });
|
||||||
this.emit("done", { errMsg, data: res });
|
(this as Emitter<IAnyData>).emit("done", { errMsg, data: res });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ class API<
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 触发数据初始化事件
|
// 触发数据初始化事件
|
||||||
this.emit("initData", this.data);
|
(this as Emitter<IAnyData>).emit("initData", this.data);
|
||||||
|
|
||||||
// 重置请求数据
|
// 重置请求数据
|
||||||
const requestData:IWxRequestOption<O> = this.requestData = {
|
const requestData:IWxRequestOption<O> = this.requestData = {
|
||||||
@ -343,7 +343,7 @@ class API<
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 触发数据解析
|
// 触发数据解析
|
||||||
this.emit("parseRequestData", this.data);
|
(this as Emitter<IAnyData>).emit("parseRequestData", this.data);
|
||||||
|
|
||||||
// 数据收集
|
// 数据收集
|
||||||
for (let key in this.params) {
|
for (let key in this.params) {
|
||||||
@ -461,18 +461,18 @@ class API<
|
|||||||
let request = () => {
|
let request = () => {
|
||||||
|
|
||||||
// 触发请求发送事件
|
// 触发请求发送事件
|
||||||
this.emit("request", this.requestData!)
|
(this as Emitter<IAnyData>).emit("request", this.requestData!)
|
||||||
|
|
||||||
wx.request<O>({
|
wx.request<O>({
|
||||||
...this.requestData!,
|
...this.requestData!,
|
||||||
success: (e) => {
|
success: (e) => {
|
||||||
this.emit("success", e);
|
(this as Emitter<IAnyData>).emit("success", e);
|
||||||
},
|
},
|
||||||
fail: (e) => {
|
fail: (e) => {
|
||||||
this.emit("fail", e);
|
(this as Emitter<IAnyData>).emit("fail", e);
|
||||||
},
|
},
|
||||||
complete: (e) => {
|
complete: (e) => {
|
||||||
this.emit("complete", e);
|
(this as Emitter<IAnyData>).emit("complete", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -490,12 +490,12 @@ class API<
|
|||||||
// 使用上次请求结果
|
// 使用上次请求结果
|
||||||
if (this.policy === RequestPolicy.useLastRequest) {
|
if (this.policy === RequestPolicy.useLastRequest) {
|
||||||
lastAPI.on("success", (e) => {
|
lastAPI.on("success", (e) => {
|
||||||
this.emit("success", e as SuccessCallbackResult<O>);
|
(this as Emitter<IAnyData>).emit("success", e as SuccessCallbackResult<O>);
|
||||||
this.emit("complete", {errMsg: e.errMsg});
|
(this as Emitter<IAnyData>).emit("complete", {errMsg: e.errMsg});
|
||||||
});
|
});
|
||||||
lastAPI.on("fail", (e) => {
|
lastAPI.on("fail", (e) => {
|
||||||
this.emit("fail", e);
|
(this as Emitter<IAnyData>).emit("fail", e);
|
||||||
this.emit("complete", {errMsg: e.errMsg});
|
(this as Emitter<IAnyData>).emit("complete", {errMsg: e.errMsg});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,8 +605,8 @@ class API<
|
|||||||
*/
|
*/
|
||||||
public addFailedCallBack(): this {
|
public addFailedCallBack(): this {
|
||||||
this.on("fail", (e) => {
|
this.on("fail", (e) => {
|
||||||
this.emit("no", e as any);
|
(this as Emitter<IAnyData>).emit("no", e as any);
|
||||||
this.emit("done", e as any);
|
(this as Emitter<IAnyData>).emit("done", e as any);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -106,8 +106,8 @@ class Mask<M extends Manager> extends Modular<M, {}, IMaskEvent> {
|
|||||||
* 处理蒙版点击事件
|
* 处理蒙版点击事件
|
||||||
*/
|
*/
|
||||||
private handleClickMask() {
|
private handleClickMask() {
|
||||||
if (this.autoCloseOnClick) this.emit("hide", void 0);
|
if (this.autoCloseOnClick) this.emit("hide");
|
||||||
this.emit("click", void 0);
|
this.emit("click");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,10 +10,10 @@ import { Mask } from "../../modular/Mask/Mask";
|
|||||||
const { manager, query } = await Manager.PageAsync();
|
const { manager, query } = await Manager.PageAsync();
|
||||||
|
|
||||||
// 添加蒙版 Modular
|
// 添加蒙版 Modular
|
||||||
const mask = manager.addModule(Mask, "mask");
|
// const mask = manager.addModule(Mask, "mask");
|
||||||
|
|
||||||
// 添加 UserCard Modular
|
// 添加 UserCard Modular
|
||||||
manager.addModule(UserCard, "userCard", { mask });
|
manager.addModule(UserCard, "userCard");
|
||||||
|
|
||||||
// 添加 MainFunction Modular
|
// 添加 MainFunction Modular
|
||||||
manager.addModule(MainFunction, "mainFunction");
|
manager.addModule(MainFunction, "mainFunction");
|
||||||
|
@ -2,7 +2,7 @@ import { Modular, Manager } from "../../core/Module";
|
|||||||
import { Mask } from "../../modular/Mask/Mask";
|
import { Mask } from "../../modular/Mask/Mask";
|
||||||
|
|
||||||
type IUserCardDependent<M extends Manager> = {
|
type IUserCardDependent<M extends Manager> = {
|
||||||
mask: Mask<M>
|
// mask: Mask<M>
|
||||||
}
|
}
|
||||||
|
|
||||||
type IUserCardEvent = {
|
type IUserCardEvent = {
|
||||||
@ -23,7 +23,7 @@ class UserCard<M extends Manager> extends Modular<M, IUserCardDependent<M>, IUse
|
|||||||
* 处理主题更换
|
* 处理主题更换
|
||||||
*/
|
*/
|
||||||
private handleChangeTheme() {
|
private handleChangeTheme() {
|
||||||
this.depends?.mask.emit("show", void 0);
|
// this.depends?.mask.emit("show", void 0);
|
||||||
this.emit("clickChangeTheme", void 0);
|
this.emit("clickChangeTheme", void 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user