@cc-component/cc-ex-component 1.6.9 → 1.7.1
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 +16 -15
- package/package.json +1 -1
package/assets/core/ViewModel.ts
CHANGED
|
@@ -63,7 +63,7 @@ interface ICollectViewEvents {
|
|
|
63
63
|
// 全局存储绑定关系: { className -> { uiProp: dataPath } }
|
|
64
64
|
const bindingMap = new Map<any, Map<string, IBindingData>>();
|
|
65
65
|
const baseData = 'viewModel'
|
|
66
|
-
const skip = "
|
|
66
|
+
const skip = "_"
|
|
67
67
|
export const refMap: Map<any, string[]> = new Map();
|
|
68
68
|
|
|
69
69
|
// const comType = {
|
|
@@ -241,6 +241,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
241
241
|
// ✅ 跳过 $ 开头的属性:不触发响应式更新
|
|
242
242
|
if (key.startsWith(skip)) {
|
|
243
243
|
target[key] = value;
|
|
244
|
+
this.refreshData(key, value)
|
|
244
245
|
return true;
|
|
245
246
|
}
|
|
246
247
|
else if (value?.skip) {
|
|
@@ -309,6 +310,9 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
309
310
|
this.offTouch()
|
|
310
311
|
}
|
|
311
312
|
|
|
313
|
+
refreshData(key: string, value: any) {
|
|
314
|
+
|
|
315
|
+
}
|
|
312
316
|
onTouch() {
|
|
313
317
|
const map = bindingMap.get(this.className)
|
|
314
318
|
for (const [propertyKey, value] of map) {
|
|
@@ -480,23 +484,20 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
480
484
|
}
|
|
481
485
|
|
|
482
486
|
function updateStatus(data: IBindingData, com: Component, value: any, self: any) {
|
|
483
|
-
if (value === undefined || value === null) {
|
|
484
|
-
return
|
|
485
|
-
}
|
|
486
487
|
const sx = data.dataPath.split('.').pop();
|
|
487
488
|
const tempData = { value: value, skip: false }
|
|
488
489
|
//console.log("updateStatus", data.propertyKey)
|
|
489
490
|
switch (data.type) {
|
|
490
491
|
case 'cc.Label':
|
|
491
492
|
if (data.reset) {
|
|
492
|
-
data.reset.call(self, value, com);
|
|
493
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
493
494
|
} else {
|
|
494
495
|
if (value != undefined && value !== null) (com as Label).string = value?.toString() || '';
|
|
495
496
|
}
|
|
496
497
|
break;
|
|
497
498
|
case 'cc.RichText':
|
|
498
499
|
if (data.reset) {
|
|
499
|
-
data.reset.call(self, value, com);
|
|
500
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
500
501
|
} else
|
|
501
502
|
if (value != undefined && value !== null)
|
|
502
503
|
(com as RichText).string = value?.toString() || '';
|
|
@@ -505,7 +506,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
505
506
|
// 假设 value 是 SpriteFrame 路径或资源
|
|
506
507
|
// 需要额外处理资源加载逻辑
|
|
507
508
|
if (data.reset) {
|
|
508
|
-
data.reset.call(self, value, com);
|
|
509
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
509
510
|
} else
|
|
510
511
|
if (value != undefined && value !== null) {
|
|
511
512
|
if (value instanceof SpriteFrame)
|
|
@@ -522,19 +523,19 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
522
523
|
case 'cc.Button':
|
|
523
524
|
const com_btn = (com as Button);
|
|
524
525
|
if (data.reset) {
|
|
525
|
-
data.reset.call(self, value, com);
|
|
526
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
526
527
|
} else
|
|
527
|
-
com_btn.node.active = value ?? true;
|
|
528
|
+
if (value !== undefined || value !== null) com_btn.node.active = value ?? true;
|
|
528
529
|
break;
|
|
529
530
|
case 'cc.ProgressBar':
|
|
530
531
|
if (data.reset) {
|
|
531
|
-
data.reset.call(self, value, com);
|
|
532
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
532
533
|
} else
|
|
533
534
|
if (value != undefined && value !== null) (com as ProgressBar).progress = Number(value) || 0;
|
|
534
535
|
break;
|
|
535
536
|
case 'sp.Skeleton':
|
|
536
537
|
if (data.reset) {
|
|
537
|
-
data.reset.call(self, value, com);
|
|
538
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
538
539
|
} else
|
|
539
540
|
if (value != undefined && value !== null)
|
|
540
541
|
if (value instanceof sp.SkeletonData)
|
|
@@ -557,7 +558,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
557
558
|
{
|
|
558
559
|
const com_sld = (com as Slider);
|
|
559
560
|
if (data.reset) {
|
|
560
|
-
data.reset.call(self, value, com);
|
|
561
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
561
562
|
} else
|
|
562
563
|
if (value != undefined && value !== null) com_sld.progress = Number(value) || 0;
|
|
563
564
|
}
|
|
@@ -566,7 +567,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
566
567
|
{
|
|
567
568
|
const com_tg = (com as Toggle);
|
|
568
569
|
if (data.reset) {
|
|
569
|
-
data.reset.call(self, value, com);
|
|
570
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
570
571
|
} else
|
|
571
572
|
if (value != undefined && value !== null) com_tg.isChecked = Boolean(value);
|
|
572
573
|
}
|
|
@@ -575,7 +576,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
575
576
|
{
|
|
576
577
|
const com_eb = (com as EditBox);
|
|
577
578
|
if (data.reset) {
|
|
578
|
-
data.reset.call(self, value, com);
|
|
579
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
579
580
|
} else
|
|
580
581
|
if (value != undefined && value !== null) com_eb.string = value?.toString() || '';
|
|
581
582
|
}
|
|
@@ -584,7 +585,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
584
585
|
{
|
|
585
586
|
const com_tgc = (com as ToggleContainer);
|
|
586
587
|
if (data.reset) {
|
|
587
|
-
data.reset.call(self, value, com);
|
|
588
|
+
if (value !== undefined || value !== null) data.reset.call(self, value, com);
|
|
588
589
|
}
|
|
589
590
|
//事件
|
|
590
591
|
if (com_tgc.checkEvents.length <= 0) {
|