form-driver 0.4.20 → 0.4.21
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/dist/m3.js +1 -1
- package/es/m3.js +1090 -878
- package/lib/m3.js +1090 -878
- package/package.json +1 -1
- package/src/framework/MUtil.tsx +145 -0
- package/src/types/MDateRangeType.ts +7 -7
- package/src/types/MDateTimeType.ts +6 -6
- package/src/ui/editor/basic/ARangePicker.tsx +41 -21
- package/types/framework/MUtil.d.ts +14 -0
- package/types/types/MDateRangeType.d.ts +2 -0
package/es/m3.js
CHANGED
|
@@ -177,6 +177,571 @@ function _createForOfIteratorHelperLoose$e(o, allowArrayLike) { var it = typeof
|
|
|
177
177
|
function _unsupportedIterableToArray$e(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$e(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$e(o, minLen); }
|
|
178
178
|
|
|
179
179
|
function _arrayLikeToArray$e(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
180
|
+
var defaultTheme = {
|
|
181
|
+
READABLE_UNKNOWN: "?",
|
|
182
|
+
READABLE_BLANK: "-",
|
|
183
|
+
READABLE_INVALID: "❓",
|
|
184
|
+
READABLE_ERROR: "❗",
|
|
185
|
+
themeName: "antMiddle"
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* 注册viewer,type,morph(viewer和type之间的关联)
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
var Assembly = /*#__PURE__*/function () {
|
|
192
|
+
var _proto = Assembly.prototype;
|
|
193
|
+
|
|
194
|
+
/** 根据定义返回View,返回nil表示没有可用的View */
|
|
195
|
+
_proto.getViewerOf = function getViewerOf(f, morph) {
|
|
196
|
+
if (f.editor && morph === "editor") {
|
|
197
|
+
if (_.isString(f.editor)) {
|
|
198
|
+
return _.get(this.viewers, f.editor);
|
|
199
|
+
} else {
|
|
200
|
+
return f.editor;
|
|
201
|
+
}
|
|
202
|
+
} else if (f.readable && morph === "readable") {
|
|
203
|
+
if (_.isString(f.readable)) {
|
|
204
|
+
return _.get(this.viewers, f.readable);
|
|
205
|
+
} else {
|
|
206
|
+
return f.readable;
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
var viewer = _.get(this.morph, morph + "." + f.type);
|
|
210
|
+
|
|
211
|
+
if (_.isString(viewer)) {
|
|
212
|
+
return _.get(this.viewers, viewer);
|
|
213
|
+
} else {
|
|
214
|
+
return viewer;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
_proto.validate = function validate(s, v, path) {
|
|
220
|
+
if (path === void 0) {
|
|
221
|
+
path = "";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
var result = undefined;
|
|
225
|
+
|
|
226
|
+
for (var _iterator = _createForOfIteratorHelperLoose$e(this.types[s.type].validators), _step; !(_step = _iterator()).done;) {
|
|
227
|
+
var validator = _step.value;
|
|
228
|
+
result = validator(this, s, v, path);
|
|
229
|
+
|
|
230
|
+
if (result === "pass" && s.type !== "weight") {
|
|
231
|
+
return undefined;
|
|
232
|
+
} else if (typeof result === "object") {
|
|
233
|
+
MUtil.debug("校验", path, result.message);
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return undefined;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
_proto.addViewer = function addViewer(name, v) {
|
|
242
|
+
if (this.viewers[name]) {
|
|
243
|
+
console.error("addViewer: \u5DF2\u7ECF\u5B58\u5728\u540D\u4E3A " + name + " \u7684 Viewer\uFF0C\u65E0\u6CD5\u518D\u6B21\u6DFB\u52A0\uFF01");
|
|
244
|
+
return;
|
|
245
|
+
} else {
|
|
246
|
+
this.viewers[name] = v;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
_proto.addEditor = function addEditor(name, v) {
|
|
251
|
+
if (this.editors[name]) {
|
|
252
|
+
console.error("addEditor: \u5DF2\u7ECF\u5B58\u5728\u540D\u4E3A " + name + " \u7684 Editor\uFF0C\u65E0\u6CD5\u518D\u6B21\u6DFB\u52A0\uFF01");
|
|
253
|
+
return;
|
|
254
|
+
} else {
|
|
255
|
+
this.editors[name] = v;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* 增加一种数据类型
|
|
260
|
+
* 例:
|
|
261
|
+
* const hpOrg = {name: "hpOrg", type: {validators: ..., toReadable: ...}, editor: HPOrgEditor, readable: "DivViewer"}
|
|
262
|
+
* addType(hpOrg)
|
|
263
|
+
* @param typeParam 类型的描述对象
|
|
264
|
+
*/
|
|
265
|
+
;
|
|
266
|
+
|
|
267
|
+
_proto.addType = function addType(typeParam) {
|
|
268
|
+
var name = typeParam.name,
|
|
269
|
+
type = typeParam.type,
|
|
270
|
+
editor = typeParam.editor,
|
|
271
|
+
_typeParam$readable = typeParam.readable,
|
|
272
|
+
readable = _typeParam$readable === void 0 ? "DivViewer" : _typeParam$readable;
|
|
273
|
+
this.types[name] = type;
|
|
274
|
+
|
|
275
|
+
_.set(this.morph, "editor." + name, editor);
|
|
276
|
+
|
|
277
|
+
_.set(this.morph, "readable." + name, readable);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function Assembly() {
|
|
281
|
+
var _this = this;
|
|
282
|
+
|
|
283
|
+
this.types = {};
|
|
284
|
+
this.viewers = {};
|
|
285
|
+
this.editors = {};
|
|
286
|
+
this.morph = {};
|
|
287
|
+
this.theme = defaultTheme;
|
|
288
|
+
|
|
289
|
+
this.toReadable = function (s, v, parent) {
|
|
290
|
+
var t = _this.types[s.type];
|
|
291
|
+
|
|
292
|
+
if (t) {
|
|
293
|
+
var _r;
|
|
294
|
+
|
|
295
|
+
var r;
|
|
296
|
+
|
|
297
|
+
if (_.isString(s.toReadable)) {
|
|
298
|
+
// eslint-disable-next-line no-new-func
|
|
299
|
+
r = new Function("_", "value", "theme", "const {READABLE_UNKNOWN, READABLE_BLANK, READABLE_INVALID, READABLE_ERROR} = theme; return " + s.toReadable)(_, v, _this.theme);
|
|
300
|
+
} else if (_.isFunction(s.toReadable)) {
|
|
301
|
+
r = s.toReadable(v, parent, _this);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
r = (_r = r) != null ? _r : t.toReadable(_this, s, v);
|
|
305
|
+
|
|
306
|
+
if (s.postfix) {
|
|
307
|
+
r += s.postfix;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return r;
|
|
311
|
+
} else {
|
|
312
|
+
return s.type + "类型无效";
|
|
313
|
+
}
|
|
314
|
+
}; // 校验types是否使用了无效的编辑器名字
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
for (var morphName in this.morph) {
|
|
318
|
+
for (var typeName in this.morph[morphName]) {
|
|
319
|
+
if (!this.types[typeName]) {
|
|
320
|
+
throw SyntaxError("\u7C7B\u578B" + typeName + "\u672A\u5B9A\u4E49");
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
var viewerName = this.morph[morphName][typeName];
|
|
324
|
+
|
|
325
|
+
if (!this.viewers[viewerName]) {
|
|
326
|
+
throw SyntaxError("\u89C6\u56FE" + viewerName + "\u672A\u5B9A\u4E49");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return Assembly;
|
|
333
|
+
}();
|
|
334
|
+
var assembly = new Assembly();
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* 非空校验,数据不能是null/undefined/""/NaN/[]
|
|
338
|
+
* 要在其他条件之前,以便required=false时短路掉nil的数据,否则后面的校验全都得处理nil
|
|
339
|
+
* @param a
|
|
340
|
+
* @param schema
|
|
341
|
+
* @param value
|
|
342
|
+
* @param path
|
|
343
|
+
* @returns
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
function validateRequired$1(a, schema, value, path) {
|
|
347
|
+
if (schema.required) {
|
|
348
|
+
if (_.isNil(value) || value === "" || _.isNaN(value) || _.isArray(value) && value.length == 0) {
|
|
349
|
+
return {
|
|
350
|
+
message: "您还没有填完这一项",
|
|
351
|
+
path: path
|
|
352
|
+
};
|
|
353
|
+
} // 凡是总有例外
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
if (schema.type === "set" && schema.openOption) {
|
|
357
|
+
if (value.length === 1 && !value[0]) {
|
|
358
|
+
return {
|
|
359
|
+
message: "您还没有填完这一项",
|
|
360
|
+
path: path
|
|
361
|
+
}; // 开放set,只勾了开放选项,没有填内容,也要算空
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
if (_.isNil(value)) {
|
|
366
|
+
return "pass";
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
/** 和validateRequired相同,但不短路 */
|
|
373
|
+
|
|
374
|
+
function validateRequiredNS(a, schema, value, path) {
|
|
375
|
+
var v = validateRequired$1(a, schema, value, path);
|
|
376
|
+
|
|
377
|
+
if (v === "pass") {
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
function validateDateMinMax(a, schema, value, path) {
|
|
382
|
+
if (schema.min) {
|
|
383
|
+
if (!value || value < schema.min) {
|
|
384
|
+
return {
|
|
385
|
+
message: "\u8BF7\u9009\u62E9" + schema.min + "\u4E4B\u540E\u7684\u65F6\u95F4",
|
|
386
|
+
path: path
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (schema.max) {
|
|
392
|
+
if (!value || value > schema.max) {
|
|
393
|
+
return {
|
|
394
|
+
message: "\u8BF7\u9009\u62E9" + schema.min + "\u4E4B\u524D\u7684\u65F6\u95F4",
|
|
395
|
+
path: path
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return undefined;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* 数组项数不超过[min, max]
|
|
404
|
+
* @param schema
|
|
405
|
+
* @param value 应该是个数组
|
|
406
|
+
*/
|
|
407
|
+
|
|
408
|
+
function validateArrayItemMinMax(a, schema, value, path) {
|
|
409
|
+
if (schema.min) {
|
|
410
|
+
if (!value || value.length < schema.min) {
|
|
411
|
+
return {
|
|
412
|
+
message: "\u81F3\u5C11\u9009\u62E9" + schema.min + "\u9879",
|
|
413
|
+
path: path
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (schema.max) {
|
|
419
|
+
if (!value || value.length > schema.max) {
|
|
420
|
+
return {
|
|
421
|
+
message: "\u6700\u591A\u9009\u62E9" + schema.max + "\u9879",
|
|
422
|
+
path: path
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return undefined;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* 字符串长度不超过[min, max]
|
|
431
|
+
* @param schema
|
|
432
|
+
* @param value 应该是个字符串
|
|
433
|
+
*/
|
|
434
|
+
|
|
435
|
+
function validateStringMinMax$1(a, schema, value, path) {
|
|
436
|
+
if (schema.min) {
|
|
437
|
+
if (!value || value.length < schema.min) {
|
|
438
|
+
return {
|
|
439
|
+
message: "\u81F3\u5C11" + schema.min + "\u4E2A\u5B57",
|
|
440
|
+
path: path
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (schema.max) {
|
|
446
|
+
if (value && value.length > schema.max) {
|
|
447
|
+
return {
|
|
448
|
+
message: "\u6700\u591A" + schema.max + "\u4E2A\u5B57",
|
|
449
|
+
path: path
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
return undefined;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* 数字不超过[min, max]
|
|
458
|
+
* @param schema
|
|
459
|
+
* @param value 应该是个数字
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
function validateNumberMinMax(a, schema, value, path) {
|
|
463
|
+
var temp = Number(value);
|
|
464
|
+
|
|
465
|
+
if (!_.isNil(schema.max)) {
|
|
466
|
+
if (!_.isFinite(temp) || temp > schema.max) {
|
|
467
|
+
return {
|
|
468
|
+
message: "\u6700\u591A" + schema.max,
|
|
469
|
+
path: path
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (!_.isNil(schema.min)) {
|
|
475
|
+
if (!_.isFinite(temp) || temp < schema.min) {
|
|
476
|
+
return {
|
|
477
|
+
message: "\u6700\u5C11" + schema.min,
|
|
478
|
+
path: path
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
function generateRegexValidate$1(regex, mismatchMsg) {
|
|
486
|
+
return function (a, schema, value, path) {
|
|
487
|
+
var asstr = _.toString(value);
|
|
488
|
+
|
|
489
|
+
if (!regex.test(asstr)) {
|
|
490
|
+
return {
|
|
491
|
+
message: mismatchMsg,
|
|
492
|
+
path: path
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return undefined;
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* 数据用Object.prototype.toString.call返回的类型是预期的
|
|
501
|
+
* 可以用Object.prototype.toString.call(<预期的类型>)来查看你想要的数据类型的expectType
|
|
502
|
+
* @param expectType 预期类型,例如:"[object Object]" "[object Null]" "[object Number]" "[object Date]" "[object Array]"
|
|
503
|
+
* @param mismatchMsg 如果不匹配,提示的错误信息
|
|
504
|
+
* @returns
|
|
505
|
+
*/
|
|
506
|
+
|
|
507
|
+
function generateJsPrototypeValidate(expectType, mismatchMsg) {
|
|
508
|
+
if (mismatchMsg === void 0) {
|
|
509
|
+
mismatchMsg = "数据有误,请重填此项";
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
return function (a, schema, value, path) {
|
|
513
|
+
if (Object.prototype.toString.call(value) == expectType) {
|
|
514
|
+
return undefined;
|
|
515
|
+
} else {
|
|
516
|
+
return {
|
|
517
|
+
message: mismatchMsg,
|
|
518
|
+
path: path
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
function generateSchemaValidate(valueSchema, mismatchMsg) {
|
|
524
|
+
return function (a, schema, value, path) {
|
|
525
|
+
var r = assembly.validate(valueSchema, value, "");
|
|
526
|
+
|
|
527
|
+
if (!r) {
|
|
528
|
+
return r;
|
|
529
|
+
} else {
|
|
530
|
+
return {
|
|
531
|
+
message: mismatchMsg != null ? mismatchMsg : r.message,
|
|
532
|
+
path: path
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
var Validator = {
|
|
538
|
+
validateRequired: validateRequired$1,
|
|
539
|
+
validateRequiredNS: validateRequiredNS,
|
|
540
|
+
validateDateMinMax: validateDateMinMax,
|
|
541
|
+
validateStringMinMax: validateStringMinMax$1,
|
|
542
|
+
validateNumberMinMax: validateNumberMinMax,
|
|
543
|
+
generateRegexValidate: generateRegexValidate$1
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
var EmtpyType = {
|
|
547
|
+
validators: [],
|
|
548
|
+
createDefaultValue: function createDefaultValue(assembly, s) {
|
|
549
|
+
if (s.defaultValue) {
|
|
550
|
+
return _.clone(s.defaultValue);
|
|
551
|
+
} else {
|
|
552
|
+
return undefined;
|
|
553
|
+
}
|
|
554
|
+
},
|
|
555
|
+
standardValue: function standardValue(assembly, s, v, strict) {
|
|
556
|
+
return v;
|
|
557
|
+
},
|
|
558
|
+
toReadable: function toReadable(assembly, s, vs) {
|
|
559
|
+
if (_.isNil(vs)) {
|
|
560
|
+
return assembly.theme.READABLE_BLANK;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return vs;
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
function createDefaultValue(assembly, s) {
|
|
567
|
+
if (s.defaultValue) {
|
|
568
|
+
return _.clone(s.defaultValue);
|
|
569
|
+
} else {
|
|
570
|
+
return undefined;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
var MDateTimeType = _.assign({}, EmtpyType, {
|
|
575
|
+
validators: [validateRequired$1, validateDateMinMax],
|
|
576
|
+
antConf: function antConf(schema) {
|
|
577
|
+
var _dataFormat, _dataFormat2, _dataFormat3, _dataFormat4, _dataFormat5, _dataFormat6, _dataFormat7, _dataFormat8;
|
|
578
|
+
|
|
579
|
+
var dataFormat = schema.dataFormat;
|
|
580
|
+
var readableFormat;
|
|
581
|
+
var mode;
|
|
582
|
+
var showTime = false;
|
|
583
|
+
|
|
584
|
+
switch (schema.type) {
|
|
585
|
+
case "year":
|
|
586
|
+
mode = "year";
|
|
587
|
+
dataFormat = (_dataFormat = dataFormat) != null ? _dataFormat : "YYYY";
|
|
588
|
+
readableFormat = "YYYY";
|
|
589
|
+
break;
|
|
590
|
+
|
|
591
|
+
case "yearMonth":
|
|
592
|
+
mode = "month";
|
|
593
|
+
dataFormat = (_dataFormat2 = dataFormat) != null ? _dataFormat2 : "YYYYMM";
|
|
594
|
+
readableFormat = "YYYY.MM";
|
|
595
|
+
break;
|
|
596
|
+
|
|
597
|
+
case "yearMonthDay":
|
|
598
|
+
mode = "date";
|
|
599
|
+
dataFormat = (_dataFormat3 = dataFormat) != null ? _dataFormat3 : "YYYYMMDD";
|
|
600
|
+
readableFormat = "YYYY.MM.DD";
|
|
601
|
+
break;
|
|
602
|
+
|
|
603
|
+
case "datetime":
|
|
604
|
+
mode = undefined;
|
|
605
|
+
dataFormat = (_dataFormat4 = dataFormat) != null ? _dataFormat4 : "x";
|
|
606
|
+
readableFormat = "YYYY.MM.DD HH:mm";
|
|
607
|
+
showTime = true;
|
|
608
|
+
break;
|
|
609
|
+
|
|
610
|
+
case "date":
|
|
611
|
+
switch (schema.datePrecision) {
|
|
612
|
+
case "year":
|
|
613
|
+
mode = "year";
|
|
614
|
+
dataFormat = (_dataFormat5 = dataFormat) != null ? _dataFormat5 : "YYYY";
|
|
615
|
+
readableFormat = "YYYY";
|
|
616
|
+
break;
|
|
617
|
+
|
|
618
|
+
case "month":
|
|
619
|
+
mode = "month";
|
|
620
|
+
dataFormat = (_dataFormat6 = dataFormat) != null ? _dataFormat6 : "YYYYMM";
|
|
621
|
+
readableFormat = "YYYY.MM";
|
|
622
|
+
break;
|
|
623
|
+
|
|
624
|
+
case "minute":
|
|
625
|
+
mode = undefined;
|
|
626
|
+
dataFormat = (_dataFormat7 = dataFormat) != null ? _dataFormat7 : "x";
|
|
627
|
+
readableFormat = "YYYY.MM.DD HH:mm";
|
|
628
|
+
showTime = true;
|
|
629
|
+
break;
|
|
630
|
+
|
|
631
|
+
default:
|
|
632
|
+
// "day" 或未指定
|
|
633
|
+
mode = "date";
|
|
634
|
+
dataFormat = (_dataFormat8 = dataFormat) != null ? _dataFormat8 : "YYYYMMDD";
|
|
635
|
+
readableFormat = "YYYY.MM.DD";
|
|
636
|
+
break;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
break;
|
|
640
|
+
// case "yearAndQuarter":
|
|
641
|
+
// case "yearAndWeek":
|
|
642
|
+
// return MUtil.error(`移动端不支持${this.props.schema.type}`, this.props.schema);
|
|
643
|
+
|
|
644
|
+
default:
|
|
645
|
+
return undefined;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return {
|
|
649
|
+
dataFormat: dataFormat,
|
|
650
|
+
readableFormat: readableFormat,
|
|
651
|
+
mode: mode,
|
|
652
|
+
showTime: showTime
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
toReadable: function toReadable(assembly, schema, v) {
|
|
656
|
+
if (_.isNil(v)) {
|
|
657
|
+
return assembly.theme.READABLE_BLANK;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
var c = MDateTimeType.antConf(schema);
|
|
661
|
+
|
|
662
|
+
if (!c) {
|
|
663
|
+
return assembly.theme.READABLE_INVALID;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
var asMoment = moment(v, c.dataFormat);
|
|
667
|
+
return asMoment.format(c.readableFormat);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
/** 根据 precision 获取可读格式 */
|
|
672
|
+
|
|
673
|
+
function getReadableFormat(precision, showTime) {
|
|
674
|
+
switch (precision) {
|
|
675
|
+
case "year":
|
|
676
|
+
return "YYYY";
|
|
677
|
+
|
|
678
|
+
case "month":
|
|
679
|
+
return "YYYY.MM";
|
|
680
|
+
|
|
681
|
+
case "minute":
|
|
682
|
+
return "YYYY.MM.DD HH:mm";
|
|
683
|
+
|
|
684
|
+
default:
|
|
685
|
+
return showTime ? "YYYY.MM.DD HH:mm:ss" : "YYYY.MM.DD";
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
function timeExpr(assembly, v, tillNow, readableFormat) {
|
|
690
|
+
if (tillNow) {
|
|
691
|
+
return "至今";
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
if (!v) {
|
|
695
|
+
return assembly.theme.READABLE_UNKNOWN;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
return moment(v, "x").format(readableFormat);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function timeRangeExpr(assembly, from, to, tillNow, readableFormat) {
|
|
702
|
+
if (readableFormat === void 0) {
|
|
703
|
+
readableFormat = "YYYY.MM.DD";
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
return timeExpr(assembly, from, false, readableFormat) + " - " + timeExpr(assembly, to, tillNow, readableFormat);
|
|
707
|
+
}
|
|
708
|
+
var MDateRangeType = _.assign({}, EmtpyType, {
|
|
709
|
+
validators: [validateRequired$1],
|
|
710
|
+
toReadable: function toReadable(assembly, s, vs) {
|
|
711
|
+
var _s$dateRange;
|
|
712
|
+
|
|
713
|
+
if (_.isNil(vs)) {
|
|
714
|
+
return assembly.theme.READABLE_BLANK;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (!_.isArray(vs)) {
|
|
718
|
+
return assembly.theme.READABLE_INVALID;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
var fmt = getReadableFormat(s.dateRangePrecision, (_s$dateRange = s.dateRange) == null ? void 0 : _s$dateRange.showTime);
|
|
722
|
+
return timeRangeExpr(assembly, vs[0], vs[1], vs[2], fmt);
|
|
723
|
+
},
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* 同toReadable,但数据无效时返回nil
|
|
727
|
+
*/
|
|
728
|
+
toReadableN: function toReadableN(assembly, s, vs) {
|
|
729
|
+
if (!_.isNil(vs) && _.isArray(vs)) {
|
|
730
|
+
var _s$dateRange2;
|
|
731
|
+
|
|
732
|
+
var fmt = getReadableFormat(s.dateRangePrecision, (_s$dateRange2 = s.dateRange) == null ? void 0 : _s$dateRange2.showTime);
|
|
733
|
+
return timeRangeExpr(assembly, vs[0], vs[1], vs[2], fmt);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
return undefined;
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
function _createForOfIteratorHelperLoose$d(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray$d(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
741
|
+
|
|
742
|
+
function _unsupportedIterableToArray$d(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$d(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$d(o, minLen); }
|
|
743
|
+
|
|
744
|
+
function _arrayLikeToArray$d(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
180
745
|
var next = Date.now() - 1617265950471; // /** 用来测量字符串长度 */
|
|
181
746
|
// let _messurer: HTMLCanvasElement|undefined;
|
|
182
747
|
|
|
@@ -343,12 +908,12 @@ var MUtil = {
|
|
|
343
908
|
|
|
344
909
|
var r = {};
|
|
345
910
|
|
|
346
|
-
for (var _iterator = _createForOfIteratorHelperLoose$
|
|
911
|
+
for (var _iterator = _createForOfIteratorHelperLoose$d((_spec$segments = spec.segments) != null ? _spec$segments : []), _step; !(_step = _iterator()).done;) {
|
|
347
912
|
var _spec$segments;
|
|
348
913
|
|
|
349
914
|
var s = _step.value;
|
|
350
915
|
|
|
351
|
-
for (var _iterator2 = _createForOfIteratorHelperLoose$
|
|
916
|
+
for (var _iterator2 = _createForOfIteratorHelperLoose$d((_s$fields = s.fields) != null ? _s$fields : []), _step2; !(_step2 = _iterator2()).done;) {
|
|
352
917
|
var _s$fields;
|
|
353
918
|
|
|
354
919
|
var f = _step2.value;
|
|
@@ -415,7 +980,7 @@ var MUtil = {
|
|
|
415
980
|
applyDefaultValue: function applyDefaultValue(schema, database, path) {
|
|
416
981
|
// FIXME 多测试下,type是object或其他简单类型的情况
|
|
417
982
|
if (schema.type === "object") {
|
|
418
|
-
for (var _iterator3 = _createForOfIteratorHelperLoose$
|
|
983
|
+
for (var _iterator3 = _createForOfIteratorHelperLoose$d((_schema$objectFields = schema.objectFields) != null ? _schema$objectFields : []), _step3; !(_step3 = _iterator3()).done;) {
|
|
419
984
|
var _schema$objectFields;
|
|
420
985
|
|
|
421
986
|
var f = _step3.value;
|
|
@@ -467,7 +1032,7 @@ var MUtil = {
|
|
|
467
1032
|
|
|
468
1033
|
var showIfScript = "let {" + l1fields.join(",") + "} = data || {};\nlet hide = {";
|
|
469
1034
|
|
|
470
|
-
for (var _iterator4 = _createForOfIteratorHelperLoose$
|
|
1035
|
+
for (var _iterator4 = _createForOfIteratorHelperLoose$d(objectFields), _step4; !(_step4 = _iterator4()).done;) {
|
|
471
1036
|
var f = _step4.value;
|
|
472
1037
|
|
|
473
1038
|
if (f.showIf) {
|
|
@@ -475,7 +1040,7 @@ var MUtil = {
|
|
|
475
1040
|
}
|
|
476
1041
|
}
|
|
477
1042
|
|
|
478
|
-
for (var _iterator5 = _createForOfIteratorHelperLoose$
|
|
1043
|
+
for (var _iterator5 = _createForOfIteratorHelperLoose$d((_uispec$segments = uispec == null ? void 0 : uispec.segments) != null ? _uispec$segments : []), _step5; !(_step5 = _iterator5()).done;) {
|
|
479
1044
|
var _uispec$segments;
|
|
480
1045
|
|
|
481
1046
|
var s = _step5.value;
|
|
@@ -487,7 +1052,7 @@ var MUtil = {
|
|
|
487
1052
|
|
|
488
1053
|
showIfScript += "}\n"; // 如果一个segment里的所有字段都隐藏,segment就要隐藏
|
|
489
1054
|
|
|
490
|
-
for (var _iterator6 = _createForOfIteratorHelperLoose$
|
|
1055
|
+
for (var _iterator6 = _createForOfIteratorHelperLoose$d((_uispec$segments2 = uispec == null ? void 0 : uispec.segments) != null ? _uispec$segments2 : []), _step6; !(_step6 = _iterator6()).done;) {
|
|
491
1056
|
var _uispec$segments2;
|
|
492
1057
|
|
|
493
1058
|
var _s = _step6.value;
|
|
@@ -556,7 +1121,7 @@ var MUtil = {
|
|
|
556
1121
|
var score = 0;
|
|
557
1122
|
var opts = MUtil.standardFields(f.setFields);
|
|
558
1123
|
|
|
559
|
-
for (var _iterator7 = _createForOfIteratorHelperLoose$
|
|
1124
|
+
for (var _iterator7 = _createForOfIteratorHelperLoose$d(opts), _step7; !(_step7 = _iterator7()).done;) {
|
|
560
1125
|
var s = _step7.value;
|
|
561
1126
|
|
|
562
1127
|
if (_.find(opts, {
|
|
@@ -611,7 +1176,7 @@ var MUtil = {
|
|
|
611
1176
|
|
|
612
1177
|
var prevSize = Object.keys(dep).length;
|
|
613
1178
|
|
|
614
|
-
for (var _iterator8 = _createForOfIteratorHelperLoose$
|
|
1179
|
+
for (var _iterator8 = _createForOfIteratorHelperLoose$d(newDepNames), _step8; !(_step8 = _iterator8()).done;) {
|
|
615
1180
|
var n = _step8.value;
|
|
616
1181
|
dep[n] = allFieldsIdx[n];
|
|
617
1182
|
delete ndep[n];
|
|
@@ -668,788 +1233,602 @@ var MUtil = {
|
|
|
668
1233
|
};
|
|
669
1234
|
}
|
|
670
1235
|
|
|
671
|
-
if (template === void 0) {
|
|
672
|
-
template = {};
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
switch (e.type) {
|
|
676
|
-
case "string":
|
|
677
|
-
if (e.enum) {
|
|
678
|
-
var _base$enumFields;
|
|
679
|
-
|
|
680
|
-
base.type = "enum";
|
|
681
|
-
base.enumFields = (_base$enumFields = base.enumFields) != null ? _base$enumFields : e.enum.map(function (v) {
|
|
682
|
-
return {
|
|
683
|
-
value: (v != null ? v : "").toString()
|
|
684
|
-
};
|
|
685
|
-
});
|
|
686
|
-
} else {
|
|
687
|
-
base.type = "string";
|
|
688
|
-
base.max = e.maxLength;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
break;
|
|
692
|
-
|
|
693
|
-
case "number":
|
|
694
|
-
case "integer":
|
|
695
|
-
base.type = "int";
|
|
696
|
-
break;
|
|
697
|
-
|
|
698
|
-
case "object":
|
|
699
|
-
base.type = "object";
|
|
700
|
-
base.objectFields = [];
|
|
701
|
-
base.uispec = {
|
|
702
|
-
type: "flowForm",
|
|
703
|
-
layout: MUtil.phoneLike() ? "vertical" : "horizontal",
|
|
704
|
-
comma: ":"
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
for (var key in e.properties) {
|
|
708
|
-
var jsmField = e.properties[key];
|
|
709
|
-
|
|
710
|
-
var m3Field = _.assign({}, template, {
|
|
711
|
-
name: key,
|
|
712
|
-
label: key,
|
|
713
|
-
type: "object"
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
if (!_.isBoolean(jsmField)) {
|
|
717
|
-
var _jsmField$title;
|
|
718
|
-
|
|
719
|
-
m3Field.label = (_jsmField$title = jsmField.title) != null ? _jsmField$title : key;
|
|
720
|
-
this.jsonSchema2MFieldSchema(jsmField, m3Field, template);
|
|
721
|
-
base.objectFields.push(m3Field);
|
|
722
|
-
} else {
|
|
723
|
-
m3Field.type = "不支持的json schema:object.properties的value是boolean";
|
|
724
|
-
base.objectFields.push();
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
break;
|
|
729
|
-
|
|
730
|
-
case "array":
|
|
731
|
-
base.type = "array";
|
|
732
|
-
base.arrayMember = {
|
|
733
|
-
label: "",
|
|
734
|
-
type: "array"
|
|
735
|
-
};
|
|
736
|
-
|
|
737
|
-
if (_.isArray(e.items)) {
|
|
738
|
-
base.arrayMember.type = "不支持的json schema:array.items是数组";
|
|
739
|
-
} else if (_.isBoolean(e.items)) {
|
|
740
|
-
base.arrayMember.type = "不支持的json schema:array.items是boolean";
|
|
741
|
-
} else if (e.items) {
|
|
742
|
-
this.jsonSchema2MFieldSchema(e.items, base, template);
|
|
743
|
-
} else {
|
|
744
|
-
base.arrayMember.type = "不支持的json schema:array.items是undefined";
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
break;
|
|
748
|
-
|
|
749
|
-
case "null":
|
|
750
|
-
case "any":
|
|
751
|
-
case "boolean":
|
|
752
|
-
default:
|
|
753
|
-
base.type = "不支持的json schema:array.items是" + e.type;
|
|
754
|
-
break;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
return base;
|
|
758
|
-
},
|
|
759
|
-
|
|
760
|
-
/**
|
|
761
|
-
* 修改一个对象里的key
|
|
762
|
-
* @param object 要修改的对象,
|
|
763
|
-
* @param renameTo
|
|
764
|
-
* @param removeNotExistKey 是否在结果里面去除renameTo里不存在的key
|
|
765
|
-
* @returns 返回一个改过key名字的新对象
|
|
766
|
-
*/
|
|
767
|
-
renameKey: function renameKey(object, renameTo, removeNotExistKey) {
|
|
768
|
-
if (removeNotExistKey === void 0) {
|
|
769
|
-
removeNotExistKey = false;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
var result = {};
|
|
773
|
-
|
|
774
|
-
for (var oldKey in object) {
|
|
775
|
-
var newKey = renameTo[oldKey];
|
|
776
|
-
|
|
777
|
-
if (!newKey) {
|
|
778
|
-
if (removeNotExistKey) {
|
|
779
|
-
continue;
|
|
780
|
-
} else {
|
|
781
|
-
newKey = oldKey;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
result[newKey] = object[oldKey];
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
return result;
|
|
789
|
-
},
|
|
790
|
-
|
|
791
|
-
/** 啥也不干的空回调 */
|
|
792
|
-
doNothing: function doNothing() {},
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
* 去掉arr中的undefined和null,拼出来一个json path
|
|
796
|
-
*/
|
|
797
|
-
jsonPath: function jsonPath() {
|
|
798
|
-
for (var _len2 = arguments.length, arr = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
799
|
-
arr[_key2] = arguments[_key2];
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return _.compact(arr).join(".");
|
|
803
|
-
},
|
|
804
|
-
|
|
805
|
-
/**
|
|
806
|
-
* 获取一个json path的父path。
|
|
807
|
-
* @param path 如果path是空的返回也是空的
|
|
808
|
-
*/
|
|
809
|
-
parentPath: function parentPath(path) {
|
|
810
|
-
var split = path.replace(/]/g, "").split(/[.\\[]/);
|
|
811
|
-
split.splice(-1, 1);
|
|
812
|
-
return split.join(".");
|
|
813
|
-
},
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* 校验一个schema
|
|
817
|
-
* @param s 要校验的schema
|
|
818
|
-
* @returns 空数组表示校验通过,否则返回校验错误信息
|
|
819
|
-
*/
|
|
820
|
-
validateSchema: function validateSchema(s, parentPath) {
|
|
821
|
-
var result = [];
|
|
822
|
-
|
|
823
|
-
var error = function error(msg) {
|
|
824
|
-
return result.push({
|
|
825
|
-
message: msg,
|
|
826
|
-
path: MUtil.jsonPath(parentPath, s.name)
|
|
827
|
-
});
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
var checkDup = function checkDup(a, msgIfFail) {
|
|
831
|
-
if (_.uniq(a).length !== a.length) {
|
|
832
|
-
error(msgIfFail);
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
|
|
836
|
-
var checkVL = function checkVL(fs) {
|
|
837
|
-
checkDup(fs.map(function (f) {
|
|
838
|
-
return f.value;
|
|
839
|
-
}), s.name + "值有重复");
|
|
840
|
-
checkDup(fs.map(function (f) {
|
|
841
|
-
return f.label;
|
|
842
|
-
}).filter(function (l) {
|
|
843
|
-
return l;
|
|
844
|
-
}), s.name + "文案有重复");
|
|
845
|
-
};
|
|
846
|
-
|
|
847
|
-
var stringOnlyEnum = function stringOnlyEnum(candidate) {
|
|
848
|
-
var ns = MUtil.standardFields(candidate).find(function (f) {
|
|
849
|
-
return !_.isString(f.value);
|
|
850
|
-
});
|
|
851
|
-
|
|
852
|
-
if (ns) {
|
|
853
|
-
error("暂不支持的选项数据类型:" + JSON.stringify(ns) + ": " + typeof ns);
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
|
|
857
|
-
if (s.type === "decoration") {
|
|
858
|
-
return [];
|
|
859
|
-
} else if (s.type === "enum") {
|
|
860
|
-
checkVL(MUtil.standardFields(s.enumFields));
|
|
861
|
-
} else if (s.type === "set") {
|
|
862
|
-
checkVL(MUtil.standardFields(s.setFields));
|
|
863
|
-
} else if (s.type === "matrix") {
|
|
864
|
-
stringOnlyEnum(s.matrix.x);
|
|
865
|
-
stringOnlyEnum(s.matrix.y);
|
|
866
|
-
} else if (s.type === "object") {
|
|
867
|
-
if (!s.objectFields) {
|
|
868
|
-
error("object类型未定义成员");
|
|
869
|
-
} else {
|
|
870
|
-
var _s$uispec;
|
|
871
|
-
|
|
872
|
-
checkDup(s.objectFields.filter(function (f) {
|
|
873
|
-
return f.type !== "decoration";
|
|
874
|
-
}).map(function (f) {
|
|
875
|
-
return f.name;
|
|
876
|
-
}), "字段名有重复");
|
|
1236
|
+
if (template === void 0) {
|
|
1237
|
+
template = {};
|
|
1238
|
+
}
|
|
877
1239
|
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1240
|
+
switch (e.type) {
|
|
1241
|
+
case "string":
|
|
1242
|
+
if (e.enum) {
|
|
1243
|
+
var _base$enumFields;
|
|
1244
|
+
|
|
1245
|
+
base.type = "enum";
|
|
1246
|
+
base.enumFields = (_base$enumFields = base.enumFields) != null ? _base$enumFields : e.enum.map(function (v) {
|
|
1247
|
+
return {
|
|
1248
|
+
value: (v != null ? v : "").toString()
|
|
1249
|
+
};
|
|
1250
|
+
});
|
|
1251
|
+
} else {
|
|
1252
|
+
base.type = "string";
|
|
1253
|
+
base.max = e.maxLength;
|
|
881
1254
|
}
|
|
882
1255
|
|
|
883
|
-
|
|
884
|
-
if (!s.uispec.segments) {
|
|
885
|
-
error("分段未定义");
|
|
886
|
-
} else {
|
|
887
|
-
checkDup(s.uispec.segments.map(function (f) {
|
|
888
|
-
return f.label;
|
|
889
|
-
}), "分段文案有重复");
|
|
1256
|
+
break;
|
|
890
1257
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1258
|
+
case "number":
|
|
1259
|
+
case "integer":
|
|
1260
|
+
base.type = "int";
|
|
1261
|
+
break;
|
|
894
1262
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1263
|
+
case "object":
|
|
1264
|
+
base.type = "object";
|
|
1265
|
+
base.objectFields = [];
|
|
1266
|
+
base.uispec = {
|
|
1267
|
+
type: "flowForm",
|
|
1268
|
+
layout: MUtil.phoneLike() ? "vertical" : "horizontal",
|
|
1269
|
+
comma: ":"
|
|
1270
|
+
};
|
|
900
1271
|
|
|
901
|
-
|
|
1272
|
+
for (var key in e.properties) {
|
|
1273
|
+
var jsmField = e.properties[key];
|
|
902
1274
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1275
|
+
var m3Field = _.assign({}, template, {
|
|
1276
|
+
name: key,
|
|
1277
|
+
label: key,
|
|
1278
|
+
type: "object"
|
|
1279
|
+
});
|
|
906
1280
|
|
|
907
|
-
|
|
1281
|
+
if (!_.isBoolean(jsmField)) {
|
|
1282
|
+
var _jsmField$title;
|
|
908
1283
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1284
|
+
m3Field.label = (_jsmField$title = jsmField.title) != null ? _jsmField$title : key;
|
|
1285
|
+
this.jsonSchema2MFieldSchema(jsmField, m3Field, template);
|
|
1286
|
+
base.objectFields.push(m3Field);
|
|
1287
|
+
} else {
|
|
1288
|
+
m3Field.type = "不支持的json schema:object.properties的value是boolean";
|
|
1289
|
+
base.objectFields.push();
|
|
912
1290
|
}
|
|
913
1291
|
}
|
|
914
|
-
}
|
|
915
|
-
}
|
|
916
1292
|
|
|
917
|
-
|
|
918
|
-
},
|
|
1293
|
+
break;
|
|
919
1294
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
applyToConstructor: function applyToConstructor(constructor, argArray) {
|
|
927
|
-
var args = [null].concat(argArray);
|
|
928
|
-
var factoryFunction = constructor.bind.apply(constructor, args);
|
|
929
|
-
return new factoryFunction();
|
|
930
|
-
},
|
|
1295
|
+
case "array":
|
|
1296
|
+
base.type = "array";
|
|
1297
|
+
base.arrayMember = {
|
|
1298
|
+
label: "",
|
|
1299
|
+
type: "array"
|
|
1300
|
+
};
|
|
931
1301
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
if (fallback === void 0) {
|
|
942
|
-
fallback = undefined;
|
|
943
|
-
}
|
|
1302
|
+
if (_.isArray(e.items)) {
|
|
1303
|
+
base.arrayMember.type = "不支持的json schema:array.items是数组";
|
|
1304
|
+
} else if (_.isBoolean(e.items)) {
|
|
1305
|
+
base.arrayMember.type = "不支持的json schema:array.items是boolean";
|
|
1306
|
+
} else if (e.items) {
|
|
1307
|
+
this.jsonSchema2MFieldSchema(e.items, base, template);
|
|
1308
|
+
} else {
|
|
1309
|
+
base.arrayMember.type = "不支持的json schema:array.items是undefined";
|
|
1310
|
+
}
|
|
944
1311
|
|
|
945
|
-
|
|
946
|
-
_this = undefined;
|
|
947
|
-
}
|
|
1312
|
+
break;
|
|
948
1313
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
} else {
|
|
956
|
-
return fallback;
|
|
1314
|
+
case "null":
|
|
1315
|
+
case "any":
|
|
1316
|
+
case "boolean":
|
|
1317
|
+
default:
|
|
1318
|
+
base.type = "不支持的json schema:array.items是" + e.type;
|
|
1319
|
+
break;
|
|
957
1320
|
}
|
|
1321
|
+
|
|
1322
|
+
return base;
|
|
958
1323
|
},
|
|
959
1324
|
|
|
960
1325
|
/**
|
|
961
|
-
*
|
|
962
|
-
* @param
|
|
1326
|
+
* 修改一个对象里的key
|
|
1327
|
+
* @param object 要修改的对象,
|
|
1328
|
+
* @param renameTo
|
|
1329
|
+
* @param removeNotExistKey 是否在结果里面去除renameTo里不存在的key
|
|
1330
|
+
* @returns 返回一个改过key名字的新对象
|
|
963
1331
|
*/
|
|
964
|
-
|
|
1332
|
+
renameKey: function renameKey(object, renameTo, removeNotExistKey) {
|
|
1333
|
+
if (removeNotExistKey === void 0) {
|
|
1334
|
+
removeNotExistKey = false;
|
|
1335
|
+
}
|
|
965
1336
|
|
|
966
|
-
var arrs = [].concat(window.location.search.split(/[?&]/), window.location.hash.split(/[#?&]/));
|
|
967
1337
|
var result = {};
|
|
968
|
-
arrs.forEach(function (item) {
|
|
969
|
-
var kv = item.split(/=/);
|
|
970
1338
|
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
}
|
|
974
|
-
});
|
|
975
|
-
return result;
|
|
976
|
-
},
|
|
977
|
-
|
|
978
|
-
/**
|
|
979
|
-
* 动态创建一个CSS样式
|
|
980
|
-
* @param css css内容,会被写进style标签里
|
|
981
|
-
* @param id <style>的id,可以没有。如果已经存在,会被覆盖掉。
|
|
982
|
-
*/
|
|
983
|
-
setCss: function setCss(css, id) {
|
|
984
|
-
var _document$getElementB;
|
|
1339
|
+
for (var oldKey in object) {
|
|
1340
|
+
var newKey = renameTo[oldKey];
|
|
985
1341
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1342
|
+
if (!newKey) {
|
|
1343
|
+
if (removeNotExistKey) {
|
|
1344
|
+
continue;
|
|
1345
|
+
} else {
|
|
1346
|
+
newKey = oldKey;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
992
1349
|
|
|
993
|
-
|
|
994
|
-
* escape数值
|
|
995
|
-
* @param str - 字符串
|
|
996
|
-
* @returns 会带上引号,类似"abc",str=nil时会返回""
|
|
997
|
-
*/
|
|
998
|
-
escapeCsv: function escapeCsv(str) {
|
|
999
|
-
if (!_.isString(str)) {
|
|
1000
|
-
str = _.toString(str);
|
|
1350
|
+
result[newKey] = object[oldKey];
|
|
1001
1351
|
}
|
|
1002
1352
|
|
|
1003
|
-
return
|
|
1353
|
+
return result;
|
|
1004
1354
|
},
|
|
1005
1355
|
|
|
1006
1356
|
/**
|
|
1007
|
-
*
|
|
1008
|
-
* @param
|
|
1009
|
-
* @param
|
|
1010
|
-
* @
|
|
1357
|
+
* 提交时将时间字段转换为可读格式
|
|
1358
|
+
* @param schema 表单 schema(type 为 object 的根 schema)
|
|
1359
|
+
* @param database 表单数据
|
|
1360
|
+
* @returns 深拷贝后转换过的数据
|
|
1011
1361
|
*/
|
|
1012
|
-
|
|
1013
|
-
if (
|
|
1014
|
-
return
|
|
1015
|
-
} else {
|
|
1016
|
-
return v1 === v2;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
var CompactArray = {
|
|
1021
|
-
indexOf: function indexOf(ca, d) {
|
|
1022
|
-
if (_.isNil(d) || _.isNil(ca)) {
|
|
1023
|
-
return -1;
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
if (_.isArray(ca)) {
|
|
1027
|
-
return ca.indexOf(d);
|
|
1028
|
-
} else {
|
|
1029
|
-
return ca === d ? 0 : -1;
|
|
1362
|
+
formatForExport: function formatForExport(schema, database) {
|
|
1363
|
+
if (_.isNil(database)) {
|
|
1364
|
+
return database;
|
|
1030
1365
|
}
|
|
1031
|
-
}
|
|
1032
|
-
};
|
|
1033
|
-
|
|
1034
|
-
function _createForOfIteratorHelperLoose$d(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray$d(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1035
|
-
|
|
1036
|
-
function _unsupportedIterableToArray$d(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$d(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$d(o, minLen); }
|
|
1037
1366
|
|
|
1038
|
-
|
|
1039
|
-
var defaultTheme = {
|
|
1040
|
-
READABLE_UNKNOWN: "?",
|
|
1041
|
-
READABLE_BLANK: "-",
|
|
1042
|
-
READABLE_INVALID: "❓",
|
|
1043
|
-
READABLE_ERROR: "❗",
|
|
1044
|
-
themeName: "antMiddle"
|
|
1045
|
-
};
|
|
1046
|
-
/**
|
|
1047
|
-
* 注册viewer,type,morph(viewer和type之间的关联)
|
|
1048
|
-
*/
|
|
1367
|
+
var result = _.cloneDeep(database);
|
|
1049
1368
|
|
|
1050
|
-
var
|
|
1051
|
-
var _proto = Assembly.prototype;
|
|
1369
|
+
var fields = schema.objectFields;
|
|
1052
1370
|
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
if (_.isString(f.editor)) {
|
|
1057
|
-
return _.get(this.viewers, f.editor);
|
|
1058
|
-
} else {
|
|
1059
|
-
return f.editor;
|
|
1060
|
-
}
|
|
1061
|
-
} else if (f.readable && morph === "readable") {
|
|
1062
|
-
if (_.isString(f.readable)) {
|
|
1063
|
-
return _.get(this.viewers, f.readable);
|
|
1064
|
-
} else {
|
|
1065
|
-
return f.readable;
|
|
1066
|
-
}
|
|
1067
|
-
} else {
|
|
1068
|
-
var viewer = _.get(this.morph, morph + "." + f.type);
|
|
1371
|
+
if (!fields) {
|
|
1372
|
+
return result;
|
|
1373
|
+
}
|
|
1069
1374
|
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1375
|
+
var _loop = function _loop() {
|
|
1376
|
+
var field = _step9.value;
|
|
1377
|
+
var value = result[field.name];
|
|
1378
|
+
|
|
1379
|
+
if (_.isNil(value)) {
|
|
1380
|
+
return "continue";
|
|
1074
1381
|
}
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
1382
|
|
|
1078
|
-
|
|
1079
|
-
if (path === void 0) {
|
|
1080
|
-
path = "";
|
|
1081
|
-
}
|
|
1383
|
+
var type = field.type; // 时间选择器
|
|
1082
1384
|
|
|
1083
|
-
|
|
1385
|
+
if (type === "year" || type === "yearMonth" || type === "yearMonthDay" || type === "datetime" || type === "date") {
|
|
1386
|
+
var antConf = MDateTimeType.antConf(field);
|
|
1084
1387
|
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
result = validator(this, s, v, path);
|
|
1388
|
+
if (antConf) {
|
|
1389
|
+
var m = moment(value, antConf.dataFormat);
|
|
1088
1390
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1391
|
+
if (m.isValid()) {
|
|
1392
|
+
result[field.name] = m.format(antConf.readableFormat);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
} // 时间范围选择器
|
|
1396
|
+
else if (type === "dateRange") {
|
|
1397
|
+
if (_.isArray(value)) {
|
|
1398
|
+
var _field$dateRange, _field$dataFormat;
|
|
1399
|
+
|
|
1400
|
+
var start = value[0],
|
|
1401
|
+
end = value[1],
|
|
1402
|
+
tillNow = value[2];
|
|
1403
|
+
var fmt = getReadableFormat(field.dateRangePrecision, (_field$dateRange = field.dateRange) == null ? void 0 : _field$dateRange.showTime);
|
|
1404
|
+
var dataFormat = (_field$dataFormat = field.dataFormat) != null ? _field$dataFormat : "x";
|
|
1405
|
+
var startStr = "";
|
|
1406
|
+
var endStr = "";
|
|
1407
|
+
|
|
1408
|
+
if (!_.isNil(start)) {
|
|
1409
|
+
var _m = moment(start, dataFormat);
|
|
1410
|
+
|
|
1411
|
+
startStr = _m.isValid() ? _m.format(fmt) : "";
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
if (tillNow) {
|
|
1415
|
+
endStr = "至今";
|
|
1416
|
+
} else if (!_.isNil(end)) {
|
|
1417
|
+
var _m2 = moment(end, dataFormat);
|
|
1418
|
+
|
|
1419
|
+
endStr = _m2.isValid() ? _m2.format(fmt) : "";
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
result[field.name] = startStr + " - " + endStr;
|
|
1423
|
+
}
|
|
1424
|
+
} // 嵌套 object
|
|
1425
|
+
else if (type === "object" && field.objectFields) {
|
|
1426
|
+
result[field.name] = MUtil.formatForExport(field, value);
|
|
1427
|
+
} // 嵌套 array
|
|
1428
|
+
else if (type === "array" && field.arrayMember && _.isArray(value)) {
|
|
1429
|
+
if (field.arrayMember.objectFields) {
|
|
1430
|
+
result[field.name] = value.map(function (item) {
|
|
1431
|
+
return MUtil.formatForExport(field.arrayMember, item);
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1094
1434
|
}
|
|
1095
|
-
}
|
|
1435
|
+
};
|
|
1096
1436
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1437
|
+
for (var _iterator9 = _createForOfIteratorHelperLoose$d(fields), _step9; !(_step9 = _iterator9()).done;) {
|
|
1438
|
+
var _ret = _loop();
|
|
1099
1439
|
|
|
1100
|
-
|
|
1101
|
-
if (this.viewers[name]) {
|
|
1102
|
-
console.error("addViewer: \u5DF2\u7ECF\u5B58\u5728\u540D\u4E3A " + name + " \u7684 Viewer\uFF0C\u65E0\u6CD5\u518D\u6B21\u6DFB\u52A0\uFF01");
|
|
1103
|
-
return;
|
|
1104
|
-
} else {
|
|
1105
|
-
this.viewers[name] = v;
|
|
1440
|
+
if (_ret === "continue") continue;
|
|
1106
1441
|
}
|
|
1107
|
-
};
|
|
1108
1442
|
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
return;
|
|
1113
|
-
} else {
|
|
1114
|
-
this.editors[name] = v;
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1443
|
+
return result;
|
|
1444
|
+
},
|
|
1445
|
+
|
|
1117
1446
|
/**
|
|
1118
|
-
*
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
*
|
|
1122
|
-
* @param typeParam 类型的描述对象
|
|
1447
|
+
* 回填时将可读格式的时间字段反解析为内部格式
|
|
1448
|
+
* @param schema 表单 schema(type 为 object 的根 schema)
|
|
1449
|
+
* @param database 可读格式的数据
|
|
1450
|
+
* @returns 深拷贝后反解析过的数据
|
|
1123
1451
|
*/
|
|
1124
|
-
|
|
1452
|
+
parseFromExport: function parseFromExport(schema, database) {
|
|
1453
|
+
if (_.isNil(database)) {
|
|
1454
|
+
return database;
|
|
1455
|
+
}
|
|
1125
1456
|
|
|
1126
|
-
|
|
1127
|
-
var name = typeParam.name,
|
|
1128
|
-
type = typeParam.type,
|
|
1129
|
-
editor = typeParam.editor,
|
|
1130
|
-
_typeParam$readable = typeParam.readable,
|
|
1131
|
-
readable = _typeParam$readable === void 0 ? "DivViewer" : _typeParam$readable;
|
|
1132
|
-
this.types[name] = type;
|
|
1457
|
+
var result = _.cloneDeep(database);
|
|
1133
1458
|
|
|
1134
|
-
|
|
1459
|
+
var fields = schema.objectFields;
|
|
1135
1460
|
|
|
1136
|
-
|
|
1137
|
-
|
|
1461
|
+
if (!fields) {
|
|
1462
|
+
return result;
|
|
1463
|
+
}
|
|
1138
1464
|
|
|
1139
|
-
|
|
1140
|
-
|
|
1465
|
+
var _loop2 = function _loop2() {
|
|
1466
|
+
var field = _step10.value;
|
|
1467
|
+
var value = result[field.name];
|
|
1141
1468
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
this.morph = {};
|
|
1146
|
-
this.theme = defaultTheme;
|
|
1469
|
+
if (_.isNil(value)) {
|
|
1470
|
+
return "continue";
|
|
1471
|
+
}
|
|
1147
1472
|
|
|
1148
|
-
|
|
1149
|
-
var t = _this.types[s.type];
|
|
1473
|
+
var type = field.type; // 时间选择器
|
|
1150
1474
|
|
|
1151
|
-
if (
|
|
1152
|
-
var
|
|
1475
|
+
if (type === "year" || type === "yearMonth" || type === "yearMonthDay" || type === "datetime" || type === "date") {
|
|
1476
|
+
var antConf = MDateTimeType.antConf(field);
|
|
1153
1477
|
|
|
1154
|
-
|
|
1478
|
+
if (antConf && _.isString(value)) {
|
|
1479
|
+
var m = moment(value, antConf.readableFormat);
|
|
1155
1480
|
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
} else if (_.isFunction(s.toReadable)) {
|
|
1160
|
-
r = s.toReadable(v, parent, _this);
|
|
1481
|
+
if (m.isValid()) {
|
|
1482
|
+
result[field.name] = m.format(antConf.dataFormat);
|
|
1483
|
+
}
|
|
1161
1484
|
}
|
|
1485
|
+
} // 时间范围选择器
|
|
1486
|
+
else if (type === "dateRange") {
|
|
1487
|
+
if (_.isString(value)) {
|
|
1488
|
+
var _field$dateRange2, _field$dataFormat2, _parts$, _parts$2;
|
|
1489
|
+
|
|
1490
|
+
var fmt = getReadableFormat(field.dateRangePrecision, (_field$dateRange2 = field.dateRange) == null ? void 0 : _field$dateRange2.showTime);
|
|
1491
|
+
var dataFormat = (_field$dataFormat2 = field.dataFormat) != null ? _field$dataFormat2 : "x";
|
|
1492
|
+
var parts = value.split(" - ");
|
|
1493
|
+
var startStr = (_parts$ = parts[0]) == null ? void 0 : _parts$.trim();
|
|
1494
|
+
var endStr = (_parts$2 = parts[1]) == null ? void 0 : _parts$2.trim();
|
|
1495
|
+
var start = null;
|
|
1496
|
+
var end = null;
|
|
1497
|
+
var tillNow = false;
|
|
1498
|
+
|
|
1499
|
+
if (startStr) {
|
|
1500
|
+
var _m3 = moment(startStr, fmt);
|
|
1501
|
+
|
|
1502
|
+
if (_m3.isValid()) {
|
|
1503
|
+
start = _m3.format(dataFormat);
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1162
1506
|
|
|
1163
|
-
|
|
1507
|
+
if (endStr === "至今") {
|
|
1508
|
+
tillNow = true;
|
|
1509
|
+
} else if (endStr) {
|
|
1510
|
+
var _m4 = moment(endStr, fmt);
|
|
1164
1511
|
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1512
|
+
if (_m4.isValid()) {
|
|
1513
|
+
end = _m4.format(dataFormat);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1168
1516
|
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1517
|
+
result[field.name] = [start, end, tillNow];
|
|
1518
|
+
}
|
|
1519
|
+
} // 嵌套 object
|
|
1520
|
+
else if (type === "object" && field.objectFields) {
|
|
1521
|
+
result[field.name] = MUtil.parseFromExport(field, value);
|
|
1522
|
+
} // 嵌套 array
|
|
1523
|
+
else if (type === "array" && field.arrayMember && _.isArray(value)) {
|
|
1524
|
+
if (field.arrayMember.objectFields) {
|
|
1525
|
+
result[field.name] = value.map(function (item) {
|
|
1526
|
+
return MUtil.parseFromExport(field.arrayMember, item);
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1172
1529
|
}
|
|
1173
|
-
};
|
|
1530
|
+
};
|
|
1174
1531
|
|
|
1532
|
+
for (var _iterator10 = _createForOfIteratorHelperLoose$d(fields), _step10; !(_step10 = _iterator10()).done;) {
|
|
1533
|
+
var _ret2 = _loop2();
|
|
1175
1534
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
if (!this.types[typeName]) {
|
|
1179
|
-
throw SyntaxError("\u7C7B\u578B" + typeName + "\u672A\u5B9A\u4E49");
|
|
1180
|
-
}
|
|
1535
|
+
if (_ret2 === "continue") continue;
|
|
1536
|
+
}
|
|
1181
1537
|
|
|
1182
|
-
|
|
1538
|
+
return result;
|
|
1539
|
+
},
|
|
1183
1540
|
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1541
|
+
/** 啥也不干的空回调 */
|
|
1542
|
+
doNothing: function doNothing() {},
|
|
1190
1543
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1544
|
+
/**
|
|
1545
|
+
* 去掉arr中的undefined和null,拼出来一个json path
|
|
1546
|
+
*/
|
|
1547
|
+
jsonPath: function jsonPath() {
|
|
1548
|
+
for (var _len2 = arguments.length, arr = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1549
|
+
arr[_key2] = arguments[_key2];
|
|
1550
|
+
}
|
|
1194
1551
|
|
|
1195
|
-
|
|
1552
|
+
return _.compact(arr).join(".");
|
|
1553
|
+
},
|
|
1196
1554
|
|
|
1197
|
-
|
|
1555
|
+
/**
|
|
1556
|
+
* 获取一个json path的父path。
|
|
1557
|
+
* @param path 如果path是空的返回也是空的
|
|
1558
|
+
*/
|
|
1559
|
+
parentPath: function parentPath(path) {
|
|
1560
|
+
var split = path.replace(/]/g, "").split(/[.\\[]/);
|
|
1561
|
+
split.splice(-1, 1);
|
|
1562
|
+
return split.join(".");
|
|
1563
|
+
},
|
|
1198
1564
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1565
|
+
/**
|
|
1566
|
+
* 校验一个schema
|
|
1567
|
+
* @param s 要校验的schema
|
|
1568
|
+
* @returns 空数组表示校验通过,否则返回校验错误信息
|
|
1569
|
+
*/
|
|
1570
|
+
validateSchema: function validateSchema(s, parentPath) {
|
|
1571
|
+
var result = [];
|
|
1203
1572
|
|
|
1204
|
-
var
|
|
1205
|
-
|
|
1573
|
+
var error = function error(msg) {
|
|
1574
|
+
return result.push({
|
|
1575
|
+
message: msg,
|
|
1576
|
+
path: MUtil.jsonPath(parentPath, s.name)
|
|
1577
|
+
});
|
|
1578
|
+
};
|
|
1206
1579
|
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1580
|
+
var checkDup = function checkDup(a, msgIfFail) {
|
|
1581
|
+
if (_.uniq(a).length !== a.length) {
|
|
1582
|
+
error(msgIfFail);
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1210
1585
|
|
|
1211
|
-
|
|
1586
|
+
var checkVL = function checkVL(fs) {
|
|
1587
|
+
checkDup(fs.map(function (f) {
|
|
1588
|
+
return f.value;
|
|
1589
|
+
}), s.name + "值有重复");
|
|
1590
|
+
checkDup(fs.map(function (f) {
|
|
1591
|
+
return f.label;
|
|
1592
|
+
}).filter(function (l) {
|
|
1593
|
+
return l;
|
|
1594
|
+
}), s.name + "文案有重复");
|
|
1595
|
+
};
|
|
1212
1596
|
|
|
1213
|
-
|
|
1214
|
-
|
|
1597
|
+
var stringOnlyEnum = function stringOnlyEnum(candidate) {
|
|
1598
|
+
var ns = MUtil.standardFields(candidate).find(function (f) {
|
|
1599
|
+
return !_.isString(f.value);
|
|
1600
|
+
});
|
|
1215
1601
|
|
|
1216
|
-
|
|
1602
|
+
if (ns) {
|
|
1603
|
+
error("暂不支持的选项数据类型:" + JSON.stringify(ns) + ": " + typeof ns);
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1217
1606
|
|
|
1218
|
-
if (
|
|
1219
|
-
return
|
|
1220
|
-
}
|
|
1607
|
+
if (s.type === "decoration") {
|
|
1608
|
+
return [];
|
|
1609
|
+
} else if (s.type === "enum") {
|
|
1610
|
+
checkVL(MUtil.standardFields(s.enumFields));
|
|
1611
|
+
} else if (s.type === "set") {
|
|
1612
|
+
checkVL(MUtil.standardFields(s.setFields));
|
|
1613
|
+
} else if (s.type === "matrix") {
|
|
1614
|
+
stringOnlyEnum(s.matrix.x);
|
|
1615
|
+
stringOnlyEnum(s.matrix.y);
|
|
1616
|
+
} else if (s.type === "object") {
|
|
1617
|
+
if (!s.objectFields) {
|
|
1618
|
+
error("object类型未定义成员");
|
|
1619
|
+
} else {
|
|
1620
|
+
var _s$uispec;
|
|
1221
1621
|
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
}, this.props);
|
|
1622
|
+
checkDup(s.objectFields.filter(function (f) {
|
|
1623
|
+
return f.type !== "decoration";
|
|
1624
|
+
}).map(function (f) {
|
|
1625
|
+
return f.name;
|
|
1626
|
+
}), "字段名有重复");
|
|
1228
1627
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
if (ctx.rootProps.wrapper && _this.props.schema.type !== 'object' && _this.props.schema.type !== 'array') {
|
|
1233
|
-
return ctx.rootProps.wrapper(ele, _this.props.schema);
|
|
1234
|
-
} else {
|
|
1235
|
-
return ele;
|
|
1628
|
+
for (var _iterator11 = _createForOfIteratorHelperLoose$d(s.objectFields), _step11; !(_step11 = _iterator11()).done;) {
|
|
1629
|
+
var f = _step11.value;
|
|
1630
|
+
result = _.concat(result, MUtil.validateSchema(f, MUtil.jsonPath(parentPath, s.name)));
|
|
1236
1631
|
}
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
};
|
|
1240
1632
|
|
|
1241
|
-
|
|
1242
|
-
|
|
1633
|
+
if (((_s$uispec = s.uispec) == null ? void 0 : _s$uispec.type) === "segmentForm") {
|
|
1634
|
+
if (!s.uispec.segments) {
|
|
1635
|
+
error("分段未定义");
|
|
1636
|
+
} else {
|
|
1637
|
+
checkDup(s.uispec.segments.map(function (f) {
|
|
1638
|
+
return f.label;
|
|
1639
|
+
}), "分段文案有重复");
|
|
1243
1640
|
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1641
|
+
var fieldsInSegments = _.flatten(s.uispec.segments.map(function (f) {
|
|
1642
|
+
return f.fields;
|
|
1643
|
+
}));
|
|
1644
|
+
|
|
1645
|
+
checkDup(fieldsInSegments, "分段字段有重复");
|
|
1646
|
+
var fields = s.objectFields.map(function (f) {
|
|
1647
|
+
return f.name;
|
|
1648
|
+
});
|
|
1649
|
+
checkDup(fields, "字段名有重复");
|
|
1253
1650
|
|
|
1254
|
-
|
|
1255
|
-
if (schema.required) {
|
|
1256
|
-
if (_.isNil(value) || value === "" || _.isNaN(value) || _.isArray(value) && value.length == 0) {
|
|
1257
|
-
return {
|
|
1258
|
-
message: "您还没有填完这一项",
|
|
1259
|
-
path: path
|
|
1260
|
-
};
|
|
1261
|
-
} // 凡是总有例外
|
|
1651
|
+
var notInSegment = _.difference(fields, fieldsInSegments);
|
|
1262
1652
|
|
|
1653
|
+
if (notInSegment.length > 0) {
|
|
1654
|
+
error("字段" + notInSegment.join(",") + "未体现在分段中");
|
|
1655
|
+
}
|
|
1263
1656
|
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1657
|
+
var fieldNotExist = _.difference(fieldsInSegments, fields);
|
|
1658
|
+
|
|
1659
|
+
if (fieldNotExist.length > 0) {
|
|
1660
|
+
error("分段字段名无效:" + notInSegment.join(","));
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1270
1664
|
}
|
|
1271
1665
|
}
|
|
1272
|
-
} else {
|
|
1273
|
-
if (_.isNil(value)) {
|
|
1274
|
-
return "pass";
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
1666
|
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1280
|
-
/** 和validateRequired相同,但不短路 */
|
|
1667
|
+
return result;
|
|
1668
|
+
},
|
|
1281
1669
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1670
|
+
/**
|
|
1671
|
+
* 参考https://stackoverflow.com/questions/3362471/how-can-i-call-a-javascript-constructor-using-call-or-apply
|
|
1672
|
+
* 示例: var d = applyToConstructor(Date, [2008, 10, 8, 00, 16, 34, 254]);
|
|
1673
|
+
* @param constructor
|
|
1674
|
+
* @param argArray
|
|
1675
|
+
*/
|
|
1676
|
+
applyToConstructor: function applyToConstructor(constructor, argArray) {
|
|
1677
|
+
var args = [null].concat(argArray);
|
|
1678
|
+
var factoryFunction = constructor.bind.apply(constructor, args);
|
|
1679
|
+
return new factoryFunction();
|
|
1680
|
+
},
|
|
1284
1681
|
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1682
|
+
/**
|
|
1683
|
+
* 执行表达式或者回调函数
|
|
1684
|
+
* @param exprOrFunction 表达式或者回调函数
|
|
1685
|
+
* @param paramName 参数名字
|
|
1686
|
+
* @param paramValue 参数值
|
|
1687
|
+
* @param fallback 如果exprOrFunction无效,返回fallback
|
|
1688
|
+
* @param _this this指针
|
|
1689
|
+
*/
|
|
1690
|
+
evalExprOrFunction: function evalExprOrFunction(exprOrFunction, paramName, paramValue, fallback, _this) {
|
|
1691
|
+
if (fallback === void 0) {
|
|
1692
|
+
fallback = undefined;
|
|
1296
1693
|
}
|
|
1297
|
-
}
|
|
1298
1694
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
return {
|
|
1302
|
-
message: "\u8BF7\u9009\u62E9" + schema.min + "\u4E4B\u524D\u7684\u65F6\u95F4",
|
|
1303
|
-
path: path
|
|
1304
|
-
};
|
|
1695
|
+
if (_this === void 0) {
|
|
1696
|
+
_this = undefined;
|
|
1305
1697
|
}
|
|
1306
|
-
}
|
|
1307
1698
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
function validateArrayItemMinMax(a, schema, value, path) {
|
|
1317
|
-
if (schema.min) {
|
|
1318
|
-
if (!value || value.length < schema.min) {
|
|
1319
|
-
return {
|
|
1320
|
-
message: "\u81F3\u5C11\u9009\u62E9" + schema.min + "\u9879",
|
|
1321
|
-
path: path
|
|
1322
|
-
};
|
|
1699
|
+
if (_.isFunction(exprOrFunction)) {
|
|
1700
|
+
return exprOrFunction.apply(_this, paramValue);
|
|
1701
|
+
} else if (_.isString(exprOrFunction)) {
|
|
1702
|
+
//return new Function("_", "value", "parent", "return (" + labelExpr + ");")(_, value, parent);
|
|
1703
|
+
var func = MUtil.applyToConstructor(Function, [].concat(paramName, ["return (" + exprOrFunction + ")"]));
|
|
1704
|
+
return func.apply(_this, paramValue);
|
|
1705
|
+
} else {
|
|
1706
|
+
return fallback;
|
|
1323
1707
|
}
|
|
1324
|
-
}
|
|
1708
|
+
},
|
|
1325
1709
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1710
|
+
/**
|
|
1711
|
+
* 读取url参数,转换成map
|
|
1712
|
+
* @param hashPrefix nil表示不读取hash里的参数,字符串表示读取hash里的参数,并加上这个前缀返回。默认是返回,但前缀是空字符串
|
|
1713
|
+
*/
|
|
1714
|
+
getQuery: function getQuery(hashPrefix) {
|
|
1334
1715
|
|
|
1335
|
-
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
* @param schema
|
|
1340
|
-
* @param value 应该是个字符串
|
|
1341
|
-
*/
|
|
1716
|
+
var arrs = [].concat(window.location.search.split(/[?&]/), window.location.hash.split(/[#?&]/));
|
|
1717
|
+
var result = {};
|
|
1718
|
+
arrs.forEach(function (item) {
|
|
1719
|
+
var kv = item.split(/=/);
|
|
1342
1720
|
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
};
|
|
1350
|
-
}
|
|
1351
|
-
}
|
|
1721
|
+
if (kv.length <= 2 && kv[0]) {
|
|
1722
|
+
result[decodeURIComponent(kv[0])] = decodeURIComponent(kv[1]);
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
return result;
|
|
1726
|
+
},
|
|
1352
1727
|
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
}
|
|
1728
|
+
/**
|
|
1729
|
+
* 动态创建一个CSS样式
|
|
1730
|
+
* @param css css内容,会被写进style标签里
|
|
1731
|
+
* @param id <style>的id,可以没有。如果已经存在,会被覆盖掉。
|
|
1732
|
+
*/
|
|
1733
|
+
setCss: function setCss(css, id) {
|
|
1734
|
+
var _document$getElementB;
|
|
1361
1735
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
*/
|
|
1736
|
+
var s = (_document$getElementB = document.getElementById(id)) != null ? _document$getElementB : document.createElement("style");
|
|
1737
|
+
s.id = id;
|
|
1738
|
+
s.type = "text/css";
|
|
1739
|
+
s.innerHTML = css;
|
|
1740
|
+
document.getElementsByTagName("head")[0].appendChild(s);
|
|
1741
|
+
},
|
|
1369
1742
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1743
|
+
/**
|
|
1744
|
+
* escape数值
|
|
1745
|
+
* @param str - 字符串
|
|
1746
|
+
* @returns 会带上引号,类似"abc",str=nil时会返回""
|
|
1747
|
+
*/
|
|
1748
|
+
escapeCsv: function escapeCsv(str) {
|
|
1749
|
+
if (!_.isString(str)) {
|
|
1750
|
+
str = _.toString(str);
|
|
1751
|
+
}
|
|
1372
1752
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1753
|
+
return '"' + str.replace(/["]/g, '""') + '"';
|
|
1754
|
+
},
|
|
1755
|
+
|
|
1756
|
+
/**
|
|
1757
|
+
* 判断两个值是否相同
|
|
1758
|
+
* @param v1 一个值
|
|
1759
|
+
* @param v2 另一个值
|
|
1760
|
+
* @param tolerate true用==判断,false用===判断
|
|
1761
|
+
*/
|
|
1762
|
+
isEquals: function isEquals(v1, v2, tolerate) {
|
|
1763
|
+
if (tolerate) {
|
|
1764
|
+
return v1 == v2;
|
|
1765
|
+
} else {
|
|
1766
|
+
return v1 === v2;
|
|
1379
1767
|
}
|
|
1380
1768
|
}
|
|
1769
|
+
};
|
|
1770
|
+
var CompactArray = {
|
|
1771
|
+
indexOf: function indexOf(ca, d) {
|
|
1772
|
+
if (_.isNil(d) || _.isNil(ca)) {
|
|
1773
|
+
return -1;
|
|
1774
|
+
}
|
|
1381
1775
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
path: path
|
|
1387
|
-
};
|
|
1776
|
+
if (_.isArray(ca)) {
|
|
1777
|
+
return ca.indexOf(d);
|
|
1778
|
+
} else {
|
|
1779
|
+
return ca === d ? 0 : -1;
|
|
1388
1780
|
}
|
|
1389
1781
|
}
|
|
1782
|
+
};
|
|
1390
1783
|
|
|
1391
|
-
|
|
1392
|
-
}
|
|
1393
|
-
function generateRegexValidate$1(regex, mismatchMsg) {
|
|
1394
|
-
return function (a, schema, value, path) {
|
|
1395
|
-
var asstr = _.toString(value);
|
|
1784
|
+
var MContext = /*#__PURE__*/React.createContext(undefined);
|
|
1396
1785
|
|
|
1397
|
-
|
|
1398
|
-
return {
|
|
1399
|
-
message: mismatchMsg,
|
|
1400
|
-
path: path
|
|
1401
|
-
};
|
|
1402
|
-
}
|
|
1786
|
+
function ownKeys$x(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
1403
1787
|
|
|
1404
|
-
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1788
|
+
function _objectSpread$x(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$x(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$x(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
1407
1789
|
/**
|
|
1408
|
-
*
|
|
1409
|
-
* 可以用Object.prototype.toString.call(<预期的类型>)来查看你想要的数据类型的expectType
|
|
1410
|
-
* @param expectType 预期类型,例如:"[object Object]" "[object Null]" "[object Number]" "[object Date]" "[object Array]"
|
|
1411
|
-
* @param mismatchMsg 如果不匹配,提示的错误信息
|
|
1412
|
-
* @returns
|
|
1790
|
+
* 一个字段的视图
|
|
1413
1791
|
*/
|
|
1414
1792
|
|
|
1415
|
-
function
|
|
1416
|
-
|
|
1417
|
-
|
|
1793
|
+
var MFieldViewer = /*#__PURE__*/function (_React$Component) {
|
|
1794
|
+
_inheritsLoose(MFieldViewer, _React$Component);
|
|
1795
|
+
|
|
1796
|
+
function MFieldViewer() {
|
|
1797
|
+
return _React$Component.apply(this, arguments) || this;
|
|
1418
1798
|
}
|
|
1419
1799
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
path: path
|
|
1427
|
-
};
|
|
1428
|
-
}
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
function generateSchemaValidate(valueSchema, mismatchMsg) {
|
|
1432
|
-
return function (a, schema, value, path) {
|
|
1433
|
-
var r = assembly.validate(valueSchema, value, "");
|
|
1800
|
+
var _proto = MFieldViewer.prototype;
|
|
1801
|
+
|
|
1802
|
+
_proto.render = function render() {
|
|
1803
|
+
var _this = this;
|
|
1804
|
+
|
|
1805
|
+
var viewer = assembly.getViewerOf(this.props.schema, this.props.morph); // console.log('MFieldViewer.viewer', viewer);
|
|
1434
1806
|
|
|
1435
|
-
if (!
|
|
1436
|
-
return
|
|
1437
|
-
} else {
|
|
1438
|
-
return {
|
|
1439
|
-
message: mismatchMsg != null ? mismatchMsg : r.message,
|
|
1440
|
-
path: path
|
|
1441
|
-
};
|
|
1807
|
+
if (!viewer) {
|
|
1808
|
+
return MUtil.error("\u5B57\u6BB5\u7684\u89C6\u56FE\u5C1A\u672A\u5B9E\u73B0", this.props.schema);
|
|
1442
1809
|
}
|
|
1810
|
+
|
|
1811
|
+
var props = _objectSpread$x({
|
|
1812
|
+
afterChange: function afterChange() {},
|
|
1813
|
+
changeSchema: function changeSchema() {},
|
|
1814
|
+
changeDatabase: function changeDatabase() {},
|
|
1815
|
+
name: this.props.path
|
|
1816
|
+
}, this.props);
|
|
1817
|
+
|
|
1818
|
+
var ele = /*#__PURE__*/React.createElement(viewer, props, null);
|
|
1819
|
+
return jsx(MContext.Consumer, {
|
|
1820
|
+
children: function children(ctx) {
|
|
1821
|
+
if (ctx.rootProps.wrapper && _this.props.schema.type !== 'object' && _this.props.schema.type !== 'array') {
|
|
1822
|
+
return ctx.rootProps.wrapper(ele, _this.props.schema);
|
|
1823
|
+
} else {
|
|
1824
|
+
return ele;
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
});
|
|
1443
1828
|
};
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
validateRequiredNS: validateRequiredNS,
|
|
1448
|
-
validateDateMinMax: validateDateMinMax,
|
|
1449
|
-
validateStringMinMax: validateStringMinMax$1,
|
|
1450
|
-
validateNumberMinMax: validateNumberMinMax,
|
|
1451
|
-
generateRegexValidate: generateRegexValidate$1
|
|
1452
|
-
};
|
|
1829
|
+
|
|
1830
|
+
return MFieldViewer;
|
|
1831
|
+
}(React.Component);
|
|
1453
1832
|
|
|
1454
1833
|
function _createForOfIteratorHelperLoose$c(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray$c(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
1455
1834
|
|
|
@@ -1536,34 +1915,6 @@ var MEnumType = {
|
|
|
1536
1915
|
}
|
|
1537
1916
|
};
|
|
1538
1917
|
|
|
1539
|
-
var EmtpyType = {
|
|
1540
|
-
validators: [],
|
|
1541
|
-
createDefaultValue: function createDefaultValue(assembly, s) {
|
|
1542
|
-
if (s.defaultValue) {
|
|
1543
|
-
return _.clone(s.defaultValue);
|
|
1544
|
-
} else {
|
|
1545
|
-
return undefined;
|
|
1546
|
-
}
|
|
1547
|
-
},
|
|
1548
|
-
standardValue: function standardValue(assembly, s, v, strict) {
|
|
1549
|
-
return v;
|
|
1550
|
-
},
|
|
1551
|
-
toReadable: function toReadable(assembly, s, vs) {
|
|
1552
|
-
if (_.isNil(vs)) {
|
|
1553
|
-
return assembly.theme.READABLE_BLANK;
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
return vs;
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
function createDefaultValue(assembly, s) {
|
|
1560
|
-
if (s.defaultValue) {
|
|
1561
|
-
return _.clone(s.defaultValue);
|
|
1562
|
-
} else {
|
|
1563
|
-
return undefined;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
1918
|
var gb2260 = [
|
|
1568
1919
|
{
|
|
1569
1920
|
value: "110000",
|
|
@@ -15101,103 +15452,6 @@ var MGB2260Type = _.assign({}, EmtpyType, {
|
|
|
15101
15452
|
}
|
|
15102
15453
|
});
|
|
15103
15454
|
|
|
15104
|
-
var MDateTimeType = _.assign({}, EmtpyType, {
|
|
15105
|
-
validators: [validateRequired$1, validateDateMinMax],
|
|
15106
|
-
antConf: function antConf(schema) {
|
|
15107
|
-
var _dataFormat, _dataFormat2, _dataFormat3, _dataFormat4, _dataFormat5, _dataFormat6, _dataFormat7, _dataFormat8;
|
|
15108
|
-
|
|
15109
|
-
var dataFormat = schema.dataFormat;
|
|
15110
|
-
var readableFormat;
|
|
15111
|
-
var mode;
|
|
15112
|
-
var showTime = false;
|
|
15113
|
-
|
|
15114
|
-
switch (schema.type) {
|
|
15115
|
-
case "year":
|
|
15116
|
-
mode = "year";
|
|
15117
|
-
dataFormat = (_dataFormat = dataFormat) != null ? _dataFormat : "YYYY";
|
|
15118
|
-
readableFormat = "YYYY";
|
|
15119
|
-
break;
|
|
15120
|
-
|
|
15121
|
-
case "yearMonth":
|
|
15122
|
-
mode = "month";
|
|
15123
|
-
dataFormat = (_dataFormat2 = dataFormat) != null ? _dataFormat2 : "YYYYMM";
|
|
15124
|
-
readableFormat = "YYYY-MM";
|
|
15125
|
-
break;
|
|
15126
|
-
|
|
15127
|
-
case "yearMonthDay":
|
|
15128
|
-
mode = "date";
|
|
15129
|
-
dataFormat = (_dataFormat3 = dataFormat) != null ? _dataFormat3 : "YYYYMMDD";
|
|
15130
|
-
readableFormat = "YYYY-MM-DD";
|
|
15131
|
-
break;
|
|
15132
|
-
|
|
15133
|
-
case "datetime":
|
|
15134
|
-
mode = undefined;
|
|
15135
|
-
dataFormat = (_dataFormat4 = dataFormat) != null ? _dataFormat4 : "x";
|
|
15136
|
-
readableFormat = "YYYY-MM-DD HH:mm";
|
|
15137
|
-
showTime = true;
|
|
15138
|
-
break;
|
|
15139
|
-
|
|
15140
|
-
case "date":
|
|
15141
|
-
switch (schema.datePrecision) {
|
|
15142
|
-
case "year":
|
|
15143
|
-
mode = "year";
|
|
15144
|
-
dataFormat = (_dataFormat5 = dataFormat) != null ? _dataFormat5 : "YYYY";
|
|
15145
|
-
readableFormat = "YYYY";
|
|
15146
|
-
break;
|
|
15147
|
-
|
|
15148
|
-
case "month":
|
|
15149
|
-
mode = "month";
|
|
15150
|
-
dataFormat = (_dataFormat6 = dataFormat) != null ? _dataFormat6 : "YYYYMM";
|
|
15151
|
-
readableFormat = "YYYY-MM";
|
|
15152
|
-
break;
|
|
15153
|
-
|
|
15154
|
-
case "minute":
|
|
15155
|
-
mode = undefined;
|
|
15156
|
-
dataFormat = (_dataFormat7 = dataFormat) != null ? _dataFormat7 : "x";
|
|
15157
|
-
readableFormat = "YYYY-MM-DD HH:mm";
|
|
15158
|
-
showTime = true;
|
|
15159
|
-
break;
|
|
15160
|
-
|
|
15161
|
-
default:
|
|
15162
|
-
// "day" 或未指定
|
|
15163
|
-
mode = "date";
|
|
15164
|
-
dataFormat = (_dataFormat8 = dataFormat) != null ? _dataFormat8 : "YYYYMMDD";
|
|
15165
|
-
readableFormat = "YYYY-MM-DD";
|
|
15166
|
-
break;
|
|
15167
|
-
}
|
|
15168
|
-
|
|
15169
|
-
break;
|
|
15170
|
-
// case "yearAndQuarter":
|
|
15171
|
-
// case "yearAndWeek":
|
|
15172
|
-
// return MUtil.error(`移动端不支持${this.props.schema.type}`, this.props.schema);
|
|
15173
|
-
|
|
15174
|
-
default:
|
|
15175
|
-
return undefined;
|
|
15176
|
-
}
|
|
15177
|
-
|
|
15178
|
-
return {
|
|
15179
|
-
dataFormat: dataFormat,
|
|
15180
|
-
readableFormat: readableFormat,
|
|
15181
|
-
mode: mode,
|
|
15182
|
-
showTime: showTime
|
|
15183
|
-
};
|
|
15184
|
-
},
|
|
15185
|
-
toReadable: function toReadable(assembly, schema, v) {
|
|
15186
|
-
if (_.isNil(v)) {
|
|
15187
|
-
return assembly.theme.READABLE_BLANK;
|
|
15188
|
-
}
|
|
15189
|
-
|
|
15190
|
-
var c = MDateTimeType.antConf(schema);
|
|
15191
|
-
|
|
15192
|
-
if (!c) {
|
|
15193
|
-
return assembly.theme.READABLE_INVALID;
|
|
15194
|
-
}
|
|
15195
|
-
|
|
15196
|
-
var asMoment = moment(v, c.dataFormat);
|
|
15197
|
-
return asMoment.format(c.readableFormat);
|
|
15198
|
-
}
|
|
15199
|
-
});
|
|
15200
|
-
|
|
15201
15455
|
function _createForOfIteratorHelperLoose$a(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray$a(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15202
15456
|
|
|
15203
15457
|
function _unsupportedIterableToArray$a(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$a(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$a(o, minLen); }
|
|
@@ -15849,75 +16103,6 @@ var MObjectType = {
|
|
|
15849
16103
|
}
|
|
15850
16104
|
};
|
|
15851
16105
|
|
|
15852
|
-
/** 根据 precision 获取可读格式 */
|
|
15853
|
-
|
|
15854
|
-
function getReadableFormat(precision, showTime) {
|
|
15855
|
-
switch (precision) {
|
|
15856
|
-
case "year":
|
|
15857
|
-
return "YYYY年";
|
|
15858
|
-
|
|
15859
|
-
case "month":
|
|
15860
|
-
return "YYYY年MM月";
|
|
15861
|
-
|
|
15862
|
-
case "minute":
|
|
15863
|
-
return "YYYY年MM月DD日 HH:mm";
|
|
15864
|
-
|
|
15865
|
-
default:
|
|
15866
|
-
return showTime ? "YYYY年MM月DD日 HH:mm:ss" : "YYYY年MM月DD日";
|
|
15867
|
-
}
|
|
15868
|
-
}
|
|
15869
|
-
|
|
15870
|
-
function timeExpr(assembly, v, tillNow, readableFormat) {
|
|
15871
|
-
if (tillNow) {
|
|
15872
|
-
return "至今";
|
|
15873
|
-
}
|
|
15874
|
-
|
|
15875
|
-
if (!v) {
|
|
15876
|
-
return assembly.theme.READABLE_UNKNOWN;
|
|
15877
|
-
}
|
|
15878
|
-
|
|
15879
|
-
return moment(v, "x").format(readableFormat);
|
|
15880
|
-
}
|
|
15881
|
-
|
|
15882
|
-
function timeRangeExpr(assembly, from, to, tillNow, readableFormat) {
|
|
15883
|
-
if (readableFormat === void 0) {
|
|
15884
|
-
readableFormat = "YYYY年MM月DD日";
|
|
15885
|
-
}
|
|
15886
|
-
|
|
15887
|
-
return timeExpr(assembly, from, false, readableFormat) + " ~ " + timeExpr(assembly, to, tillNow, readableFormat);
|
|
15888
|
-
}
|
|
15889
|
-
var MDateRangeType = _.assign({}, EmtpyType, {
|
|
15890
|
-
validators: [validateRequired$1],
|
|
15891
|
-
toReadable: function toReadable(assembly, s, vs) {
|
|
15892
|
-
var _s$dateRange;
|
|
15893
|
-
|
|
15894
|
-
if (_.isNil(vs)) {
|
|
15895
|
-
return assembly.theme.READABLE_BLANK;
|
|
15896
|
-
}
|
|
15897
|
-
|
|
15898
|
-
if (!_.isArray(vs)) {
|
|
15899
|
-
return assembly.theme.READABLE_INVALID;
|
|
15900
|
-
}
|
|
15901
|
-
|
|
15902
|
-
var fmt = getReadableFormat(s.dateRangePrecision, (_s$dateRange = s.dateRange) == null ? void 0 : _s$dateRange.showTime);
|
|
15903
|
-
return timeRangeExpr(assembly, vs[0], vs[1], vs[2], fmt);
|
|
15904
|
-
},
|
|
15905
|
-
|
|
15906
|
-
/**
|
|
15907
|
-
* 同toReadable,但数据无效时返回nil
|
|
15908
|
-
*/
|
|
15909
|
-
toReadableN: function toReadableN(assembly, s, vs) {
|
|
15910
|
-
if (!_.isNil(vs) && _.isArray(vs)) {
|
|
15911
|
-
var _s$dateRange2;
|
|
15912
|
-
|
|
15913
|
-
var fmt = getReadableFormat(s.dateRangePrecision, (_s$dateRange2 = s.dateRange) == null ? void 0 : _s$dateRange2.showTime);
|
|
15914
|
-
return timeRangeExpr(assembly, vs[0], vs[1], vs[2], fmt);
|
|
15915
|
-
}
|
|
15916
|
-
|
|
15917
|
-
return undefined;
|
|
15918
|
-
}
|
|
15919
|
-
});
|
|
15920
|
-
|
|
15921
16106
|
function _createForOfIteratorHelperLoose$6(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray$6(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15922
16107
|
|
|
15923
16108
|
function _unsupportedIterableToArray$6(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$6(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$6(o, minLen); }
|
|
@@ -22878,25 +23063,43 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
|
|
|
22878
23063
|
}, "start_" + mobilePrecision), jsx(DatePicker, {
|
|
22879
23064
|
visible: this.state.mobileDlg && this.state.mobileStep === 'end',
|
|
22880
23065
|
precision: mobilePrecision,
|
|
22881
|
-
title: "
|
|
22882
|
-
|
|
23066
|
+
title: // 如果允许"至今"且开始时间不在未来,在标题区域展示"至今"按钮
|
|
23067
|
+
!((_this$props$schema$da3 = this.props.schema.dateRange) != null && _this$props$schema$da3.hideTillNow) && !((_this$props$schema$da4 = this.props.schema.dateRange) != null && _this$props$schema$da4.showTime) && !(this.state.mobileStartDate && this.state.mobileStartDate > new Date()) ? jsxs("div", {
|
|
23068
|
+
style: {
|
|
23069
|
+
display: 'flex',
|
|
23070
|
+
alignItems: 'center',
|
|
23071
|
+
justifyContent: 'center',
|
|
23072
|
+
gap: 12
|
|
23073
|
+
},
|
|
23074
|
+
children: [jsx("span", {
|
|
23075
|
+
children: "\u9009\u62E9\u7ED3\u675F\u65E5\u671F"
|
|
23076
|
+
}), jsx(Button, {
|
|
23077
|
+
size: "small",
|
|
23078
|
+
type: "primary",
|
|
23079
|
+
onClick: function onClick() {
|
|
23080
|
+
var startDate = _this2.state.mobileStartDate;
|
|
23081
|
+
|
|
23082
|
+
if (startDate) {
|
|
23083
|
+
_Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data([moment(startDate), moment()], true), true, true);
|
|
23084
|
+
}
|
|
23085
|
+
|
|
23086
|
+
_this2.setState({
|
|
23087
|
+
mobileDlg: false
|
|
23088
|
+
});
|
|
23089
|
+
},
|
|
23090
|
+
children: "\u81F3\u4ECA"
|
|
23091
|
+
})]
|
|
23092
|
+
}) : "选择结束日期",
|
|
22883
23093
|
min: this.state.mobileStartDate || (this.props.schema.min ? new Date(this.props.schema.min) : undefined),
|
|
22884
23094
|
max: this.props.schema.max ? new Date(this.props.schema.max) : undefined,
|
|
22885
23095
|
onConfirm: function onConfirm(val) {
|
|
22886
23096
|
var startDate = _this2.state.mobileStartDate;
|
|
22887
23097
|
|
|
22888
23098
|
if (startDate) {
|
|
22889
|
-
|
|
22890
|
-
|
|
22891
|
-
if (isTillNow) {
|
|
22892
|
-
// 用户选择了"至今"
|
|
22893
|
-
_Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data([moment(startDate), moment()], true), true, true);
|
|
22894
|
-
} else {
|
|
22895
|
-
// 防御:结束日期不能早于开始日期
|
|
22896
|
-
var finalEnd = val < startDate ? startDate : val;
|
|
23099
|
+
// 防御:结束日期不能早于开始日期
|
|
23100
|
+
var finalEnd = val < startDate ? startDate : val;
|
|
22897
23101
|
|
|
22898
|
-
|
|
22899
|
-
}
|
|
23102
|
+
_Viewer.prototype.changeValueEx.call(_this2, _this2._rangePicker2Data([moment(startDate), moment(finalEnd)], false), true, true);
|
|
22900
23103
|
}
|
|
22901
23104
|
|
|
22902
23105
|
_this2.setState({
|
|
@@ -22933,6 +23136,15 @@ var ARangePicker = /*#__PURE__*/function (_Viewer) {
|
|
|
22933
23136
|
return jsx(DatePicker$1.RangePicker, _objectSpread$8({
|
|
22934
23137
|
ref: this._pickerRef,
|
|
22935
23138
|
renderExtraFooter: hideFooter ? undefined : function (mode) {
|
|
23139
|
+
var _this2$_onCalendarCha;
|
|
23140
|
+
|
|
23141
|
+
// 如果开始时间超过当前时间(未来时间),不展示"至今"按钮
|
|
23142
|
+
var startMoment = (_this2$_onCalendarCha = _this2._onCalendarChangeValue) == null ? void 0 : _this2$_onCalendarCha[0];
|
|
23143
|
+
|
|
23144
|
+
if (startMoment && startMoment.isAfter(moment())) {
|
|
23145
|
+
return null;
|
|
23146
|
+
}
|
|
23147
|
+
|
|
22936
23148
|
return jsx("div", {
|
|
22937
23149
|
style: {
|
|
22938
23150
|
textAlign: "right"
|