feat(wip): 進一步完善 UserAPI 和基類函數
This commit is contained in:
@@ -8,6 +8,12 @@ export default abstract class BaseApi {
|
||||
this.onInit()
|
||||
}
|
||||
abstract onInit(): void
|
||||
checkArgsMissing(args: {}, names: []) {
|
||||
for (const k of names)
|
||||
if (!(k in args))
|
||||
return true
|
||||
return false
|
||||
}
|
||||
registerEvent(name: CallMethod, func: EventCallbackFunction) {
|
||||
if (!name.startsWith(this.getName() + ".")) throw Error("注冊的事件應該與接口集合命名空間相匹配: " + name)
|
||||
ApiManager.addEventListener(name, func)
|
||||
|
||||
@@ -5,7 +5,7 @@ export default class UserApi extends BaseApi {
|
||||
return "User"
|
||||
}
|
||||
override onInit(): void {
|
||||
this.registerEvent("User.auth", () => {
|
||||
this.registerEvent("User.auth", (args) => {
|
||||
return {
|
||||
msg: "",
|
||||
code: 200,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import ApiCallbackMessage from "../api/ApiCallbackMessage.ts"
|
||||
|
||||
type EventCallbackFunction = (args: {}) => ApiCallbackMessage
|
||||
type EventCallbackFunction = (args: { [key: string]: unknown }) => ApiCallbackMessage
|
||||
|
||||
export default EventCallbackFunction
|
||||
|
||||
Reference in New Issue
Block a user