@byteluck-fe/model-driven-engine 2.1.0-beta.1 → 2.1.0-beta.2
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.
|
@@ -431,7 +431,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
431
431
|
this.store.state = proxyState(this.store.state, this._proxyStateCallback.bind(this), this._proxyStateBeforeSetCallback.bind(this));
|
|
432
432
|
};
|
|
433
433
|
_proto._proxyStateBeforeSetCallback = function _proxyStateBeforeSetCallback(state, key, newValue, oldValue) {
|
|
434
|
-
var instance = findItem(this.runtime.flatInstances, key);
|
|
434
|
+
var instance = findItem(this.runtime.flatInstances, key, this.store, this.runtime);
|
|
435
435
|
// 找不到控件说明不是改动控件上的字段,直接通过
|
|
436
436
|
if (!instance) {
|
|
437
437
|
return newValue;
|
|
@@ -473,7 +473,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
473
473
|
}
|
|
474
474
|
};
|
|
475
475
|
_proto._handlerArrayUpdate = function _handlerArrayUpdate(state, key, type, args, result) {
|
|
476
|
-
var subtable = findItem(this.runtime.flatInstances, key);
|
|
476
|
+
var subtable = findItem(this.runtime.flatInstances, key, this.store, this.runtime);
|
|
477
477
|
if (!_instanceof(subtable, RuntimeListControl)) return;
|
|
478
478
|
// 新增多行方法
|
|
479
479
|
// JUTODO 这里已经直接删除了创建instance 的逻辑,或许以后连这个函数都不需要调用了
|
|
@@ -556,7 +556,7 @@ var Engine = /*#__PURE__*/ function(Watcher) {
|
|
|
556
556
|
}
|
|
557
557
|
};
|
|
558
558
|
_proto._handlerObjectUpdate = function _handlerObjectUpdate(state, key, value, oldValue) {
|
|
559
|
-
var instance = findItem(this.runtime.flatInstances, key);
|
|
559
|
+
var instance = findItem(this.runtime.flatInstances, key, this.store, this.runtime);
|
|
560
560
|
if (!instance) {
|
|
561
561
|
return;
|
|
562
562
|
}
|
|
@@ -30,8 +30,9 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
30
30
|
if (n === "Map" || n === "Set") return Array.from(n);
|
|
31
31
|
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
32
32
|
}
|
|
33
|
-
import { RuntimeFormControl } from "@byteluck-fe/model-driven-core";
|
|
34
|
-
import { error, logerror } from "@byteluck-fe/model-driven-shared";
|
|
33
|
+
import { RuntimeFormControl, RuntimeListControl } from "@byteluck-fe/model-driven-core";
|
|
34
|
+
import { error, log, logerror, warn } from "@byteluck-fe/model-driven-shared";
|
|
35
|
+
import { copyPropsFromControlInstance } from "./SubTableSpeedUp";
|
|
35
36
|
var proxyArrayApi = [
|
|
36
37
|
"splice",
|
|
37
38
|
"push",
|
|
@@ -217,14 +218,94 @@ function flatInstanceForChildren(controls) {
|
|
|
217
218
|
});
|
|
218
219
|
return result;
|
|
219
220
|
}
|
|
221
|
+
var findRowIndex = function(keys) {
|
|
222
|
+
return keys.find(isNumberString);
|
|
223
|
+
};
|
|
224
|
+
var isNumberString = function(item) {
|
|
225
|
+
return item === String(Number(item));
|
|
226
|
+
};
|
|
227
|
+
var isInSubtable = function(keys) {
|
|
228
|
+
return keys.some(isNumberString);
|
|
229
|
+
};
|
|
230
|
+
var findSubTableInstanceFromKeyPath = function(flatInstance, keys) {
|
|
231
|
+
if (keys.length < 2) {
|
|
232
|
+
warn("未找到 明细子表控件", keys);
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
236
|
+
try {
|
|
237
|
+
for(var _iterator = flatInstance[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
238
|
+
var instance = _step.value;
|
|
239
|
+
if (keys.includes(instance.id)) {
|
|
240
|
+
if (_instanceof(instance, RuntimeListControl)) {
|
|
241
|
+
return instance;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
warn("未找到 明细子表控件", keys);
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
} catch (err) {
|
|
248
|
+
_didIteratorError = true;
|
|
249
|
+
_iteratorError = err;
|
|
250
|
+
} finally{
|
|
251
|
+
try {
|
|
252
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
253
|
+
_iterator.return();
|
|
254
|
+
}
|
|
255
|
+
} finally{
|
|
256
|
+
if (_didIteratorError) {
|
|
257
|
+
throw _iteratorError;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
220
262
|
/**
|
|
221
263
|
* 在flatInstance中通过key查找出对应的instance
|
|
222
264
|
* @param flatInstance 拍平的instance数组
|
|
223
265
|
* @param key 操作的数据在state的key - 可以是深层次的 subtable.0.input等
|
|
224
|
-
* */ export function findItem(flatInstance, key) {
|
|
266
|
+
* */ export function findItem(flatInstance, key, store, runtime) {
|
|
225
267
|
if (key === "") return undefined;
|
|
226
268
|
var keys = key.split(".");
|
|
227
269
|
if (keys.length === 0) return undefined;
|
|
270
|
+
// 在明细子表里的,就直接给create 一个 instance,并从subtable instance上取得对应 目标的props 赋值上去
|
|
271
|
+
if (isInSubtable(keys)) {
|
|
272
|
+
console.log("findItem isInSubtable");
|
|
273
|
+
// 先找到 明细子表的instance
|
|
274
|
+
var subTableInstance = findSubTableInstanceFromKeyPath(flatInstance, keys);
|
|
275
|
+
if (!subTableInstance) {
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
// 再找到 明细子表的 state
|
|
279
|
+
var subTableState = store.getState(subTableInstance.id);
|
|
280
|
+
if (!subTableState) {
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
var rowIndex = Number(findRowIndex(keys));
|
|
284
|
+
if (!Number.isInteger(rowIndex)) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
// 最后找到 行 的state
|
|
288
|
+
var rowState = subTableState[rowIndex];
|
|
289
|
+
var rowUid = rowState.uid;
|
|
290
|
+
// 当 rowProps 中没有对应的 rowProps时候,进行copy
|
|
291
|
+
if (!subTableInstance.rowProps[rowUid]) {
|
|
292
|
+
var headerInstances = subTableInstance.props.headers.map(function(v) {
|
|
293
|
+
return v.children[0];
|
|
294
|
+
});
|
|
295
|
+
var columnId = keys[keys.length - 1];
|
|
296
|
+
var targetInstance = headerInstances.find(function(i) {
|
|
297
|
+
return i.id === columnId;
|
|
298
|
+
});
|
|
299
|
+
if (!targetInstance) {
|
|
300
|
+
return undefined;
|
|
301
|
+
}
|
|
302
|
+
log("\uD83C\uDF1F copy rowProps", subTableInstance.id, rowUid, columnId);
|
|
303
|
+
subTableInstance.rowProps[rowUid] = copyPropsFromControlInstance(targetInstance);
|
|
304
|
+
// @ts-ignore
|
|
305
|
+
var tempInstance = runtime.createControlInstance(targetInstance.type);
|
|
306
|
+
return tempInstance;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
228
309
|
var oneKey = keys[0];
|
|
229
310
|
var otherKeys = keys.slice(1);
|
|
230
311
|
var initInstance = flatInstance.find(function(item) {
|