@byteluck-fe/model-driven-engine 1.5.0-beta.7 → 1.8.0-beta.0

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.
@@ -30,9 +30,10 @@ var Store = /*#__PURE__*/ function() {
30
30
  "use strict";
31
31
  function Store(props) {
32
32
  _classCallCheck(this, Store);
33
- var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping;
33
+ var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping, fieldCodeState = ref.fieldCodeState;
34
34
  this.emptyState = emptyState;
35
35
  this.state = state;
36
+ this.fieldCodeState = fieldCodeState;
36
37
  this.dataBindMapping = databindMapping;
37
38
  this.controlIdMapping = controlidMapping;
38
39
  }
@@ -123,6 +124,25 @@ var Store = /*#__PURE__*/ function() {
123
124
  }
124
125
  }
125
126
  };
127
+ _proto.getFieldCodeState = function getFieldCodeState(controlId) {
128
+ //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
129
+ // const controlInfo = this.controlIdMapping[controlId]
130
+ var detection = this.fieldCodeState[controlId];
131
+ if (detection !== undefined) {
132
+ return this.fieldCodeState[controlId];
133
+ } else {
134
+ var controlInfo = this.controlIdMapping[controlId];
135
+ var dataCode = controlInfo.dataBind.dataCode;
136
+ if (controlInfo !== undefined) {
137
+ if (controlInfo.dataView === controlId) {
138
+ return this.fieldCodeState[controlId];
139
+ } else {
140
+ var dataCode1 = controlInfo.dataBind.dataCode;
141
+ return this.fieldCodeState[controlInfo.dataView][dataCode1] || this.fieldCodeState[controlInfo.dataView];
142
+ }
143
+ }
144
+ }
145
+ };
126
146
  _proto.getEmptyState = function getEmptyState(controlId) {
127
147
  var _this = this;
128
148
  var detection = this.emptyState[controlId];
@@ -173,6 +193,8 @@ var Store = /*#__PURE__*/ function() {
173
193
  function init(instance) {
174
194
  var state = {};
175
195
  var emptyState = {};
196
+ var fieldCodeState = {};
197
+ var fieldCodeEmptyState = {};
176
198
  var databindMapping = {};
177
199
  var controlidMapping = {};
178
200
  // loopFormControl(instance, (item, children) => {
@@ -182,39 +204,76 @@ function init(instance) {
182
204
  var dvId = dataView.id;
183
205
  var dataViewState = {};
184
206
  var emptyDataViewState = {};
207
+ var dataViewFieldCodeState = {};
208
+ var emptyDataViewFieldCodeState = {};
185
209
  // @ts-ignore
186
210
  loopFormControl([
187
211
  dataView
188
212
  ], function(item, children) {
189
- buildState(dataViewState, emptyDataViewState, item);
213
+ buildState(dataViewState, emptyDataViewState, dataViewFieldCodeState, emptyDataViewFieldCodeState, item);
190
214
  buildDataBindMapping(databindMapping, dvId, item);
191
215
  buildControlIdMapping(controlidMapping, dvId, item);
192
216
  });
193
217
  state[dvId] = dataViewState;
194
218
  emptyState[dvId] = emptyDataViewState;
219
+ fieldCodeState[dvId] = dataViewFieldCodeState;
220
+ fieldCodeEmptyState[dvId] = emptyDataViewFieldCodeState;
195
221
  });
196
222
  return {
197
223
  state: state,
198
224
  emptyState: emptyState,
199
225
  databindMapping: databindMapping,
200
- controlidMapping: controlidMapping
226
+ controlidMapping: controlidMapping,
227
+ fieldCodeState: fieldCodeState,
228
+ fieldCodeEmptyState: fieldCodeEmptyState
201
229
  };
202
230
  }
203
- function buildState(dataViewState, emptyDataViewState, // @ts-ignore
231
+ function buildState(dataViewState, emptyDataViewState, dataViewFieldCodeState, emptyDataViewFieldCodeState, // @ts-ignore
204
232
  item) {
205
233
  if (_instanceof(item, RuntimeFormControl)) {
206
234
  dataViewState[item.id] = JSONCopy(item.props.defaultValue);
207
235
  emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
236
+ if (_instanceof(item.props.dataBind, ObjectDataBind)) {
237
+ // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
238
+ Object.keys(item.props.dataBind).forEach(function(key) {
239
+ var dataBind = item.props.dataBind;
240
+ var defaultValue = item.props.defaultValue;
241
+ var dataBindFieldCode = dataBind[key].fieldCode;
242
+ dataViewFieldCodeState[dataBindFieldCode] = JSONCopy(defaultValue[key]);
243
+ emptyDataViewFieldCodeState[dataBindFieldCode] = JSONCopy(defaultValue[key]);
244
+ });
245
+ } else {
246
+ var dataBindFieldCode = item.props.dataBind.fieldCode;
247
+ dataViewFieldCodeState[dataBindFieldCode] = JSONCopy(item.props.defaultValue);
248
+ emptyDataViewFieldCodeState[dataBindFieldCode] = JSONCopy(item.props.defaultValue);
249
+ }
208
250
  } else {
209
251
  var emptyTemplate = {};
252
+ var emptyFieldCodeTemplate = {};
210
253
  loopFormSchema(item.props.headers, function(headerItem) {
211
254
  emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
255
+ // 处理成fieldCode
256
+ var headerItemFieldCode = headerItem.props.dataBind.fieldCode;
257
+ if (_instanceof(headerItem.props.dataBind, ObjectDataBind)) {
258
+ // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
259
+ Object.keys(headerItem.props.dataBind).forEach(function(key) {
260
+ emptyFieldCodeTemplate[headerItem.props.dataBind[key].fieldCode] = JSONCopy(headerItem.props.defaultValue[key]);
261
+ });
262
+ } else {
263
+ emptyFieldCodeTemplate[headerItemFieldCode] = JSONCopy(headerItem.props.defaultValue);
264
+ }
212
265
  });
213
266
  var _defaultRows;
214
267
  dataViewState[item.id] = new Array((_defaultRows = item.props.defaultRows) !== null && _defaultRows !== void 0 ? _defaultRows : 1).fill(0).map(function() {
215
268
  return JSONCopy(emptyTemplate);
216
269
  });
217
270
  emptyDataViewState[item.id] = emptyTemplate;
271
+ var dataBindFieldCode1 = item.props.datasourceBind.dataCode;
272
+ var _defaultRows1;
273
+ dataViewFieldCodeState[dataBindFieldCode1] = new Array((_defaultRows1 = item.props.defaultRows) !== null && _defaultRows1 !== void 0 ? _defaultRows1 : 1).fill(0).map(function() {
274
+ return JSONCopy(emptyFieldCodeTemplate);
275
+ });
276
+ emptyDataViewFieldCodeState[dataBindFieldCode1] = emptyFieldCodeTemplate;
218
277
  }
219
278
  }
220
279
  function buildDataBindMapping(data, dataViewId, // @ts-ignore
@@ -38,7 +38,7 @@ var proxyArrayApi = [
38
38
  "shift",
39
39
  "pop",
40
40
  "unshift",
41
- "reverse",
41
+ "reverse"
42
42
  ];
43
43
  export var engineProxyFlag = Symbol("__engineProxy__");
44
44
  export var engineTargetKey = Symbol("__engineTarget__");
@@ -85,7 +85,7 @@ function ArrayHandler(target, propertyKey, value, thisKey, callback) {
85
85
  return function() {
86
86
  return callback.call(null, target, thisKey, "splice", [
87
87
  newLength,
88
- oldLength - newLength,
88
+ oldLength - newLength
89
89
  ]);
90
90
  };
91
91
  // 直接操作下标
@@ -29,6 +29,7 @@ function _unsupportedIterableToArray(o, minLen) {
29
29
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
30
30
  }
31
31
  import { CONTROL_TYPE, CALC_TOKEN_TYPE, CALC_AGGREGATE_TYPE } from "@byteluck-fe/model-driven-shared";
32
+ import { format } from "mathjs";
32
33
  var DisplayType;
33
34
  (function(DisplayType) {
34
35
  DisplayType[/**
@@ -331,7 +332,10 @@ export var CalcPlugin = /*#__PURE__*/ function() {
331
332
  if (this.cacheComputedResult[scriptText] !== undefined) {
332
333
  value = this.cacheComputedResult[scriptText];
333
334
  } else {
334
- value = new Function("return ".concat(scriptText))();
335
+ // 解决js精准度问题
336
+ value = Number(format(new Function("return ".concat(scriptText))(), {
337
+ precision: 16
338
+ }));
335
339
  this.cacheComputedResult[scriptText] = value;
336
340
  }
337
341
  var rowIndex = undefined;
@@ -32,7 +32,101 @@ function _classCallCheck(instance, Constructor) {
32
32
  throw new TypeError("Cannot call a class as a function");
33
33
  }
34
34
  }
35
- import regeneratorRuntime from "regenerator-runtime";
35
+ var __generator = this && this.__generator || function(thisArg, body) {
36
+ var f, y, t, g, _ = {
37
+ label: 0,
38
+ sent: function() {
39
+ if (t[0] & 1) throw t[1];
40
+ return t[1];
41
+ },
42
+ trys: [],
43
+ ops: []
44
+ };
45
+ return(g = {
46
+ next: verb(0),
47
+ "throw": verb(1),
48
+ "return": verb(2)
49
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
50
+ return this;
51
+ }), g);
52
+ function verb(n) {
53
+ return function(v) {
54
+ return step([
55
+ n,
56
+ v
57
+ ]);
58
+ };
59
+ }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while(_)try {
63
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
64
+ if (y = 0, t) op = [
65
+ op[0] & 2,
66
+ t.value
67
+ ];
68
+ switch(op[0]){
69
+ case 0:
70
+ case 1:
71
+ t = op;
72
+ break;
73
+ case 4:
74
+ _.label++;
75
+ return {
76
+ value: op[1],
77
+ done: false
78
+ };
79
+ case 5:
80
+ _.label++;
81
+ y = op[1];
82
+ op = [
83
+ 0
84
+ ];
85
+ continue;
86
+ case 7:
87
+ op = _.ops.pop();
88
+ _.trys.pop();
89
+ continue;
90
+ default:
91
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
+ _ = 0;
93
+ continue;
94
+ }
95
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
+ _.label = op[1];
97
+ break;
98
+ }
99
+ if (op[0] === 6 && _.label < t[1]) {
100
+ _.label = t[1];
101
+ t = op;
102
+ break;
103
+ }
104
+ if (t && _.label < t[2]) {
105
+ _.label = t[2];
106
+ _.ops.push(op);
107
+ break;
108
+ }
109
+ if (t[2]) _.ops.pop();
110
+ _.trys.pop();
111
+ continue;
112
+ }
113
+ op = body.call(thisArg, _);
114
+ } catch (e) {
115
+ op = [
116
+ 6,
117
+ e
118
+ ];
119
+ y = 0;
120
+ } finally{
121
+ f = t = 0;
122
+ }
123
+ if (op[0] & 5) throw op[1];
124
+ return {
125
+ value: op[0] ? op[1] : void 0,
126
+ done: true
127
+ };
128
+ }
129
+ };
36
130
  import { EventLogic } from "@byteluck-fe/model-driven-shared";
37
131
  // type EventKeyMap = {
38
132
  // [eventKey in EventKeys]?: string
@@ -80,30 +174,36 @@ export var ControlsEventPlugin = /*#__PURE__*/ function() {
80
174
  _proto.engineAddEventListener = function engineAddEventListener(eventKey, controlEventKey) {
81
175
  var _this = this;
82
176
  this.engine.on(eventKey, function() {
83
- var _ref = _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee(payload) {
84
- return regeneratorRuntime.wrap(function _callee$(_ctx) {
85
- while(1)switch(_ctx.prev = _ctx.next){
177
+ var _ref = _asyncToGenerator(function(payload) {
178
+ return __generator(this, function(_state) {
179
+ switch(_state.label){
86
180
  case 0:
87
- if (!(eventKey === "change" && !_this.engine.isMounted)) {
88
- _ctx.next = 2;
89
- break;
181
+ // 初始化state的时候不触发change事件,必须在engine mounted以后才触发
182
+ if (eventKey === "change" && !_this.engine.isMounted) {
183
+ return [
184
+ 2
185
+ ];
90
186
  }
91
- return _ctx.abrupt("return");
187
+ if (!(payload.instance !== undefined)) return [
188
+ 3,
189
+ 2
190
+ ];
191
+ return [
192
+ 4,
193
+ _this.callControlEvent(controlEventKey, payload)
194
+ ];
195
+ case 1:
196
+ return [
197
+ 2,
198
+ _state.sent()
199
+ ];
92
200
  case 2:
93
- if (!(payload.instance !== undefined)) {
94
- _ctx.next = 6;
95
- break;
96
- }
97
- _ctx.next = 5;
98
- return _this.callControlEvent(controlEventKey, payload);
99
- case 5:
100
- return _ctx.abrupt("return", _ctx.sent);
101
- case 6:
102
- case "end":
103
- return _ctx.stop();
201
+ return [
202
+ 2
203
+ ];
104
204
  }
105
- }, _callee);
106
- }));
205
+ });
206
+ });
107
207
  return function(payload) {
108
208
  return _ref.apply(this, arguments);
109
209
  };
@@ -111,58 +211,66 @@ export var ControlsEventPlugin = /*#__PURE__*/ function() {
111
211
  };
112
212
  _proto.callControlEvent = function callControlEvent(name, payload) {
113
213
  var _this = this;
114
- return _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
214
+ return _asyncToGenerator(function() {
115
215
  var events, result;
116
- return regeneratorRuntime.wrap(function _callee$(_ctx) {
117
- while(1)switch(_ctx.prev = _ctx.next){
216
+ return __generator(this, function(_state) {
217
+ switch(_state.label){
118
218
  case 0:
119
219
  events = _this.config[payload.instance.id];
120
- if (!(!events || !Array.isArray(events[name]))) {
121
- _ctx.next = 3;
122
- break;
220
+ if (!events || !Array.isArray(events[name])) {
221
+ return [
222
+ 2,
223
+ []
224
+ ];
123
225
  }
124
- return _ctx.abrupt("return", []);
125
- case 3:
126
- _ctx.next = 5;
127
- return Promise.all(events[name].map(function() {
128
- var _ref = _asyncToGenerator(/*#__PURE__*/ regeneratorRuntime.mark(function _callee(eventName) {
129
- var execResult;
130
- return regeneratorRuntime.wrap(function _callee$(_ctx) {
131
- while(1)switch(_ctx.prev = _ctx.next){
132
- case 0:
133
- _ctx.next = 2;
134
- return _this.engine.getAction().execAction(eventName, //qiyu 注释掉的两个参数变为全局参数
135
- // this.engine,
136
- // this.engine.getAction().actionUtils, //以前是params,空的
137
- payload);
138
- case 2:
139
- execResult = _ctx.sent;
140
- return _ctx.abrupt("return", execResult);
141
- case 4:
142
- case "end":
143
- return _ctx.stop();
144
- }
145
- }, _callee);
146
- }));
147
- return function(eventName) {
148
- return _ref.apply(this, arguments);
149
- };
150
- }()));
151
- case 5:
152
- result = _ctx.sent;
153
- if (!result.includes(false)) {
154
- _ctx.next = 10;
155
- break;
226
+ return [
227
+ 4,
228
+ Promise.all(events[name].map(function() {
229
+ var _ref = _asyncToGenerator(function(eventName) {
230
+ var execResult;
231
+ return __generator(this, function(_state) {
232
+ switch(_state.label){
233
+ case 0:
234
+ return [
235
+ 4,
236
+ _this.engine.getAction().execAction(eventName, //qiyu 注释掉的两个参数变为全局参数
237
+ // this.engine,
238
+ // this.engine.getAction().actionUtils, //以前是params,空的
239
+ payload)
240
+ ];
241
+ case 1:
242
+ execResult = _state.sent();
243
+ return [
244
+ 2,
245
+ execResult
246
+ ];
247
+ }
248
+ });
249
+ });
250
+ return function(eventName) {
251
+ return _ref.apply(this, arguments);
252
+ };
253
+ }()))
254
+ ];
255
+ case 1:
256
+ result = _state.sent();
257
+ if (result.includes(false)) {
258
+ return [
259
+ 2,
260
+ false
261
+ ];
262
+ } else {
263
+ return [
264
+ 2,
265
+ result
266
+ ];
156
267
  }
157
- return _ctx.abrupt("return", false);
158
- case 10:
159
- return _ctx.abrupt("return", result);
160
- case 11:
161
- case "end":
162
- return _ctx.stop();
268
+ return [
269
+ 2
270
+ ];
163
271
  }
164
- }, _callee);
165
- }))();
272
+ });
273
+ })();
166
274
  };
167
275
  return ControlsEventPlugin;
168
276
  }();