@cc-component/cc-ex-component 2.0.0 → 2.0.2
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/assets/core/ViewModel.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { SpriteFrame } from 'cc';
|
|
|
21
21
|
import { tween } from 'cc';
|
|
22
22
|
import { v3 } from 'cc';
|
|
23
23
|
import { BaseReference } from '../core/BaseReference';
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
|
|
26
26
|
interface IBindingData extends ITableViewEvents, IBindingDataEvents {
|
|
27
27
|
dataPath: string;
|
|
@@ -71,6 +71,7 @@ interface ICollectViewEvents {
|
|
|
71
71
|
// 全局存储绑定关系: { className -> { uiProp: dataPath } }
|
|
72
72
|
const bindingMap = new Map<any, Map<string, IBindingData>>();
|
|
73
73
|
const bindingMapFunc = new Map<any, Map<string, string>>();
|
|
74
|
+
const bindingMapView = new Map<any, { key: string, manager: any }>();
|
|
74
75
|
|
|
75
76
|
const baseData = 'viewModel'
|
|
76
77
|
const skip = "func"
|
|
@@ -173,7 +174,7 @@ export function Bind<T extends Component>(path?: string, param?: IBindingDataEve
|
|
|
173
174
|
};
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
export function BindFunc
|
|
177
|
+
export function BindFunc(path?: string) {
|
|
177
178
|
return function (target: any, propertyKey: string) {
|
|
178
179
|
const className = target.constructor.prototype
|
|
179
180
|
const funcName = path ? path : propertyKey
|
|
@@ -181,7 +182,17 @@ export function BindFunc<T extends Component>(path?: string, param?: IBindingDat
|
|
|
181
182
|
bindingMapFunc.get(className)!.set(propertyKey, funcName);
|
|
182
183
|
};
|
|
183
184
|
}
|
|
185
|
+
/**绑定自定义viewModel */
|
|
186
|
+
export function BindData(viewName?: string) {
|
|
187
|
+
return function (target: any, propertyKey: string) {
|
|
188
|
+
const viewClassName = viewName ? viewName : propertyKey
|
|
189
|
+
const className = target.constructor
|
|
190
|
+
if (!bindingMapView.has(viewClassName)) { bindingMapView.set(viewClassName, { key: '', manager: null }); }
|
|
191
|
+
bindingMapView.get(viewClassName)!.key = propertyKey
|
|
192
|
+
bindingMapView.get(viewClassName)!.manager = className
|
|
184
193
|
|
|
194
|
+
};
|
|
195
|
+
}
|
|
185
196
|
|
|
186
197
|
export function BindTable<T extends Component>(dataPath: string, param?: ITableViewEvents) {
|
|
187
198
|
dataPath = baseData + '.' + dataPath;
|
|
@@ -233,20 +244,21 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
233
244
|
_bindings: Record<string, string> = {}; // key: dataPath, value: uiProp
|
|
234
245
|
|
|
235
246
|
viewModel: any
|
|
236
|
-
touch_start = 'CALL_TOUCH_START'
|
|
237
|
-
touch_move = 'CALL_TOUCH_MOVE'
|
|
238
|
-
touch_end = 'CALL_TOUCH_END'
|
|
239
|
-
touch_cancel = 'CALL_TOUCH_CANCEL'
|
|
240
|
-
|
|
241
|
-
touch_start_scale = 'touch_start_scale'
|
|
242
|
-
touch_end_scale = 'touch_end_scale'
|
|
243
|
-
touch_cancel_scale = 'touch_cancel_scale'
|
|
244
|
-
|
|
245
|
-
touch_click = 'CALL_CLICK'
|
|
246
|
-
touch_slide = 'CALL_SLIDE_EVENT'
|
|
247
|
-
touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
248
|
-
touch_editbox = 'CALL_EDITBOX_EVENT'
|
|
249
|
-
|
|
247
|
+
private touch_start = 'CALL_TOUCH_START'
|
|
248
|
+
private touch_move = 'CALL_TOUCH_MOVE'
|
|
249
|
+
private touch_end = 'CALL_TOUCH_END'
|
|
250
|
+
private touch_cancel = 'CALL_TOUCH_CANCEL'
|
|
251
|
+
|
|
252
|
+
private touch_start_scale = 'touch_start_scale'
|
|
253
|
+
private touch_end_scale = 'touch_end_scale'
|
|
254
|
+
private touch_cancel_scale = 'touch_cancel_scale'
|
|
255
|
+
|
|
256
|
+
private touch_click = 'CALL_CLICK'
|
|
257
|
+
private touch_slide = 'CALL_SLIDE_EVENT'
|
|
258
|
+
private touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
259
|
+
private touch_editbox = 'CALL_EDITBOX_EVENT'
|
|
260
|
+
/**是对象 */
|
|
261
|
+
private className: any
|
|
250
262
|
|
|
251
263
|
/**ui配置 */
|
|
252
264
|
config: {
|
|
@@ -354,13 +366,13 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
354
366
|
protected onLoad(): void {
|
|
355
367
|
super.onLoad()
|
|
356
368
|
this.isOnLoad = true;
|
|
357
|
-
this.bindFunc()
|
|
358
369
|
this.onTouch()
|
|
359
370
|
this.managerData()
|
|
360
371
|
}
|
|
361
372
|
// 在 withDataBinding 返回的 class 中
|
|
362
373
|
protected onDestroy(): void {
|
|
363
374
|
this.unbindViewModel();
|
|
375
|
+
this.bindData(false)
|
|
364
376
|
super.onDestroy?.();
|
|
365
377
|
}
|
|
366
378
|
|
|
@@ -368,6 +380,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
368
380
|
|
|
369
381
|
onLoadFinished() {
|
|
370
382
|
this.refreshFuncName()
|
|
383
|
+
this.bindData(true)
|
|
371
384
|
}
|
|
372
385
|
|
|
373
386
|
managerData() {
|
|
@@ -383,7 +396,14 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
383
396
|
// this.offTouch()
|
|
384
397
|
}
|
|
385
398
|
|
|
386
|
-
|
|
399
|
+
|
|
400
|
+
bindData(isBind: boolean) {
|
|
401
|
+
const name = js.getClassName(this)
|
|
402
|
+
const managerData = bindingMapView.get(name)
|
|
403
|
+
if (managerData) {
|
|
404
|
+
const manager: any = ExComponentModule.EmitBindData(managerData.manager)
|
|
405
|
+
manager[managerData.key] = isBind ? this.viewModel : null
|
|
406
|
+
}
|
|
387
407
|
}
|
|
388
408
|
|
|
389
409
|
private refreshData(key: string, value: any) {
|
|
@@ -20,7 +20,7 @@ export class ExComponentModule {
|
|
|
20
20
|
paramSpinePlay: { play: (param: { spine: sp.Skeleton, value: { path: string, bundle: string, param?: ISpinePlayData[] } }) => void }
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
paramUIWindow: { onLoad: (config: any, viewModel: any) => void }
|
|
23
|
+
paramUIWindow: { onLoad: (config: any, viewModel: any) => void, bindData: (className: any) => any }
|
|
24
24
|
paramClose: { close: (openParam: any, closeParam: any) => void }
|
|
25
25
|
|
|
26
26
|
ResetBaseWindow: string = "BaseWindow";
|
|
@@ -46,7 +46,7 @@ export class ExComponentModule {
|
|
|
46
46
|
if (!isGet) ExComponentModule.Ins.ResetBaseWindow = name
|
|
47
47
|
return ExComponentModule.Ins.ResetBaseWindow
|
|
48
48
|
}
|
|
49
|
-
static OnVMManager(param: { onLoad: (config: any, viewModel: any) => void }) {
|
|
49
|
+
static OnVMManager(param: { onLoad: (config: any, viewModel: any) => void, bindData: (className: any) => any }) {
|
|
50
50
|
ExComponentModule.Ins.paramUIWindow = param
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -88,6 +88,10 @@ export class ExComponentModule {
|
|
|
88
88
|
return ExComponentModule.Ins.paramUIWindow?.onLoad?.(param, viewModel)
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
static EmitBindData(className: any) {
|
|
92
|
+
return ExComponentModule.Ins.paramUIWindow?.bindData?.(className)
|
|
93
|
+
}
|
|
94
|
+
|
|
91
95
|
static EmitCloseWindow(openParam: any, closeParam: any) {
|
|
92
96
|
return ExComponentModule.Ins.paramClose?.close?.(openParam, closeParam)
|
|
93
97
|
}
|
|
@@ -35,7 +35,8 @@ declare global {
|
|
|
35
35
|
/**重置基础窗口 */
|
|
36
36
|
function ResetBaseWindow(name?: string, isGet?: boolean);
|
|
37
37
|
/**监听UI onLoad 给模块manager 赋值 */
|
|
38
|
-
function OnVMManager(param: { onLoad: (config: IConfig, viewModel: any) => void });
|
|
38
|
+
function OnVMManager(param: { onLoad: (config: IConfig, viewModel: any) => void, bindData: (className: string) => any });
|
|
39
|
+
|
|
39
40
|
/**组件:内部使用方法 */
|
|
40
41
|
function Emit(btn: Button);
|
|
41
42
|
function EmitAnim();
|
|
@@ -45,6 +46,7 @@ declare global {
|
|
|
45
46
|
function EmitLoadSpine(param: any): Promise<sp.SkeletonData>;
|
|
46
47
|
function EmitGetSpine(param: any): sp.SkeletonData;
|
|
47
48
|
function EmitUIWindow(param: IConfig, viewModel: any);
|
|
49
|
+
function EmitBindData(className: any);
|
|
48
50
|
function EmitCloseWindow(openParam: any, closeParam: any);
|
|
49
51
|
function EmitSpinePlay(param: { spine: sp.Skeleton, value: { path: string, bundle: string, param?: ISpinePlayData[] } });
|
|
50
52
|
}
|