@cc-component/cc-ex-component 2.0.7 → 2.0.9
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 +8 -0
- 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
|
@@ -26,6 +26,8 @@ declare global {
|
|
|
26
26
|
addOutline(colorHex: string, font: number): string
|
|
27
27
|
/**添加粗体 -富文本*/
|
|
28
28
|
addBold(): string
|
|
29
|
+
/**占位符格式化:示例:format("恢复{0}生命", [50]) */
|
|
30
|
+
format(values: any[]);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
interface Any {
|
|
@@ -804,6 +806,12 @@ String.prototype.addOutline = function (colorHex: string, font: number): string
|
|
|
804
806
|
String.prototype.addBold = function (): string {
|
|
805
807
|
return `<b>${this}</b>`
|
|
806
808
|
};
|
|
809
|
+
String.prototype.format = function (values: any[]): string {
|
|
810
|
+
return this.replace(/\{(\d+)\}/g, (_, index) => {
|
|
811
|
+
const idx = parseInt(index);
|
|
812
|
+
return idx < values.length ? String(values[idx]) : ""; // 超出范围则替换为空
|
|
813
|
+
});
|
|
814
|
+
};
|
|
807
815
|
Label.prototype.fromHEX = function (this: Label, hex: string): void {
|
|
808
816
|
const label = this;
|
|
809
817
|
label.color = (new Color()).fromHEX(hex)
|