@byteluck-fe/model-driven-engine 2.7.0-alpha.2 → 2.7.0-alpha.20

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.
@@ -3,6 +3,20 @@ function _classCallCheck(instance, Constructor) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
5
5
  }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _createClass(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
6
20
  function _defineProperty(obj, key, value) {
7
21
  if (key in obj) {
8
22
  Object.defineProperty(obj, key, {
@@ -16,13 +30,6 @@ function _defineProperty(obj, key, value) {
16
30
  }
17
31
  return obj;
18
32
  }
19
- function _instanceof(left, right) {
20
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
21
- return !!right[Symbol.hasInstance](left);
22
- } else {
23
- return left instanceof right;
24
- }
25
- }
26
33
  function _objectSpread(target) {
27
34
  for(var i = 1; i < arguments.length; i++){
28
35
  var source = arguments[i] != null ? arguments[i] : {};
@@ -38,13 +45,19 @@ function _objectSpread(target) {
38
45
  }
39
46
  return target;
40
47
  }
41
- import { DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
48
+ import { DataBind, isDataBind } from "@byteluck-fe/model-driven-core";
42
49
  import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from "@byteluck-fe/model-driven-shared";
43
50
  import { loopDataViewControl, loopFormControl, buildUUID } from "../utils/runtimeUtils";
44
51
  var Store = /*#__PURE__*/ function() {
45
52
  "use strict";
46
53
  function Store(props) {
47
54
  _classCallCheck(this, Store);
55
+ _defineProperty(this, "emptyState", void 0);
56
+ _defineProperty(this, "state", void 0);
57
+ _defineProperty(this, "dataBindMapping", void 0 // 主要提供给二开使用
58
+ );
59
+ _defineProperty(this, "controlIdMapping", void 0);
60
+ _defineProperty(this, "defaultState", void 0);
48
61
  var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState;
49
62
  this.emptyState = emptyState;
50
63
  this.state = state;
@@ -52,145 +65,160 @@ var Store = /*#__PURE__*/ function() {
52
65
  this.controlIdMapping = controlidMapping;
53
66
  this.defaultState = defaultState;
54
67
  }
55
- var _proto = Store.prototype;
56
- /**
68
+ _createClass(Store, [
69
+ {
70
+ /**
57
71
  * 使用该方法仅改变数据,不会表单触发事件。明细表可全量赋值也可根据rowIndex进行单独设置
58
72
  * @param controlId 组件ID
59
73
  * @param value
60
- */ _proto.setState = function setState(controlId, value, rowIndex) {
61
- var _this = this;
62
- var controlInfo = this.controlIdMapping[controlId];
63
- if (controlInfo !== undefined) {
64
- //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
65
- this.state[controlInfo.dataView][controlId] = value;
66
- // if (
67
- // controlInfo.dataBind instanceof ObjectDataBind &&
68
- // isPlainObject(value)
69
- // ) {
70
- // Object.assign(this.state[controlInfo.dataView][controlId], value)
71
- // } else {
72
- // this.state[controlInfo.dataView][controlId] = value
73
- // }
74
- } else {
75
- if (rowIndex !== undefined) {
76
- //TODO 目前只找了一层明细表,没有递归 如果是添加uid
77
- Object.keys(this.controlIdMapping).map(function(subtableId) {
78
- var dataView = _this.controlIdMapping[subtableId].dataView;
79
- var children = _this.controlIdMapping[subtableId].children;
80
- if (children !== undefined) {
81
- Object.keys(children).map(function(childControlId) {
82
- if (childControlId === controlId) {
83
- _this.state[dataView][subtableId][rowIndex][controlId] = value;
74
+ */ key: "setState",
75
+ value: function setState(controlId, value, rowIndex) {
76
+ var _this = this;
77
+ var controlInfo = this.controlIdMapping[controlId];
78
+ if (controlInfo !== undefined) {
79
+ //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
80
+ this.state[controlInfo.dataView][controlId] = value;
81
+ // if (
82
+ // controlInfo.dataBind instanceof ObjectDataBind &&
83
+ // isPlainObject(value)
84
+ // ) {
85
+ // Object.assign(this.state[controlInfo.dataView][controlId], value)
86
+ // } else {
87
+ // this.state[controlInfo.dataView][controlId] = value
88
+ // }
89
+ } else {
90
+ if (rowIndex !== undefined) {
91
+ //TODO 目前只找了一层明细表,没有递归 如果是添加uid
92
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
93
+ var dataView = _this.controlIdMapping[subtableId].dataView;
94
+ var children = _this.controlIdMapping[subtableId].children;
95
+ if (children !== undefined) {
96
+ Object.keys(children).map(function(childControlId) {
97
+ if (childControlId === controlId) {
98
+ if (_this.state[dataView][subtableId][rowIndex]) {
99
+ _this.state[dataView][subtableId][rowIndex][controlId] = value;
100
+ }
101
+ }
102
+ });
84
103
  }
85
104
  });
105
+ } else {
106
+ //不存在的 controlId,直接被挂载到外部key
107
+ this.state[controlId] = value;
86
108
  }
87
- });
88
- } else {
89
- //不存在的 controlId,直接被挂载到外部key
90
- this.state[controlId] = value;
109
+ }
91
110
  }
92
- }
93
- };
94
- _proto.getState = function getState(controlId, rowIndex) {
95
- var _this = this;
96
- //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
97
- // const controlInfo = this.controlIdMapping[controlId]
98
- var detection = this.state[controlId];
99
- if (detection !== undefined) {
100
- return this.state[controlId];
101
- } else {
102
- var controlInfo = this.controlIdMapping[controlId];
103
- if (controlInfo !== undefined) {
104
- return this.state[controlInfo.dataView][controlId];
105
- } else {
106
- if (rowIndex !== undefined) {
107
- var state;
108
- //TODO 目前只找了一层明细表,没有递归
109
- Object.keys(this.controlIdMapping).map(function(subtableId) {
110
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
111
- var children = _this.controlIdMapping[subtableId].children;
112
- if (children !== undefined) {
113
- Object.keys(children).map(function(childControlId) {
114
- if (childControlId === controlId) {
115
- var _this_state_dataViewId_subtableId_rowIndex;
116
- state = (_this_state_dataViewId_subtableId_rowIndex = _this.state[dataViewId][subtableId][rowIndex]) === null || _this_state_dataViewId_subtableId_rowIndex === void 0 ? void 0 : _this_state_dataViewId_subtableId_rowIndex[controlId];
111
+ },
112
+ {
113
+ key: "getState",
114
+ value: function getState(controlId, rowIndex) {
115
+ var _this = this;
116
+ //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
117
+ // const controlInfo = this.controlIdMapping[controlId]
118
+ var detection = this.state[controlId];
119
+ if (detection !== undefined) {
120
+ return this.state[controlId];
121
+ } else {
122
+ var controlInfo = this.controlIdMapping[controlId];
123
+ if (controlInfo !== undefined) {
124
+ return this.state[controlInfo.dataView][controlId];
125
+ } else {
126
+ if (rowIndex !== undefined) {
127
+ var state;
128
+ //TODO 目前只找了一层明细表,没有递归
129
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
130
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
131
+ var children = _this.controlIdMapping[subtableId].children;
132
+ if (children !== undefined) {
133
+ Object.keys(children).map(function(childControlId) {
134
+ if (childControlId === controlId) {
135
+ var _this_state_dataViewId_subtableId_rowIndex;
136
+ state = (_this_state_dataViewId_subtableId_rowIndex = _this.state[dataViewId][subtableId][rowIndex]) === null || _this_state_dataViewId_subtableId_rowIndex === void 0 ? void 0 : _this_state_dataViewId_subtableId_rowIndex[controlId];
137
+ }
138
+ });
117
139
  }
118
140
  });
119
- }
120
- });
121
- return state;
122
- } else {
123
- var states = [];
124
- Object.keys(this.controlIdMapping).map(function(subtableId) {
125
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
126
- var children = _this.controlIdMapping[subtableId].children;
127
- if (children !== undefined) {
128
- Object.keys(children).map(function(childControlId) {
129
- if (childControlId === controlId) {
130
- _this.state[dataViewId][subtableId].map(function(item) {
131
- states.push(item[controlId]);
141
+ return state;
142
+ } else {
143
+ var states = [];
144
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
145
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
146
+ var children = _this.controlIdMapping[subtableId].children;
147
+ if (children !== undefined) {
148
+ Object.keys(children).map(function(childControlId) {
149
+ if (childControlId === controlId) {
150
+ _this.state[dataViewId][subtableId].map(function(item) {
151
+ states.push(item[controlId]);
152
+ });
153
+ }
132
154
  });
133
155
  }
134
156
  });
157
+ return states;
135
158
  }
136
- });
137
- return states;
159
+ }
138
160
  }
139
161
  }
140
- }
141
- };
142
- _proto.getEmptyState = function getEmptyState(controlId) {
143
- var _this = this;
144
- var detection = this.emptyState[controlId];
145
- if (detection !== undefined) {
146
- return this.emptyState[controlId];
147
- } else {
148
- var controlInfo = this.controlIdMapping[controlId];
149
- if (controlInfo !== undefined) {
150
- var state = this.emptyState[controlInfo.dataView][controlId];
151
- //判断找到的是否是明细表的控件
152
- if ("children" in controlInfo) {
153
- Object.assign(state, {
154
- uid: "new:" + buildUUID("uid")
155
- });
156
- }
157
- return state;
158
- } else {
159
- var state1;
160
- //TODO 目前只找了一层明细表,没有递归
161
- Object.keys(this.controlIdMapping).map(function(subtableId) {
162
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
163
- var children = _this.controlIdMapping[subtableId].children;
164
- if (children !== undefined) {
165
- Object.keys(children).map(function(childControlId) {
166
- if (childControlId === controlId) {
167
- state1 = _this.emptyState[dataViewId][subtableId][controlId];
162
+ },
163
+ {
164
+ key: "getEmptyState",
165
+ value: function getEmptyState(controlId) {
166
+ var _this = this;
167
+ var detection = this.emptyState[controlId];
168
+ if (detection !== undefined) {
169
+ return this.emptyState[controlId];
170
+ } else {
171
+ var controlInfo = this.controlIdMapping[controlId];
172
+ if (controlInfo !== undefined) {
173
+ var state = this.emptyState[controlInfo.dataView][controlId];
174
+ //判断找到的是否是明细表的控件
175
+ if ("children" in controlInfo) {
176
+ Object.assign(state, {
177
+ uid: "new:" + buildUUID("uid")
178
+ });
179
+ }
180
+ return state;
181
+ } else {
182
+ var state1;
183
+ //TODO 目前只找了一层明细表,没有递归
184
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
185
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
186
+ var children = _this.controlIdMapping[subtableId].children;
187
+ if (children !== undefined) {
188
+ Object.keys(children).map(function(childControlId) {
189
+ if (childControlId === controlId) {
190
+ state1 = _this.emptyState[dataViewId][subtableId][controlId];
191
+ }
192
+ });
168
193
  }
169
194
  });
195
+ return state1;
170
196
  }
171
- });
172
- return state1;
197
+ }
173
198
  }
174
- }
175
- };
176
- _proto.getDataBind = function getDataBind(controlId) {
177
- var result = this.controlIdMapping[controlId];
178
- if (result) {
179
- return result.dataBind;
180
- }
181
- wrapperFor: for(var id in this.controlIdMapping){
182
- var dataBindMapping = this.controlIdMapping[id];
183
- if (dataBindMapping.children) {
184
- for(var subId in dataBindMapping.children){
185
- if (subId === controlId) {
186
- result = dataBindMapping.children[subId];
187
- break wrapperFor;
199
+ },
200
+ {
201
+ key: "getDataBind",
202
+ value: function getDataBind(controlId) {
203
+ var result = this.controlIdMapping[controlId];
204
+ if (result) {
205
+ return result.dataBind;
206
+ }
207
+ wrapperFor: for(var id in this.controlIdMapping){
208
+ var dataBindMapping = this.controlIdMapping[id];
209
+ if (dataBindMapping.children) {
210
+ for(var subId in dataBindMapping.children){
211
+ if (subId === controlId) {
212
+ result = dataBindMapping.children[subId];
213
+ break wrapperFor;
214
+ }
215
+ }
188
216
  }
189
217
  }
218
+ return result === null || result === void 0 ? void 0 : result.dataBind;
190
219
  }
191
220
  }
192
- return result === null || result === void 0 ? void 0 : result.dataBind;
193
- };
221
+ ]);
194
222
  return Store;
195
223
  }();
196
224
  function init(instance) {
@@ -238,12 +266,12 @@ item) {
238
266
  loopFormSchema(item.props.headers, function(headerItem) {
239
267
  emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
240
268
  });
241
- var _item_props_defaultRows;
242
- dataViewState[item.id] = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
269
+ var _item_props_defaultRows, _fill_map;
270
+ dataViewState[item.id] = (_fill_map = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
243
271
  return _objectSpread({
244
272
  uid: "new:" + buildUUID("uid")
245
273
  }, JSONCopy(emptyTemplate));
246
- });
274
+ })) !== null && _fill_map !== void 0 ? _fill_map : [];
247
275
  emptyDataViewState[item.id] = emptyTemplate;
248
276
  }
249
277
  }
@@ -252,7 +280,8 @@ item) {
252
280
  // if (item instanceof RuntimeFormControl) {
253
281
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
254
282
  var _item_props, _item_props_dataBind;
255
- if (_instanceof(item.props.dataBind, ObjectDataBind)) {
283
+ // if (item.props.dataBind instanceof ObjectDataBind) {
284
+ if (!isDataBind(item.props.dataBind)) {
256
285
  // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
257
286
  Object.keys(item.props.dataBind).map(function(key) {
258
287
  var dataBind = item.props.dataBind;
@@ -307,7 +336,8 @@ item) {
307
336
  };
308
337
  var subtableId = item.id;
309
338
  loopFormSchema(item.props.headers, function(item) {
310
- if (_instanceof(item.props.dataBind, ObjectDataBind)) {
339
+ // if (item.props.dataBind instanceof ObjectDataBind) {
340
+ if (!isDataBind(item.props.dataBind)) {
311
341
  Object.keys(item.props.dataBind).map(function(key) {
312
342
  var dataBind = item.props.dataBind;
313
343
  var dataCode = dataBind[key].dataCode;