@cc-component/cc-ex-component 2.0.6 → 2.0.8
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 +30 -1
- package/assets/ex/ExCommon.ts +7 -7
- package/package.json +1 -1
package/assets/core/ViewModel.ts
CHANGED
|
@@ -72,6 +72,7 @@ interface ICollectViewEvents {
|
|
|
72
72
|
const bindingMap = new Map<any, Map<string, IBindingData>>();
|
|
73
73
|
const bindingMapFunc = new Map<any, Map<string, string>>();
|
|
74
74
|
const bindingMapView = new Map<any, { key: string, manager: any }>();
|
|
75
|
+
const bindingMapClick = new Map<any, Map<string, { func: string, subSx: string, subFunc: string }>>();
|
|
75
76
|
|
|
76
77
|
const baseData = 'viewModel'
|
|
77
78
|
const skip = "func"
|
|
@@ -186,6 +187,18 @@ export function Bind<T extends Component>(path?: string, param?: IBindingDataEve
|
|
|
186
187
|
bindingMap.get(className)!.set(propertyKey, data);
|
|
187
188
|
};
|
|
188
189
|
}
|
|
190
|
+
export function BindClick(propertyName: string, funcName?: string) {
|
|
191
|
+
return function (target: any, propertyKey: string) {
|
|
192
|
+
const className = target.constructor.prototype
|
|
193
|
+
if (!bindingMapClick.has(className)) { bindingMapClick.set(className, new Map()); }
|
|
194
|
+
const data = bindingMapClick.get(className)
|
|
195
|
+
if (!data.has(propertyKey)) { data.set(propertyKey, { func: '', subFunc: '', subSx: '' }) }
|
|
196
|
+
const sub = data.get(propertyKey)
|
|
197
|
+
sub.func = propertyKey
|
|
198
|
+
sub.subSx = `${propertyName}`
|
|
199
|
+
sub.subFunc = `${funcName ?? propertyKey}`
|
|
200
|
+
};
|
|
201
|
+
}
|
|
189
202
|
|
|
190
203
|
export function BindFunc(path?: string) {
|
|
191
204
|
return function (target: any, propertyKey: string) {
|
|
@@ -409,6 +422,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
409
422
|
onLoadFinished() {
|
|
410
423
|
this.refreshFuncName()
|
|
411
424
|
this.bindData(true)
|
|
425
|
+
this.bindClick();
|
|
412
426
|
}
|
|
413
427
|
|
|
414
428
|
managerData() {
|
|
@@ -424,7 +438,22 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
424
438
|
// this.offTouch()
|
|
425
439
|
}
|
|
426
440
|
|
|
427
|
-
|
|
441
|
+
bindClick() {
|
|
442
|
+
const data = bindingMapClick.get(this.className)
|
|
443
|
+
if (data) {
|
|
444
|
+
const self = this;
|
|
445
|
+
for (const [key, value] of data) {
|
|
446
|
+
const subObj = this[value.subSx]
|
|
447
|
+
if (subObj) {
|
|
448
|
+
const oriFunc = this[value.subSx][value.subFunc]
|
|
449
|
+
this[value.subSx][value.subFunc] = function (...args) {
|
|
450
|
+
oriFunc.apply(this, args)
|
|
451
|
+
self[value.func](args)
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
428
457
|
bindData(isBind: boolean) {
|
|
429
458
|
const name = js.getClassName(this)
|
|
430
459
|
const managerData = bindingMapView.get(name)
|
package/assets/ex/ExCommon.ts
CHANGED
|
@@ -265,8 +265,7 @@ declare module 'cc' {
|
|
|
265
265
|
interface Label {
|
|
266
266
|
/**动画播放 */
|
|
267
267
|
play(param: {
|
|
268
|
-
|
|
269
|
-
endValue: number,
|
|
268
|
+
end: number,
|
|
270
269
|
duration: number,
|
|
271
270
|
formatter?: (value: number) => string,
|
|
272
271
|
onComplete?: () => void
|
|
@@ -718,27 +717,28 @@ Map.prototype.toObject = function (): Object {
|
|
|
718
717
|
Label.prototype.play = function (
|
|
719
718
|
this: Label,
|
|
720
719
|
param: {
|
|
721
|
-
|
|
722
|
-
endValue: number,
|
|
720
|
+
end: number,
|
|
723
721
|
duration: number,
|
|
724
722
|
formatter: (value: number) => string,
|
|
725
723
|
onComplete?: () => void
|
|
726
724
|
}
|
|
727
725
|
): void {
|
|
728
726
|
const label = this;
|
|
729
|
-
|
|
730
727
|
// 如果已有动画,先停止
|
|
731
728
|
if (label._currentTween) {
|
|
732
729
|
label._currentTween.stop();
|
|
733
730
|
}
|
|
731
|
+
const start = label.startValue ?? 0;
|
|
732
|
+
label.startValue = start;
|
|
734
733
|
// 使用 tween 动画
|
|
735
|
-
const obj: { value: number } = { value:
|
|
734
|
+
const obj: { value: number } = { value: start }
|
|
736
735
|
label._currentTween = tween(obj)
|
|
737
736
|
.to(
|
|
738
737
|
param.duration,
|
|
739
|
-
{ value: param.
|
|
738
|
+
{ value: param.end },
|
|
740
739
|
{
|
|
741
740
|
onUpdate(target: { value: number }) {
|
|
741
|
+
label.startValue = target.value
|
|
742
742
|
label.string = param.formatter?.(target.value) ?? (Math.floor(target.value) + '');
|
|
743
743
|
},
|
|
744
744
|
easing: "quadOut",
|