@cc-component/cc-ex-component 2.0.0 → 2.0.3
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,21 @@ 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 call = () => {
|
|
189
|
+
if (!propertyKey.endsWith('Data')) { console.error('属性名称 必须以Data结尾', propertyKey) }
|
|
190
|
+
return propertyKey.replace('Data', '')
|
|
191
|
+
}
|
|
192
|
+
const viewClassName = viewName ? viewName : call()
|
|
193
|
+
const className = target.constructor
|
|
194
|
+
if (!bindingMapView.has(viewClassName)) { bindingMapView.set(viewClassName, { key: '', manager: null }); }
|
|
195
|
+
bindingMapView.get(viewClassName)!.key = propertyKey
|
|
196
|
+
bindingMapView.get(viewClassName)!.manager = className
|
|
184
197
|
|
|
198
|
+
};
|
|
199
|
+
}
|
|
185
200
|
|
|
186
201
|
export function BindTable<T extends Component>(dataPath: string, param?: ITableViewEvents) {
|
|
187
202
|
dataPath = baseData + '.' + dataPath;
|
|
@@ -233,20 +248,21 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
233
248
|
_bindings: Record<string, string> = {}; // key: dataPath, value: uiProp
|
|
234
249
|
|
|
235
250
|
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
|
-
|
|
251
|
+
private touch_start = 'CALL_TOUCH_START'
|
|
252
|
+
private touch_move = 'CALL_TOUCH_MOVE'
|
|
253
|
+
private touch_end = 'CALL_TOUCH_END'
|
|
254
|
+
private touch_cancel = 'CALL_TOUCH_CANCEL'
|
|
255
|
+
|
|
256
|
+
private touch_start_scale = 'touch_start_scale'
|
|
257
|
+
private touch_end_scale = 'touch_end_scale'
|
|
258
|
+
private touch_cancel_scale = 'touch_cancel_scale'
|
|
259
|
+
|
|
260
|
+
private touch_click = 'CALL_CLICK'
|
|
261
|
+
private touch_slide = 'CALL_SLIDE_EVENT'
|
|
262
|
+
private touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
263
|
+
private touch_editbox = 'CALL_EDITBOX_EVENT'
|
|
264
|
+
/**是对象 */
|
|
265
|
+
private className: any
|
|
250
266
|
|
|
251
267
|
/**ui配置 */
|
|
252
268
|
config: {
|
|
@@ -354,13 +370,13 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
354
370
|
protected onLoad(): void {
|
|
355
371
|
super.onLoad()
|
|
356
372
|
this.isOnLoad = true;
|
|
357
|
-
this.bindFunc()
|
|
358
373
|
this.onTouch()
|
|
359
374
|
this.managerData()
|
|
360
375
|
}
|
|
361
376
|
// 在 withDataBinding 返回的 class 中
|
|
362
377
|
protected onDestroy(): void {
|
|
363
378
|
this.unbindViewModel();
|
|
379
|
+
this.bindData(false)
|
|
364
380
|
super.onDestroy?.();
|
|
365
381
|
}
|
|
366
382
|
|
|
@@ -368,6 +384,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
368
384
|
|
|
369
385
|
onLoadFinished() {
|
|
370
386
|
this.refreshFuncName()
|
|
387
|
+
this.bindData(true)
|
|
371
388
|
}
|
|
372
389
|
|
|
373
390
|
managerData() {
|
|
@@ -383,7 +400,14 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
383
400
|
// this.offTouch()
|
|
384
401
|
}
|
|
385
402
|
|
|
386
|
-
|
|
403
|
+
|
|
404
|
+
bindData(isBind: boolean) {
|
|
405
|
+
const name = js.getClassName(this)
|
|
406
|
+
const managerData = bindingMapView.get(name)
|
|
407
|
+
if (managerData) {
|
|
408
|
+
const manager: any = ExComponentModule.EmitBindData(managerData.manager)
|
|
409
|
+
manager[managerData.key] = isBind ? this.viewModel : null
|
|
410
|
+
}
|
|
387
411
|
}
|
|
388
412
|
|
|
389
413
|
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
|
}
|