This commit is contained in:
Your Name
2026-03-11 09:49:47 +08:00
parent 02ae537b4c
commit 38ad60f4bb
290 changed files with 36917 additions and 123 deletions
+59
View File
@@ -0,0 +1,59 @@
type func = (...args: any[]) => any;
/**
* 广播参数信息
* @interface NotifyEventParams
* @property {string} eventName 事件名
* @property {string} method 调用的方法名
* @property {Record<string, any>} params 业务参数
* @property {func} [callback] 回调函数
*/
interface NotifyEventParams {
eventName: string;
params?: Record<string, any>;
callback?: func;
}
interface TUINotification {
onNotifyEvent(options: NotifyEventParams): void;
}
/**
* @interface TUIBridge
*/
interface TUIBridge {
/**
* 注册广播监听
* @function
* @param {string} eventName 事件名
* @param {string} subKey 事件的具体操作
* @param {TUINotification} notification 事件监听者
* @example
* TUICore.registerEvent('LoginState.LoginSuccess', this);
*/
registerEvent(eventName: string, notification: TUINotification): void;
/**
* 反注册广播监听
* @function
* @param {string} eventName 事件名
* @param {string} subKey 事件的具体操作
* @param {ITUINotification} notification 事件监听者
* @example
* TUICore.unregisterEvent('LoginState.LoginSuccess', this);
*/
unregisterEvent(eventName: string, notification: TUINotification): void;
/**
* 广播通知
* @function
* @param {NotifyEventParams} options 通知内容
* @example
* TUICore.notifyEvent({
* eventName: LoginState.LoginSuccess,
* params: { chat },
* });
*/
notifyEvent(options: NotifyEventParams): void;
}
declare const tuiBridge: TUIBridge;
export { tuiBridge as TUIBridge, tuiBridge as default };
@@ -0,0 +1 @@
const e="LoginState.LoginSuccess";class t{constructor(){this.eventMap=new Map,this.chat=null}registerEvent(e,t){if(console.log(`TUIEventManager.registerEvent eventName:${e}`),!this.eventMap.has(e)){const t=[];this.eventMap.set(e,t)}const n=this.eventMap.get(e)||[];-1===n.indexOf(t)&&(n.push(t),this.renotify(e,t))}unregisterEvent(e,t){if(console.log(`TUIEventManager.unregisterEvent eventName:${e}`),this.eventMap.has(e)){const n=this.eventMap.get(e)||[],s=n.indexOf(t);s>-1&&n.splice(s,1)}}notifyEvent(t){const{eventName:n,params:s}=t;if(console.log("TUIEventManager.notifyEvent options:",t),n===e&&(this.chat=(null==s?void 0:s.chat)||null),this.eventMap.has(n)){(this.eventMap.get(n)||[]).forEach((e=>{e.onNotifyEvent(t)}))}}renotify(t,n){var s;t===e&&(null===(s=this.chat)||void 0===s?void 0:s.isReady())&&(n.onNotifyEvent({eventName:t,params:{chat:this.chat}}),console.log("TUIEventManager.renotify success."))}}class n{constructor(){this.eventManager=new t}static getInstance(){return n.instance||(console.log("TUIBridge.getInstance ok."),n.instance=new n),n.instance}registerEvent(e,t){return this.eventManager.registerEvent(e,t)}unregisterEvent(e,t){return this.eventManager.unregisterEvent(e,t)}notifyEvent(e){return this.eventManager.notifyEvent(e)}}console.log("TUIBridge.VERSION:0.0.1");const s=n.getInstance();export{s as TUIBridge,s as default};