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