@cc-component/cc-ex-component 2.0.3 → 2.0.5

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.
@@ -110,6 +110,8 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
110
110
 
111
111
  const self = this
112
112
  const map = bindingMap.get(className)
113
+ const childPromises: Promise<void>[] = []; // 👈 收集子组件的 Promise
114
+
113
115
  for (const [propertyKey, value] of map) {
114
116
  //属性绑定
115
117
  this.initReferenceCollector();
@@ -120,12 +122,16 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
120
122
  const classname = js.getClassName(com)
121
123
  value.type = classname
122
124
  //绑定自定义的继承BaseReference 的类的viewModel
125
+ // ✅ 关键:为每个 BaseReference 子组件创建 Promise
123
126
  if (com instanceof BaseReference) {
124
- const onLoadFinished = com.onLoadFinished;
127
+ let resolveFn: () => void;
128
+ childPromises.push(new Promise<void>((resolve) => { resolveFn = resolve; }));
129
+ const originalOnLoadFinished = com.onLoadFinished;
125
130
  com.onLoadFinished = function () {
126
- self.viewModel[propertyKey] = com.viewModel
127
- onLoadFinished.call(com);
128
- }
131
+ self.viewModel[propertyKey] = com.viewModel;
132
+ originalOnLoadFinished?.call(com);
133
+ resolveFn(); // 👈 子组件完成,resolve Promise
134
+ };
129
135
  }
130
136
  //console.log('属性绑定', propertyKey, value.type, com, this)
131
137
  // 记录绑定关系到实例
@@ -140,7 +146,14 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
140
146
 
141
147
  this.onLoadFinish();
142
148
  onLoad.call(this);
143
- this.onLoadFinished();
149
+ // ✅ 关键:等待所有子组件完成后,再执行父组件的 onLoadFinished
150
+ if (childPromises.length > 0) {
151
+ Promise.all(childPromises).then(() => { this.onLoadFinished(); });
152
+ } else {
153
+ // 如果没有子组件,直接执行
154
+ this.onLoadFinished();
155
+ }
156
+
144
157
  };
145
158
  };
146
159
 
@@ -182,7 +195,7 @@ export function BindFunc(path?: string) {
182
195
  bindingMapFunc.get(className)!.set(propertyKey, funcName);
183
196
  };
184
197
  }
185
- /**绑定自定义viewModel */
198
+ /**绑定自定义界面的viewModel */
186
199
  export function BindData(viewName?: string) {
187
200
  return function (target: any, propertyKey: string) {
188
201
  const call = () => {
@@ -192,9 +205,9 @@ export function BindData(viewName?: string) {
192
205
  const viewClassName = viewName ? viewName : call()
193
206
  const className = target.constructor
194
207
  if (!bindingMapView.has(viewClassName)) { bindingMapView.set(viewClassName, { key: '', manager: null }); }
195
- bindingMapView.get(viewClassName)!.key = propertyKey
196
- bindingMapView.get(viewClassName)!.manager = className
197
-
208
+ const data = bindingMapView.get(viewClassName)
209
+ data.key = propertyKey
210
+ data.manager = className
198
211
  };
199
212
  }
200
213
 
@@ -283,6 +296,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
283
296
  const self = this as any;
284
297
  return new Proxy(obj, {
285
298
  get(target, key: string) {
299
+
286
300
  // ✅ 跳过 $ 开头的属性:直接返回原始值,不代理
287
301
  if (key.startsWith(skip)) {
288
302
  return target[key];
@@ -293,6 +307,12 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
293
307
  // console.log(`get ${pathPrefix}----${key}`);
294
308
  // return self._makeReactive(value, `${pathPrefix}.${key}`);
295
309
  // }
310
+
311
+ //绑定的方法
312
+ const funcName = bindingMapFunc.get(self.className)?.get(key)
313
+ if (funcName) {
314
+ return self[funcName]?.()
315
+ }
296
316
  return value;
297
317
  },
298
318
  set(target, key: string, value: any) {
@@ -420,7 +440,10 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
420
440
  }
421
441
 
422
442
  private refreshFuncName() {
423
- this.funcMap.forEach((value, key) => { this[key]?.(value) })
443
+ // console.error('刷新数据失败:', this.funcMap)
444
+ this.funcMap.forEach((value, key) => {
445
+ this[key]?.(value)
446
+ })
424
447
  }
425
448
 
426
449
  resetButtonScale(btn: Button) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-component/cc-ex-component",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "engine": ">=3.8.6",
5
5
  "description": "系统组件添加常用扩展方法",
6
6
  "main": "index.ts",