@cc-component/cc-ex-component 2.0.8 → 2.1.0
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
|
@@ -466,7 +466,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
466
466
|
private refreshData(key: string, value: any) {
|
|
467
467
|
const funcName = bindingMapFunc.get(this.className)?.get(key)
|
|
468
468
|
if (this.isOnLoad) {
|
|
469
|
-
this[funcName]?.(value)
|
|
469
|
+
this[funcName]?.(value, true)
|
|
470
470
|
} else {
|
|
471
471
|
this.funcMap.set(funcName, value)
|
|
472
472
|
}
|
|
@@ -475,7 +475,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
475
475
|
private refreshFuncName() {
|
|
476
476
|
// console.error('刷新数据失败:', this.funcMap)
|
|
477
477
|
this.funcMap.forEach((value, key) => {
|
|
478
|
-
this[key]?.(value)
|
|
478
|
+
this[key]?.(value, true)//true:是set方法,否则是get方法
|
|
479
479
|
})
|
|
480
480
|
}
|
|
481
481
|
|
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)
|