dzkcc-mflow 0.0.45 → 0.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App.d.ts +8 -7
- package/dist/core/Api.d.ts +4 -168
- package/dist/core/index.d.ts +0 -1
- package/dist/libs/BaseView.d.ts +10 -4
- package/dist/libs/BaseView.js +9 -2
- package/dist/libs/Broadcaster.d.ts +70 -17
- package/dist/libs/Broadcaster.js +47 -30
- package/dist/libs/CocosCore.js +6 -3
- package/dist/libs/HttpManager.d.ts +18 -2
- package/dist/libs/ResLoader.d.ts +2 -2
- package/dist/libs/ResLoader.js +8 -6
- package/dist/libs/UIManager.d.ts +38 -69
- package/dist/libs/UIManager.js +133 -236
- package/dist/libs/UIRoot.d.ts +123 -1
- package/dist/libs/UIRoot.js +281 -4
- package/dist/libs/WebSocketManager.d.ts +22 -2
- package/dist/libs/index.js +1 -1
- package/dist/libs/indicator/RedDotManager.d.ts +2 -2
- package/dist/libs/indicator/RedDotManager.js +1 -0
- package/dist/mflow-tools.zip +0 -0
- package/dist/utils/UIUtil.d.ts +6 -0
- package/dist/utils/UIUtil.js +13 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +31 -9
- package/dist/core/ICocosResManager.d.ts +0 -11
- package/dist/core/ICocosResManager.js +0 -1
package/dist/App.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ICore
|
|
1
|
+
import { ICore } from "./core";
|
|
2
|
+
import { CCUIManager, HttpManager, WebSocketManager, ResLoader, RedDotManager, Broadcaster } from "./libs";
|
|
2
3
|
/**
|
|
3
4
|
* 对外暴露的全局app对像,用于访问基础能力,为上层业务提供了简洁的访问方式
|
|
4
5
|
*
|
|
@@ -8,12 +9,12 @@ export declare class App {
|
|
|
8
9
|
static get core(): ICore;
|
|
9
10
|
static readonly log: any;
|
|
10
11
|
static readonly config: any;
|
|
11
|
-
static get gui():
|
|
12
|
-
static get http():
|
|
13
|
-
static get socket():
|
|
14
|
-
static get res():
|
|
15
|
-
static get event():
|
|
16
|
-
static get reddot():
|
|
12
|
+
static get gui(): CCUIManager;
|
|
13
|
+
static get http(): HttpManager;
|
|
14
|
+
static get socket(): WebSocketManager;
|
|
15
|
+
static get res(): ResLoader;
|
|
16
|
+
static get event(): Broadcaster;
|
|
17
|
+
static get reddot(): RedDotManager;
|
|
17
18
|
static readonly storage: any;
|
|
18
19
|
static readonly audio: any;
|
|
19
20
|
static readonly timer: any;
|
package/dist/core/Api.d.ts
CHANGED
|
@@ -61,8 +61,12 @@ export interface UIOpenConfig {
|
|
|
61
61
|
showLoading?: boolean;
|
|
62
62
|
/** 是否可点击遮罩关闭 */
|
|
63
63
|
clickToCloseMask?: boolean;
|
|
64
|
+
/** 层级名称,由业务层定义,默认为'default' */
|
|
65
|
+
layer?: string;
|
|
64
66
|
/** 自定义参数 */
|
|
65
67
|
args?: any;
|
|
68
|
+
/** 退出回调 */
|
|
69
|
+
onExitCallback?: (view: any) => void;
|
|
66
70
|
}
|
|
67
71
|
/**
|
|
68
72
|
* View 基接口 - 视图生命周期
|
|
@@ -81,171 +85,3 @@ export interface IView {
|
|
|
81
85
|
/** 退出动画(可选) */
|
|
82
86
|
onExitAnimation?(): Promise<void>;
|
|
83
87
|
}
|
|
84
|
-
/**
|
|
85
|
-
* UI 管理器接口 - 管理视图的打开、关闭和栈操作
|
|
86
|
-
*
|
|
87
|
-
* 注意:open 和 openAndPush 的返回类型由全局类型声明提供
|
|
88
|
-
*/
|
|
89
|
-
export interface IUIManager {
|
|
90
|
-
/** 打开视图 */
|
|
91
|
-
open<T extends keyof UIRegistry>(viewClass: T, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
92
|
-
/** 关闭视图 */
|
|
93
|
-
close<T extends keyof UIRegistry>(viewClass: T): Promise<void>;
|
|
94
|
-
/** 打开视图并入栈 */
|
|
95
|
-
openAndPush<T extends keyof UIRegistry>(viewClass: T, group: string, args?: any): Promise<InstanceType<UIRegistry[T]>>;
|
|
96
|
-
/** 关闭栈顶视图并弹出 */
|
|
97
|
-
closeAndPop(group: string, destroy?: boolean): Promise<void>;
|
|
98
|
-
/** 获取栈顶视图 */
|
|
99
|
-
getTopView(): IView | undefined;
|
|
100
|
-
/** 清空视图栈 */
|
|
101
|
-
clearStack(group: string, destroy?: boolean): void;
|
|
102
|
-
/** 关闭所有视图 */
|
|
103
|
-
closeAll(destroy?: boolean): void;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* 资源管理器接口
|
|
107
|
-
*/
|
|
108
|
-
export interface IResManager {
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* HTTP 请求配置
|
|
112
|
-
*/
|
|
113
|
-
export interface HttpRequestOptions {
|
|
114
|
-
/** 请求 URL */
|
|
115
|
-
url: string;
|
|
116
|
-
/** HTTP 方法 */
|
|
117
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
118
|
-
/** 请求头 */
|
|
119
|
-
headers?: Record<string, string>;
|
|
120
|
-
/** URL 参数 */
|
|
121
|
-
params?: Record<string, any>;
|
|
122
|
-
/** 请求体数据 */
|
|
123
|
-
data?: any;
|
|
124
|
-
/** 超时时间(毫秒) */
|
|
125
|
-
timeout?: number;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* HTTP 管理器接口 - 处理 HTTP 请求
|
|
129
|
-
*/
|
|
130
|
-
export interface IHttpManager extends IManager {
|
|
131
|
-
/** GET 请求 */
|
|
132
|
-
get<T = any>(url: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<T>;
|
|
133
|
-
/** POST 请求 */
|
|
134
|
-
post<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<T>;
|
|
135
|
-
/** PUT 请求 */
|
|
136
|
-
put<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<T>;
|
|
137
|
-
/** DELETE 请求 */
|
|
138
|
-
delete<T = any>(url: string, params?: Record<string, any>, headers?: Record<string, string>): Promise<T>;
|
|
139
|
-
/** 通用请求 */
|
|
140
|
-
request<T = any>(options: HttpRequestOptions): Promise<T>;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* WebSocket 配置
|
|
144
|
-
*/
|
|
145
|
-
export interface WebSocketConfig {
|
|
146
|
-
/** WebSocket URL */
|
|
147
|
-
url: string;
|
|
148
|
-
/** 协议 */
|
|
149
|
-
protocols?: string | string[];
|
|
150
|
-
/** 是否自动重连 */
|
|
151
|
-
reconnect?: boolean;
|
|
152
|
-
/** 重连间隔(毫秒) */
|
|
153
|
-
reconnectInterval?: number;
|
|
154
|
-
/** 重连尝试次数 */
|
|
155
|
-
reconnectAttempts?: number;
|
|
156
|
-
/** 是否启用心跳 */
|
|
157
|
-
heartbeat?: boolean;
|
|
158
|
-
/** 心跳间隔(毫秒) */
|
|
159
|
-
heartbeatInterval?: number;
|
|
160
|
-
/** 心跳消息 */
|
|
161
|
-
heartbeatMessage?: string;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* WebSocket 管理器接口 - 管理 WebSocket 连接
|
|
165
|
-
*/
|
|
166
|
-
export interface IWebSocketManager extends IManager {
|
|
167
|
-
/** 连接 WebSocket */
|
|
168
|
-
connect(url: string, protocols?: string | string[]): void;
|
|
169
|
-
/** 断开连接 */
|
|
170
|
-
disconnect(code?: number, reason?: string): void;
|
|
171
|
-
/** 发送数据 */
|
|
172
|
-
send(data: string | ArrayBuffer | Blob | object): void;
|
|
173
|
-
/** 是否已连接 */
|
|
174
|
-
isConnected(): boolean;
|
|
175
|
-
/** 监听事件 */
|
|
176
|
-
on(event: 'open' | 'message' | 'error' | 'close', handler: Function): void;
|
|
177
|
-
/** 移除事件监听 */
|
|
178
|
-
off(event: 'open' | 'message' | 'error' | 'close', handler?: Function): void;
|
|
179
|
-
/** 获取连接状态 */
|
|
180
|
-
getReadyState(): number;
|
|
181
|
-
/** 配置 WebSocket */
|
|
182
|
-
configure(config: Partial<WebSocketConfig>): void;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* 事件消息键类型(由业务层扩展)
|
|
186
|
-
*/
|
|
187
|
-
export interface IEventMsgKey {
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* 将索引类型转换为任意类型的索引类型
|
|
191
|
-
*/
|
|
192
|
-
export type ToAnyIndexKey<IndexKey, AnyType> = IndexKey extends keyof AnyType ? IndexKey : keyof AnyType;
|
|
193
|
-
/**
|
|
194
|
-
* 监听器结果回调
|
|
195
|
-
*/
|
|
196
|
-
export type OnListenerResult<T = any> = (data?: T, callBack?: any) => void;
|
|
197
|
-
/**
|
|
198
|
-
* 监听器函数
|
|
199
|
-
*/
|
|
200
|
-
export type OnListener<T = any, K = any> = (value?: T, callBack?: OnListenerResult<K>, ...args: any[]) => void;
|
|
201
|
-
/**
|
|
202
|
-
* 监听器处理器配置
|
|
203
|
-
*/
|
|
204
|
-
export type ListenerHandler<keyType extends keyof any = any, ValueType = any, ResultType = any> = {
|
|
205
|
-
/** 事件键 */
|
|
206
|
-
key: keyType;
|
|
207
|
-
/** 监听函数 */
|
|
208
|
-
listener: OnListener<ValueType[ToAnyIndexKey<keyType, ValueType>], ResultType[ToAnyIndexKey<keyType, ResultType>]>;
|
|
209
|
-
/** 上下文 */
|
|
210
|
-
context?: any;
|
|
211
|
-
/** 额外参数 */
|
|
212
|
-
args?: any[];
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* 事件管理器接口 - 事件的发布订阅
|
|
216
|
-
*/
|
|
217
|
-
export interface IEventManager<MsgKeyType extends IEventMsgKey = IEventMsgKey, ValueType = any, ResultType = any> {
|
|
218
|
-
/** 监听事件 */
|
|
219
|
-
on<keyType extends keyof MsgKeyType>(keyOrHandler: keyType | ListenerHandler<keyType, ValueType, ResultType> | ListenerHandler<keyType, ValueType, ResultType>[], listener?: OnListener<ValueType[ToAnyIndexKey<keyType, ValueType>], ResultType[ToAnyIndexKey<keyType, ResultType>]>, context?: any, args?: any[]): void;
|
|
220
|
-
/** 监听一次事件 */
|
|
221
|
-
once<keyType extends keyof MsgKeyType>(keyOrHandler: keyType | ListenerHandler<keyType, ValueType, ResultType> | ListenerHandler<keyType, ValueType, ResultType>[], listener?: OnListener<ValueType[ToAnyIndexKey<keyType, ValueType>], ResultType[ToAnyIndexKey<keyType, ResultType>]>, context?: any, args?: any[]): void;
|
|
222
|
-
/** 移除事件监听 */
|
|
223
|
-
off<keyType extends keyof MsgKeyType>(key: keyType, listener: OnListener<ValueType[ToAnyIndexKey<keyType, ValueType>], ResultType[ToAnyIndexKey<keyType, ResultType>]>): void;
|
|
224
|
-
/** 移除所有事件监听 */
|
|
225
|
-
offAll<keyType extends keyof MsgKeyType>(key?: keyType, context?: any): void;
|
|
226
|
-
/** 派发事件 */
|
|
227
|
-
dispatch<keyType extends keyof MsgKeyType>(key: keyType, data?: ValueType[ToAnyIndexKey<keyType, ValueType>], callback?: OnListenerResult<ResultType[ToAnyIndexKey<keyType, ResultType>]>, persistence?: boolean): void;
|
|
228
|
-
/** 派发粘性事件(自动保存) */
|
|
229
|
-
dispatchSticky<keyType extends keyof MsgKeyType>(key: keyType, data?: ValueType[ToAnyIndexKey<keyType, ValueType>], callback?: OnListenerResult<ResultType[ToAnyIndexKey<keyType, ResultType>]>, persistence?: boolean): void;
|
|
230
|
-
/** 移除粘性广播 */
|
|
231
|
-
removeStickyBroadcast(key: keyof MsgKeyType): void;
|
|
232
|
-
/** 检查事件是否已注册 */
|
|
233
|
-
isRegistered(key: keyof MsgKeyType): boolean;
|
|
234
|
-
/** 获取持久化的值 */
|
|
235
|
-
getPersistentValue<keyType extends keyof MsgKeyType>(key: keyType): ValueType[ToAnyIndexKey<keyType, ValueType>] | undefined;
|
|
236
|
-
/** 销毁 */
|
|
237
|
-
dispose(): void;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* 红点管理器接口 - 管理 UI 红点提示
|
|
241
|
-
*/
|
|
242
|
-
export interface IRedDotManager extends IManager {
|
|
243
|
-
/** 设置红点数量 */
|
|
244
|
-
setCount(nodeId: string, count: number): void;
|
|
245
|
-
/** 获取红点数量 */
|
|
246
|
-
getCount(nodeId: string): number;
|
|
247
|
-
/** 监听红点变化 */
|
|
248
|
-
on(path: string, listener: Function): void;
|
|
249
|
-
/** 移除红点监听 */
|
|
250
|
-
off(path: string, listener: Function): void;
|
|
251
|
-
}
|
package/dist/core/index.d.ts
CHANGED
package/dist/libs/BaseView.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Component } from 'cc';
|
|
2
|
-
import { IView,
|
|
2
|
+
import { IView, UIOpenConfig } from '../core';
|
|
3
|
+
import { Broadcaster, ResLoader } from '.';
|
|
3
4
|
export declare abstract class BaseView extends Component implements IView {
|
|
4
5
|
/** @internal */
|
|
5
6
|
private readonly __isIView__;
|
|
6
7
|
private _eventProxy?;
|
|
7
8
|
private _eventHandlers;
|
|
8
|
-
protected get event():
|
|
9
|
+
protected get event(): Broadcaster;
|
|
9
10
|
private _loaderProxy?;
|
|
10
11
|
private _loaderHandlers;
|
|
11
|
-
protected get res():
|
|
12
|
+
protected get res(): ResLoader;
|
|
12
13
|
private _openConfig;
|
|
13
14
|
/**
|
|
14
15
|
* 打开时传入的配置数据
|
|
@@ -29,7 +30,12 @@ export declare abstract class BaseView extends Component implements IView {
|
|
|
29
30
|
abstract onPause(): void;
|
|
30
31
|
abstract onResume(): void;
|
|
31
32
|
abstract onEnter(args?: UIOpenConfig): void;
|
|
32
|
-
onExit(): void;
|
|
33
|
+
abstract onExit(): void;
|
|
34
|
+
/**
|
|
35
|
+
* 仅供框架内部使用,业务覆写onExit即可。
|
|
36
|
+
*/
|
|
37
|
+
/** @internal */
|
|
38
|
+
__exit__(): void;
|
|
33
39
|
protected onDestroy(): void;
|
|
34
40
|
/**
|
|
35
41
|
* 获取 Model 实例
|
package/dist/libs/BaseView.js
CHANGED
|
@@ -25,7 +25,8 @@ class BaseView extends Component {
|
|
|
25
25
|
this._eventHandlers.push({ key: keyOrHandler, listener: listener });
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
return Reflect.get(target, prop).apply(target, [keyOrHandler, listener, context, args]);
|
|
28
|
+
// return Reflect.get(target, prop).apply(target, [keyOrHandler, listener, context, args]);
|
|
29
|
+
return target[prop](keyOrHandler, listener, context, args);
|
|
29
30
|
};
|
|
30
31
|
}
|
|
31
32
|
return Reflect.get(target, prop);
|
|
@@ -76,13 +77,19 @@ class BaseView extends Component {
|
|
|
76
77
|
var _a;
|
|
77
78
|
return (_a = this._openConfig) === null || _a === void 0 ? void 0 : _a.args;
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
+
/**
|
|
81
|
+
* 仅供框架内部使用,业务覆写onExit即可。
|
|
82
|
+
*/
|
|
83
|
+
/** @internal */
|
|
84
|
+
__exit__() {
|
|
85
|
+
var _a, _b;
|
|
80
86
|
// 自动清理所有事件监听
|
|
81
87
|
this._eventHandlers.forEach(({ key, listener }) => {
|
|
82
88
|
//@ts-ignore
|
|
83
89
|
mf.event.off(key, listener);
|
|
84
90
|
});
|
|
85
91
|
this._eventHandlers = [];
|
|
92
|
+
(_b = (_a = this.__config__) === null || _a === void 0 ? void 0 : _a.onExitCallback) === null || _b === void 0 ? void 0 : _b.call(_a, this);
|
|
86
93
|
}
|
|
87
94
|
onDestroy() {
|
|
88
95
|
// 自动清理加载的资源
|
|
@@ -1,10 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 事件消息键类型(由业务层扩展)
|
|
3
|
+
* 使用字符串索引定义事件名和对应的数据类型
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // 在项目中扩展事件类型
|
|
8
|
+
* import 'dzkcc-mflow/libs'; // 👈 这一行很重要!没有这行表示重定义,这行表示扩展
|
|
9
|
+
* declare module 'dzkcc-mflow/libs' {
|
|
10
|
+
* interface IEventMsgKey {
|
|
11
|
+
* 'gameStart': { level: number };
|
|
12
|
+
* 'scoreChanged': number;
|
|
13
|
+
* 'userLogin': { userId: number; name: string };
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* // 使用时会有类型检查
|
|
18
|
+
* mf.event.on('gameStart', (data) => {
|
|
19
|
+
* console.log(data.level); // ✅ 有类型提示
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* mf.event.dispatch('scoreChanged', 100); // ✅ 正确
|
|
23
|
+
* mf.event.dispatch('unknownEvent', {}); // ❌ 类型错误:事件名不存在
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface IEventMsgKey {
|
|
27
|
+
[eventName: string]: any;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 监听器结果回调
|
|
31
|
+
*/
|
|
32
|
+
export type OnListenerResult<T = any> = (data?: T, callBack?: any) => void;
|
|
33
|
+
/**
|
|
34
|
+
* 监听器函数
|
|
35
|
+
*/
|
|
36
|
+
export type OnListener<T = any, K = any> = (value?: T, callBack?: OnListenerResult<K>, ...args: any[]) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 监听器处理器配置
|
|
39
|
+
*/
|
|
40
|
+
export type ListenerHandler = {
|
|
41
|
+
/** 事件键 */
|
|
42
|
+
key: keyof IEventMsgKey;
|
|
43
|
+
/** 监听函数 */
|
|
44
|
+
listener: OnListener;
|
|
45
|
+
/** 上下文 */
|
|
46
|
+
context?: any;
|
|
47
|
+
/** 额外参数 */
|
|
48
|
+
args?: any[];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* 事件广播器 - 非泛型版本
|
|
52
|
+
* 提供事件的注册、派发、粘性广播等功能
|
|
53
|
+
*/
|
|
54
|
+
export declare class Broadcaster {
|
|
3
55
|
private _persistBrodcastMap;
|
|
4
56
|
private _listenerHandlerMap;
|
|
5
57
|
private _stickBrodcastMap;
|
|
6
58
|
private _unuseHandlers;
|
|
7
59
|
constructor();
|
|
60
|
+
initialize(): void;
|
|
61
|
+
/**
|
|
62
|
+
* 销毁广播系统
|
|
63
|
+
*/
|
|
64
|
+
dispose(): void;
|
|
8
65
|
/**
|
|
9
66
|
* 回收handler
|
|
10
67
|
* @param handler
|
|
@@ -32,8 +89,8 @@ export declare class Broadcaster<MsgKeyType extends IEventMsgKey, ValueType = an
|
|
|
32
89
|
* @param args 透传参数
|
|
33
90
|
*
|
|
34
91
|
*/
|
|
35
|
-
on<
|
|
36
|
-
on
|
|
92
|
+
on<K extends keyof IEventMsgKey>(key: K, listener: OnListener, context?: any, args?: any[]): void;
|
|
93
|
+
on(handler: ListenerHandler | ListenerHandler[]): void;
|
|
37
94
|
/**
|
|
38
95
|
* 注册事件,只监听一次
|
|
39
96
|
* @param key 事件名
|
|
@@ -42,22 +99,22 @@ export declare class Broadcaster<MsgKeyType extends IEventMsgKey, ValueType = an
|
|
|
42
99
|
* @param args 透传参数
|
|
43
100
|
*
|
|
44
101
|
*/
|
|
45
|
-
once<
|
|
46
|
-
once
|
|
102
|
+
once<K extends keyof IEventMsgKey>(key: K, listener: OnListener, context?: any, args?: any[]): void;
|
|
103
|
+
once(handler: ListenerHandler | ListenerHandler[]): void;
|
|
47
104
|
/**
|
|
48
105
|
* 注销指定监听
|
|
49
106
|
* @param key 事件名
|
|
50
107
|
* @param listener 监听回调
|
|
51
108
|
* @return this
|
|
52
109
|
*/
|
|
53
|
-
off<
|
|
110
|
+
off<K extends keyof IEventMsgKey>(key: K, listener: OnListener): this;
|
|
54
111
|
/**
|
|
55
112
|
* 注销所有监听
|
|
56
113
|
* @param key
|
|
57
114
|
* @param context
|
|
58
115
|
*/
|
|
59
116
|
offAll(): void;
|
|
60
|
-
offAll<
|
|
117
|
+
offAll<K extends keyof IEventMsgKey>(key: K): void;
|
|
61
118
|
offAll(context: any): void;
|
|
62
119
|
/**
|
|
63
120
|
* 广播
|
|
@@ -67,7 +124,7 @@ export declare class Broadcaster<MsgKeyType extends IEventMsgKey, ValueType = an
|
|
|
67
124
|
* @param callback
|
|
68
125
|
* @param persistence 是否持久化消息类型。持久化的消息可以在任意时刻通过 getPersistentValue(key) 获取最后一次被持久化的数据。
|
|
69
126
|
*/
|
|
70
|
-
dispatch<
|
|
127
|
+
dispatch<K extends keyof IEventMsgKey>(key: K, data?: any, callback?: OnListenerResult, persistence?: boolean): void;
|
|
71
128
|
/**
|
|
72
129
|
* 广播一条粘性消息。如果广播系统中没有注册该类型的接收者,本条信息将被滞留在系统中,否则等效dispatch方法。
|
|
73
130
|
* 可以使用removeStickyBroadcast移除存在的粘性广播。
|
|
@@ -77,25 +134,21 @@ export declare class Broadcaster<MsgKeyType extends IEventMsgKey, ValueType = an
|
|
|
77
134
|
* @param callback
|
|
78
135
|
* @param persistence 是否持久化消息类型。持久化的消息可以在任意时刻通过 getPersistentValue(key) 获取最后一次被持久化的数据。
|
|
79
136
|
*/
|
|
80
|
-
dispatchSticky<
|
|
137
|
+
dispatchSticky<K extends keyof IEventMsgKey>(key: K, data?: any, callback?: OnListenerResult, persistence?: boolean): void;
|
|
81
138
|
/**
|
|
82
139
|
* 移除指定的粘性广播
|
|
83
140
|
*
|
|
84
141
|
* @param key
|
|
85
142
|
*/
|
|
86
|
-
removeStickyBroadcast(key:
|
|
143
|
+
removeStickyBroadcast<K extends keyof IEventMsgKey>(key: K): void;
|
|
87
144
|
/**
|
|
88
145
|
* 事件注册是否被注册
|
|
89
146
|
* @param key
|
|
90
147
|
*/
|
|
91
|
-
isRegistered(key:
|
|
148
|
+
isRegistered<K extends keyof IEventMsgKey>(key: K): boolean;
|
|
92
149
|
/**
|
|
93
150
|
* 获取被持久化的消息。ps:相同key的持久化广播会被覆盖。
|
|
94
151
|
* @param key
|
|
95
152
|
*/
|
|
96
|
-
getPersistentValue<
|
|
97
|
-
/**
|
|
98
|
-
* 销毁广播系统
|
|
99
|
-
*/
|
|
100
|
-
dispose(): void;
|
|
153
|
+
getPersistentValue<K extends keyof IEventMsgKey>(key: K): any | undefined;
|
|
101
154
|
}
|
package/dist/libs/Broadcaster.js
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import { ObjectUtil } from '../utils/ObjectUtil.js';
|
|
2
2
|
import { StringUtil } from '../utils/StringUtil.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 事件广播器 - 非泛型版本
|
|
6
|
+
* 提供事件的注册、派发、粘性广播等功能
|
|
7
|
+
*/
|
|
4
8
|
class Broadcaster {
|
|
5
9
|
constructor() {
|
|
10
|
+
this.initialize();
|
|
11
|
+
}
|
|
12
|
+
initialize() {
|
|
6
13
|
this._persistBrodcastMap = {};
|
|
7
14
|
this._listenerHandlerMap = {};
|
|
8
15
|
this._stickBrodcastMap = {};
|
|
9
16
|
this._unuseHandlers = [];
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* 销毁广播系统
|
|
20
|
+
*/
|
|
21
|
+
dispose() {
|
|
22
|
+
//@ts-ignore
|
|
23
|
+
this._listenerHandlerMap = undefined;
|
|
24
|
+
//@ts-ignore
|
|
25
|
+
this._stickBrodcastMap = undefined;
|
|
26
|
+
//@ts-ignore
|
|
27
|
+
this._persistBrodcastMap = undefined;
|
|
28
|
+
}
|
|
11
29
|
/**
|
|
12
30
|
* 回收handler
|
|
13
31
|
* @param handler
|
|
@@ -17,8 +35,11 @@ class Broadcaster {
|
|
|
17
35
|
return;
|
|
18
36
|
//@ts-ignore
|
|
19
37
|
handler.listener = undefined;
|
|
38
|
+
//@ts-ignore
|
|
20
39
|
handler.key = undefined;
|
|
40
|
+
//@ts-ignore
|
|
21
41
|
handler.args = undefined;
|
|
42
|
+
//@ts-ignore
|
|
22
43
|
handler.context = undefined;
|
|
23
44
|
this._unuseHandlers.push(handler);
|
|
24
45
|
}
|
|
@@ -46,10 +67,10 @@ class Broadcaster {
|
|
|
46
67
|
const stickyHandlers = this._stickBrodcastMap[msgKey];
|
|
47
68
|
if (stickyHandlers) {
|
|
48
69
|
//需要把执行过的粘性广播删除,防止注册时再次执行
|
|
49
|
-
this.removeStickyBroadcast(
|
|
70
|
+
this.removeStickyBroadcast(handler.key);
|
|
50
71
|
for (let i = 0; i < stickyHandlers.length; i++) {
|
|
51
72
|
let e = stickyHandlers[i];
|
|
52
|
-
this.dispatch(
|
|
73
|
+
this.dispatch(e.key, e.data, e.callback, e.persistence);
|
|
53
74
|
}
|
|
54
75
|
}
|
|
55
76
|
}
|
|
@@ -63,11 +84,11 @@ class Broadcaster {
|
|
|
63
84
|
if (!handler.listener)
|
|
64
85
|
return;
|
|
65
86
|
let args = [];
|
|
66
|
-
if (data) {
|
|
87
|
+
if (data !== undefined) {
|
|
67
88
|
args.push(data);
|
|
68
89
|
}
|
|
69
90
|
if (callback) {
|
|
70
|
-
|
|
91
|
+
args.push(callback);
|
|
71
92
|
}
|
|
72
93
|
//如果有透传参数,则添加到参数列表中
|
|
73
94
|
if (handler.args && handler.args.length > 0) {
|
|
@@ -133,16 +154,16 @@ class Broadcaster {
|
|
|
133
154
|
this._checkListenerValidity(msgKey);
|
|
134
155
|
};
|
|
135
156
|
if (key) { //清除指定key的所有监听
|
|
136
|
-
|
|
157
|
+
const keyStr = key;
|
|
158
|
+
if (!handlerMap[keyStr]) {
|
|
137
159
|
throw new Error(`没有找到key为${key.toString()}的事件`);
|
|
138
160
|
}
|
|
139
|
-
processHandler(handlerMap[
|
|
161
|
+
processHandler(handlerMap[keyStr], keyStr, false);
|
|
140
162
|
}
|
|
141
163
|
else { //处理全局或上下文清除
|
|
142
164
|
const isGlobalClear = !context;
|
|
143
165
|
Object.keys(handlerMap).forEach((msgKey) => {
|
|
144
|
-
|
|
145
|
-
processHandler(handlerMap[k], k, !isGlobalClear);
|
|
166
|
+
processHandler(handlerMap[msgKey], msgKey, !isGlobalClear);
|
|
146
167
|
});
|
|
147
168
|
isGlobalClear && (this._listenerHandlerMap = {});
|
|
148
169
|
}
|
|
@@ -156,14 +177,17 @@ class Broadcaster {
|
|
|
156
177
|
* @param persistence 是否持久化消息类型。持久化的消息可以在任意时刻通过 getPersistentValue(key) 获取最后一次被持久化的数据。
|
|
157
178
|
*/
|
|
158
179
|
dispatch(key, data, callback, persistence) {
|
|
159
|
-
|
|
180
|
+
const keyStr = key;
|
|
181
|
+
if (StringUtil.isEmptyOrWhiteSpace(keyStr)) {
|
|
160
182
|
throw new Error('广播的key不能为空');
|
|
161
183
|
}
|
|
162
184
|
//持久化
|
|
163
|
-
|
|
164
|
-
|
|
185
|
+
if (persistence) {
|
|
186
|
+
this._persistBrodcastMap[keyStr] = data;
|
|
187
|
+
}
|
|
188
|
+
const handlers = this._listenerHandlerMap[keyStr];
|
|
165
189
|
if (!handlers || handlers.length == 0) {
|
|
166
|
-
console.warn(`没有注册广播:${
|
|
190
|
+
console.warn(`没有注册广播:${keyStr}`);
|
|
167
191
|
return;
|
|
168
192
|
}
|
|
169
193
|
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
@@ -173,7 +197,7 @@ class Broadcaster {
|
|
|
173
197
|
this.off(key, handler.listener);
|
|
174
198
|
}
|
|
175
199
|
}
|
|
176
|
-
this._checkListenerValidity(
|
|
200
|
+
this._checkListenerValidity(keyStr);
|
|
177
201
|
}
|
|
178
202
|
/**
|
|
179
203
|
* 广播一条粘性消息。如果广播系统中没有注册该类型的接收者,本条信息将被滞留在系统中,否则等效dispatch方法。
|
|
@@ -187,16 +211,17 @@ class Broadcaster {
|
|
|
187
211
|
dispatchSticky(key, data, callback, persistence) {
|
|
188
212
|
var _a;
|
|
189
213
|
var _b;
|
|
190
|
-
|
|
214
|
+
const keyStr = key;
|
|
215
|
+
if (StringUtil.isEmptyOrWhiteSpace(keyStr)) {
|
|
191
216
|
throw new Error('广播的key不能为空');
|
|
192
217
|
}
|
|
193
218
|
//如果已经有了监听者,则直接广播
|
|
194
|
-
if (this._listenerHandlerMap[
|
|
219
|
+
if (this._listenerHandlerMap[keyStr]) {
|
|
195
220
|
this.dispatch(key, data, callback, persistence);
|
|
196
221
|
return;
|
|
197
222
|
}
|
|
198
223
|
//注意:??= 在ES2021(TypeScript版本4.4)引入
|
|
199
|
-
((_a = (_b = this._stickBrodcastMap)[
|
|
224
|
+
((_a = (_b = this._stickBrodcastMap)[keyStr]) !== null && _a !== void 0 ? _a : (_b[keyStr] = [])).push({
|
|
200
225
|
key: key,
|
|
201
226
|
data: data,
|
|
202
227
|
callback: callback,
|
|
@@ -204,7 +229,9 @@ class Broadcaster {
|
|
|
204
229
|
});
|
|
205
230
|
//如果persistence=true需要先持久化,不能等到通过on->broadcast的时候再持久化。
|
|
206
231
|
//因为中途可能会有removeStickyBroadcast操作,那么on就不会调用broadcast,造成持久化无效bug。
|
|
207
|
-
|
|
232
|
+
if (persistence) {
|
|
233
|
+
this._persistBrodcastMap[keyStr] = data;
|
|
234
|
+
}
|
|
208
235
|
}
|
|
209
236
|
/**
|
|
210
237
|
* 移除指定的粘性广播
|
|
@@ -212,8 +239,9 @@ class Broadcaster {
|
|
|
212
239
|
* @param key
|
|
213
240
|
*/
|
|
214
241
|
removeStickyBroadcast(key) {
|
|
215
|
-
|
|
216
|
-
|
|
242
|
+
const keyStr = key;
|
|
243
|
+
if (this._stickBrodcastMap[keyStr]) {
|
|
244
|
+
delete this._stickBrodcastMap[keyStr];
|
|
217
245
|
}
|
|
218
246
|
}
|
|
219
247
|
/**
|
|
@@ -230,17 +258,6 @@ class Broadcaster {
|
|
|
230
258
|
getPersistentValue(key) {
|
|
231
259
|
return this._persistBrodcastMap[key];
|
|
232
260
|
}
|
|
233
|
-
/**
|
|
234
|
-
* 销毁广播系统
|
|
235
|
-
*/
|
|
236
|
-
dispose() {
|
|
237
|
-
//@ts-ignore
|
|
238
|
-
this._listenerHandlerMap = undefined;
|
|
239
|
-
//@ts-ignore
|
|
240
|
-
this._stickBrodcastMap = undefined;
|
|
241
|
-
//@ts-ignore
|
|
242
|
-
this._persistBrodcastMap = undefined;
|
|
243
|
-
}
|
|
244
261
|
}
|
|
245
262
|
|
|
246
263
|
export { Broadcaster };
|
package/dist/libs/CocosCore.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Component } from 'cc';
|
|
2
2
|
import { AbstractCore } from '../core/Core.js';
|
|
3
3
|
import { ServiceLocator } from '../core/ServiceLocator.js';
|
|
4
|
-
import
|
|
5
|
-
import { ResLoader } from './ResLoader.js';
|
|
4
|
+
import './BaseView.js';
|
|
6
5
|
import { Broadcaster } from './Broadcaster.js';
|
|
6
|
+
import { ResLoader } from './ResLoader.js';
|
|
7
|
+
import { CCUIManager } from './UIManager.js';
|
|
8
|
+
import './UIRoot.js';
|
|
7
9
|
import { HttpManager } from './HttpManager.js';
|
|
8
10
|
import { WebSocketManager } from './WebSocketManager.js';
|
|
9
11
|
import { RedDotManager } from './indicator/RedDotManager.js';
|
|
12
|
+
import './indicator/UIRedDot.js';
|
|
10
13
|
import '../App.js';
|
|
11
14
|
|
|
12
15
|
class Core extends AbstractCore {
|
|
@@ -15,7 +18,7 @@ class Core extends AbstractCore {
|
|
|
15
18
|
// 注册框架基础服务
|
|
16
19
|
ServiceLocator.regService('EventManager', new Broadcaster());
|
|
17
20
|
ServiceLocator.regService('ResLoader', new ResLoader());
|
|
18
|
-
ServiceLocator.regService('UIManager', new
|
|
21
|
+
ServiceLocator.regService('UIManager', new CCUIManager());
|
|
19
22
|
ServiceLocator.regService('HttpManager', new HttpManager());
|
|
20
23
|
ServiceLocator.regService('WebSocketManager', new WebSocketManager());
|
|
21
24
|
ServiceLocator.regService('RedDotManager', new RedDotManager());
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 请求配置
|
|
3
|
+
*/
|
|
4
|
+
export interface HttpRequestOptions {
|
|
5
|
+
/** 请求 URL */
|
|
6
|
+
url: string;
|
|
7
|
+
/** HTTP 方法 */
|
|
8
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
9
|
+
/** 请求头 */
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
/** URL 参数 */
|
|
12
|
+
params?: Record<string, any>;
|
|
13
|
+
/** 请求体数据 */
|
|
14
|
+
data?: any;
|
|
15
|
+
/** 超时时间(毫秒) */
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}
|
|
2
18
|
/**
|
|
3
19
|
* HTTP 管理器实现类
|
|
4
20
|
*
|
|
@@ -18,7 +34,7 @@ import { IHttpManager, HttpRequestOptions } from "../core";
|
|
|
18
34
|
↓
|
|
19
35
|
【错误拦截器】统一处理错误(如显示提示、记录日志等)
|
|
20
36
|
*/
|
|
21
|
-
export declare class HttpManager
|
|
37
|
+
export declare class HttpManager {
|
|
22
38
|
private baseURL;
|
|
23
39
|
private defaultTimeout;
|
|
24
40
|
private defaultHeaders;
|