@cc-component/cc-ex-component 2.0.3 → 2.0.4
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 +22 -9
- package/package.json +1 -1
package/assets/core/ViewModel.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
|
196
|
-
|
|
197
|
-
|
|
208
|
+
const data = bindingMapView.get(viewClassName)
|
|
209
|
+
data.key = propertyKey
|
|
210
|
+
data.manager = className
|
|
198
211
|
};
|
|
199
212
|
}
|
|
200
213
|
|