UNPKG

161 kBJavaScriptView Raw
1/*!
2 * @form-create/ant-design-vue v2.5.11
3 * (c) 2018-2021 xaboy
4 * Github https://github.com/xaboy/form-create
5 * Released under the MIT License.
6 */
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('moment')) :
9 typeof define === 'function' && define.amd ? define(['exports', 'vue', 'moment'], factory) :
10 (global = global || self, factory(global.formCreate = {}, global.Vue, global.moment));
11}(this, (function (exports, Vue, moment) { 'use strict';
12
13 Vue = Vue && Object.prototype.hasOwnProperty.call(Vue, 'default') ? Vue['default'] : Vue;
14 moment = moment && Object.prototype.hasOwnProperty.call(moment, 'default') ? moment['default'] : moment;
15
16 function _extends() {
17 return _extends = Object.assign || function (a) {
18 for (var b, c = 1; c < arguments.length; c++) {
19 for (var d in b = arguments[c], b) {
20 Object.prototype.hasOwnProperty.call(b, d) && (a[d] = b[d]);
21 }
22 }
23
24 return a;
25 }, _extends.apply(this, arguments);
26 }
27
28 var normalMerge = ["attrs", "props", "domProps"],
29 toArrayMerge = ["class", "style", "directives"],
30 functionalMerge = ["on", "nativeOn"],
31 mergeJsxProps = function mergeJsxProps(a) {
32 return a.reduce(function (c, a) {
33 for (var b in a) {
34 if (!c[b]) c[b] = a[b];else if (-1 !== normalMerge.indexOf(b)) c[b] = _extends({}, c[b], a[b]);else if (-1 !== toArrayMerge.indexOf(b)) {
35 var d = c[b] instanceof Array ? c[b] : [c[b]],
36 e = a[b] instanceof Array ? a[b] : [a[b]];
37 c[b] = d.concat(e);
38 } else if (-1 !== functionalMerge.indexOf(b)) {
39 for (var f in a[b]) {
40 if (c[b][f]) {
41 var g = c[b][f] instanceof Array ? c[b][f] : [c[b][f]],
42 h = a[b][f] instanceof Array ? a[b][f] : [a[b][f]];
43 c[b][f] = g.concat(h);
44 } else c[b][f] = a[b][f];
45 }
46 } else if ("hook" == b) for (var i in a[b]) {
47 c[b][i] = c[b][i] ? mergeFn(c[b][i], a[b][i]) : a[b][i];
48 } else c[b] = a[b];
49 }
50
51 return c;
52 }, {});
53 },
54 mergeFn = function mergeFn(a, b) {
55 return function () {
56 a && a.apply(this, arguments), b && b.apply(this, arguments);
57 };
58 };
59
60 var helper = mergeJsxProps;
61
62 function _typeof(obj) {
63 "@babel/helpers - typeof";
64
65 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
66 _typeof = function (obj) {
67 return typeof obj;
68 };
69 } else {
70 _typeof = function (obj) {
71 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
72 };
73 }
74
75 return _typeof(obj);
76 }
77
78 function _classCallCheck(instance, Constructor) {
79 if (!(instance instanceof Constructor)) {
80 throw new TypeError("Cannot call a class as a function");
81 }
82 }
83
84 function _defineProperty(obj, key, value) {
85 if (key in obj) {
86 Object.defineProperty(obj, key, {
87 value: value,
88 enumerable: true,
89 configurable: true,
90 writable: true
91 });
92 } else {
93 obj[key] = value;
94 }
95
96 return obj;
97 }
98
99 function ownKeys(object, enumerableOnly) {
100 var keys = Object.keys(object);
101
102 if (Object.getOwnPropertySymbols) {
103 var symbols = Object.getOwnPropertySymbols(object);
104 if (enumerableOnly) symbols = symbols.filter(function (sym) {
105 return Object.getOwnPropertyDescriptor(object, sym).enumerable;
106 });
107 keys.push.apply(keys, symbols);
108 }
109
110 return keys;
111 }
112
113 function _objectSpread2(target) {
114 for (var i = 1; i < arguments.length; i++) {
115 var source = arguments[i] != null ? arguments[i] : {};
116
117 if (i % 2) {
118 ownKeys(Object(source), true).forEach(function (key) {
119 _defineProperty(target, key, source[key]);
120 });
121 } else if (Object.getOwnPropertyDescriptors) {
122 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
123 } else {
124 ownKeys(Object(source)).forEach(function (key) {
125 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
126 });
127 }
128 }
129
130 return target;
131 }
132
133 function _inherits(subClass, superClass) {
134 if (typeof superClass !== "function" && superClass !== null) {
135 throw new TypeError("Super expression must either be null or a function");
136 }
137
138 subClass.prototype = Object.create(superClass && superClass.prototype, {
139 constructor: {
140 value: subClass,
141 writable: true,
142 configurable: true
143 }
144 });
145 if (superClass) _setPrototypeOf(subClass, superClass);
146 }
147
148 function _getPrototypeOf(o) {
149 _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
150 return o.__proto__ || Object.getPrototypeOf(o);
151 };
152 return _getPrototypeOf(o);
153 }
154
155 function _setPrototypeOf(o, p) {
156 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
157 o.__proto__ = p;
158 return o;
159 };
160
161 return _setPrototypeOf(o, p);
162 }
163
164 function _isNativeReflectConstruct() {
165 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
166 if (Reflect.construct.sham) return false;
167 if (typeof Proxy === "function") return true;
168
169 try {
170 Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
171 return true;
172 } catch (e) {
173 return false;
174 }
175 }
176
177 function _assertThisInitialized(self) {
178 if (self === void 0) {
179 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
180 }
181
182 return self;
183 }
184
185 function _possibleConstructorReturn(self, call) {
186 if (call && (typeof call === "object" || typeof call === "function")) {
187 return call;
188 }
189
190 return _assertThisInitialized(self);
191 }
192
193 function _createSuper(Derived) {
194 var hasNativeReflectConstruct = _isNativeReflectConstruct();
195
196 return function _createSuperInternal() {
197 var Super = _getPrototypeOf(Derived),
198 result;
199
200 if (hasNativeReflectConstruct) {
201 var NewTarget = _getPrototypeOf(this).constructor;
202
203 result = Reflect.construct(Super, arguments, NewTarget);
204 } else {
205 result = Super.apply(this, arguments);
206 }
207
208 return _possibleConstructorReturn(this, result);
209 };
210 }
211
212 function _toConsumableArray(arr) {
213 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
214 }
215
216 function _arrayWithoutHoles(arr) {
217 if (Array.isArray(arr)) return _arrayLikeToArray(arr);
218 }
219
220 function _iterableToArray(iter) {
221 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
222 }
223
224 function _unsupportedIterableToArray(o, minLen) {
225 if (!o) return;
226 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
227 var n = Object.prototype.toString.call(o).slice(8, -1);
228 if (n === "Object" && o.constructor) n = o.constructor.name;
229 if (n === "Map" || n === "Set") return Array.from(o);
230 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
231 }
232
233 function _arrayLikeToArray(arr, len) {
234 if (len == null || len > arr.length) len = arr.length;
235
236 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
237
238 return arr2;
239 }
240
241 function _nonIterableSpread() {
242 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
243 }
244
245 function toString(val) {
246 return val == null ? '' : _typeof(val) === 'object' ? JSON.stringify(val, null, 2) : String(val);
247 }
248
249 function $set(target, field, value) {
250 Vue.set(target, field, value);
251 }
252 function $del(target, field) {
253 Vue["delete"](target, field);
254 }
255
256 var is = {
257 type: function type(arg, _type) {
258 return Object.prototype.toString.call(arg) === '[object ' + _type + ']';
259 },
260 Undef: function Undef(v) {
261 return v === undefined || v === null;
262 },
263 Element: function Element(arg) {
264 return _typeof(arg) === 'object' && arg !== null && arg.nodeType === 1 && !is.Object(arg);
265 },
266 trueArray: function trueArray(data) {
267 return Array.isArray(data) && data.length > 0;
268 }
269 };
270 ['Date', 'Object', 'Function', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
271 is[t] = function (arg) {
272 return is.type(arg, t);
273 };
274 });
275 function hasProperty(rule, k) {
276 return {}.hasOwnProperty.call(rule, k);
277 }
278
279 function deepExtend(origin) {
280 var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
281 var mode = arguments.length > 2 ? arguments[2] : undefined;
282 var isArr = false;
283
284 for (var key in target) {
285 if (Object.prototype.hasOwnProperty.call(target, key)) {
286 var clone = target[key];
287
288 if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
289 var nst = origin[key] === undefined;
290
291 if (isArr) {
292 isArr = false;
293 nst && $set(origin, key, []);
294 } else if (clone._clone && mode !== undefined) {
295 if (mode) {
296 clone = clone.getRule();
297 nst && $set(origin, key, {});
298 } else {
299 $set(origin, key, clone._clone());
300 continue;
301 }
302 } else {
303 nst && $set(origin, key, {});
304 }
305
306 origin[key] = deepExtend(origin[key], clone, mode);
307 } else if (is.Undef(clone)) {
308 $set(origin, key, clone);
309 } else if (clone.__json !== undefined) {
310 $set(origin, key, clone.__json);
311 } else if (clone.__origin !== undefined) {
312 $set(origin, key, clone.__origin);
313 } else {
314 $set(origin, key, clone);
315 }
316 }
317 }
318
319 return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
320 return !v || !v.__ctrl;
321 }) : origin;
322 }
323 function deepCopy(value) {
324 return deepExtend({}, {
325 value: value
326 }).value;
327 }
328
329 function toArray(value) {
330 return Array.isArray(value) ? value : [null, undefined, ''].indexOf(value) > -1 ? [] : [value];
331 }
332
333 function getSlot(slots, exclude) {
334 return Object.keys(slots).reduce(function (lst, name) {
335 if (!exclude || exclude.indexOf(name) === -1) {
336 lst.push(slots[name]);
337 }
338
339 return lst;
340 }, []);
341 }
342
343 var parseFile = function parseFile(file, uid) {
344 return {
345 url: file,
346 name: getFileName(file),
347 status: 'done',
348 uid: uid + 1
349 };
350 },
351 getFileName = function getFileName(file) {
352 return toString(file).split('/').pop();
353 },
354 parseUpload = function parseUpload(file) {
355 return {
356 url: file.url,
357 file: file
358 };
359 };
360
361 var NAME = 'fcUpload';
362 var Upload = {
363 name: NAME,
364 formCreateParser: {
365 toFormValue: function toFormValue(value) {
366 return toArray(value);
367 },
368 toValue: function toValue(formValue, ctx) {
369 return ctx.prop.props.limit === 1 ? formValue[0] || '' : formValue;
370 }
371 },
372 props: {
373 limit: {
374 type: Number,
375 "default": 0
376 },
377 formCreateInject: {
378 type: Object,
379 required: true
380 },
381 value: {
382 type: Array,
383 "default": function _default() {
384 return [];
385 }
386 },
387 onSuccess: {
388 type: Function,
389 required: true
390 },
391 onHandle: {
392 type: Function,
393 "default": function _default(file) {
394 this.previewImage = file.url;
395 this.previewVisible = true;
396 }
397 },
398 modalTitle: String,
399 previewMask: undefined
400 },
401 data: function data() {
402 var fileList = this.value.map(parseFile);
403 return {
404 defaultUploadList: fileList,
405 previewImage: '',
406 previewVisible: false,
407 uploadList: fileList.map(parseUpload)
408 };
409 },
410 watch: {
411 value: function value(n) {
412 var fileList = n.map(parseFile);
413 this.$refs.upload.sFileList = fileList;
414 this.uploadList = fileList.map(parseUpload);
415 }
416 },
417 methods: {
418 handleChange: function handleChange(_ref) {
419 var file = _ref.file,
420 fileList = _ref.fileList;
421 var list = this.uploadList;
422
423 if (file.status === 'done') {
424 this.onSuccess(file, fileList);
425 if (file.url) list.push({
426 url: file.url,
427 file: fileList[fileList.length - 1]
428 });
429 this.input();
430 } else if (file.status === 'removed') {
431 list.forEach(function (v, i) {
432 if (v.file === file) {
433 list.splice(i, 1);
434 }
435 });
436 this.input();
437 }
438 },
439 input: function input() {
440 this.$emit('input', this.uploadList.map(function (v) {
441 return v.url;
442 }));
443 }
444 },
445 render: function render() {
446 var _this = this;
447
448 var h = arguments[0];
449 var isShow = !this.limit || this.limit > this.uploadList.length;
450
451 var ctx = _objectSpread2({}, this.formCreateInject.prop);
452
453 ctx.on = deepExtend({}, ctx.on || {});
454 return h("div", [h("AUpload", helper([{}, ctx, {
455 "on": {
456 "preview": this.onHandle.bind(this),
457 "change": this.handleChange
458 },
459 "ref": "upload",
460 "attrs": {
461 "defaultFileList": this.defaultUploadList
462 }
463 }]), [isShow ? h("template", {
464 "slot": "default"
465 }, [this.$slots["default"] || h("AIcon", {
466 "attrs": {
467 "type": "plus"
468 }
469 })]) : null, getSlot(this.$slots, ['default'])]), h("aModal", {
470 "attrs": {
471 "mask": this.previewMask,
472 "title": this.modalTitle,
473 "footer": null
474 },
475 "model": {
476 value: _this.previewVisible,
477 callback: function callback($$v) {
478 _this.previewVisible = $$v;
479 }
480 }
481 }, [h("img", {
482 "style": "width: 100%",
483 "attrs": {
484 "src": this.previewImage
485 }
486 })])]);
487 }
488 };
489
490 function styleInject(css, ref) {
491 if (ref === void 0) ref = {};
492 var insertAt = ref.insertAt;
493
494 if (!css || typeof document === 'undefined') {
495 return;
496 }
497
498 var head = document.head || document.getElementsByTagName('head')[0];
499 var style = document.createElement('style');
500 style.type = 'text/css';
501
502 if (insertAt === 'top') {
503 if (head.firstChild) {
504 head.insertBefore(style, head.firstChild);
505 } else {
506 head.appendChild(style);
507 }
508 } else {
509 head.appendChild(style);
510 }
511
512 if (style.styleSheet) {
513 style.styleSheet.cssText = css;
514 } else {
515 style.appendChild(document.createTextNode(css));
516 }
517 }
518
519 var css_248z = "._fc-frame .fc-files img {\n width: 100%;\n height: 100%;\n display: inline-block;\n vertical-align: top;\n}\n\n._fc-frame .fc-upload-cover {\n opacity: 0;\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n background: rgba(0, 0, 0, .6);\n transition: opacity .3s;\n}\n\n._fc-frame .fc-upload-cover i {\n color: #fff;\n font-size: 20px;\n cursor: pointer;\n margin: 0 2px;\n}\n\n._fc-frame .fc-files:hover .fc-upload-cover {\n opacity: 1;\n}\n\n._fc-frame .ant-upload {\n display: block;\n}\n\n._fc-frame .fc-upload-btn, .fc-files {\n display: inline-block;\n width: 104px;\n height: 104px;\n text-align: center;\n line-height: 104px;\n border: 1px solid #c0ccda;\n border-radius: 4px;\n overflow: hidden;\n background: #fff;\n position: relative;\n box-shadow: 2px 2px 5px rgba(0, 0, 0, .1);\n margin-right: 4px;\n box-sizing: border-box;\n}\n";
520 styleInject(css_248z);
521
522 var NAME$1 = 'fcFrame';
523 var Frame = {
524 name: NAME$1,
525 props: {
526 formCreateInject: {
527 type: Object,
528 required: true
529 },
530 type: {
531 type: String,
532 "default": 'input'
533 },
534 field: String,
535 helper: {
536 type: Boolean,
537 "default": true
538 },
539 disabled: {
540 type: Boolean,
541 "default": false
542 },
543 src: {
544 type: String,
545 required: true
546 },
547 icon: {
548 type: String,
549 "default": 'folder'
550 },
551 width: {
552 type: [Number, String],
553 "default": 500
554 },
555 height: {
556 type: [Number, String],
557 "default": 370
558 },
559 maxLength: {
560 type: Number,
561 "default": 0
562 },
563 okBtnText: {
564 type: String,
565 "default": '确定'
566 },
567 closeBtnText: {
568 type: String,
569 "default": '关闭'
570 },
571 modalTitle: String,
572 handleIcon: {
573 type: [String, Boolean],
574 "default": undefined
575 },
576 title: String,
577 allowRemove: {
578 type: Boolean,
579 "default": true
580 },
581 onOpen: {
582 type: Function,
583 "default": function _default() {}
584 },
585 onOk: {
586 type: Function,
587 "default": function _default() {}
588 },
589 onCancel: {
590 type: Function,
591 "default": function _default() {}
592 },
593 onLoad: {
594 type: Function,
595 "default": function _default() {}
596 },
597 onBeforeRemove: {
598 type: Function,
599 "default": function _default() {}
600 },
601 onRemove: {
602 type: Function,
603 "default": function _default() {}
604 },
605 onHandle: {
606 type: Function,
607 "default": function _default(src) {
608 this.previewImage = this.getSrc(src);
609 this.previewVisible = true;
610 }
611 },
612 modal: {
613 type: Object,
614 "default": function _default() {
615 return {};
616 }
617 },
618 srcKey: {
619 type: [String, Number]
620 },
621 value: [Array, String, Number, Object],
622 previewMask: undefined,
623 footer: {
624 type: Boolean,
625 "default": true
626 },
627 reload: {
628 type: Boolean,
629 "default": true
630 },
631 closeBtn: {
632 type: Boolean,
633 "default": true
634 },
635 okBtn: {
636 type: Boolean,
637 "default": true
638 }
639 },
640 data: function data() {
641 return {
642 fileList: toArray(this.value),
643 previewVisible: false,
644 frameVisible: false,
645 previewImage: ''
646 };
647 },
648 watch: {
649 value: function value(n) {
650 this.fileList = toArray(n);
651 },
652 fileList: function fileList(n) {
653 var val = this.maxLength === 1 ? n[0] || '' : n;
654 this.$emit('input', val);
655 this.$emit('change', val);
656 }
657 },
658 methods: {
659 key: function key(unique) {
660 return unique;
661 },
662 closeModal: function closeModal(close) {
663 this.$emit(close ? '$close' : '$ok');
664
665 if (this.reload) {
666 this.$off('$ok');
667 this.$off('$close');
668 }
669
670 this.frameVisible = false;
671 },
672 showModal: function showModal() {
673 if (this.disabled || false === this.onOpen()) return;
674 this.frameVisible = true;
675 },
676 makeInput: function makeInput() {
677 var _this = this;
678
679 var h = this.$createElement;
680 var props = {
681 type: 'text',
682 value: this.fileList.map(function (v) {
683 return _this.getSrc(v);
684 }).toString(),
685 readonly: true
686 };
687 return h("AInput", helper([{}, {
688 "props": props
689 }, {
690 "key": this.key('input')
691 }]), [h("AIcon", {
692 "attrs": {
693 "type": this.icon
694 },
695 "slot": "addonAfter",
696 "on": {
697 "click": this.showModal
698 }
699 }), this.fileList.length ? h("AIcon", {
700 "attrs": {
701 "type": "close-circle"
702 },
703 "slot": "suffix",
704 "on": {
705 "click": function click() {
706 return _this.fileList = [];
707 }
708 }
709 }) : null]);
710 },
711 makeGroup: function makeGroup(children) {
712 var h = this.$createElement;
713 if (!this.maxLength || this.fileList.length < this.maxLength) children.push(this.makeBtn());
714 return h("div", {
715 "key": this.key('group')
716 }, _toConsumableArray(children));
717 },
718 makeItem: function makeItem(index, children) {
719 var h = this.$createElement;
720 return h("div", {
721 "class": 'fc-files',
722 "key": this.key('file' + index)
723 }, _toConsumableArray(children));
724 },
725 valid: function valid(f) {
726 var field = this.formCreateInject.field || this.field;
727 if (field && f !== field) throw new Error('[frame]无效的字段值');
728 },
729 makeIcons: function makeIcons(val, index) {
730 var h = this.$createElement;
731
732 if (this.handleIcon !== false || this.allowRemove === true) {
733 var icons = [];
734 if (this.type !== 'file' && this.handleIcon !== false || this.type === 'file' && this.handleIcon) icons.push(this.makeHandleIcon(val, index));
735 if (this.allowRemove) icons.push(this.makeRemoveIcon(val, index));
736 return h("div", {
737 "class": 'fc-upload-cover',
738 "key": this.key('uc')
739 }, [icons]);
740 }
741 },
742 makeHandleIcon: function makeHandleIcon(val, index) {
743 var _this2 = this;
744
745 var h = this.$createElement;
746 return h("AIcon", {
747 "attrs": {
748 "type": this.handleIcon === true || this.handleIcon === undefined ? 'eye-o' : this.handleIcon
749 },
750 "on": {
751 "click": function click() {
752 return _this2.handleClick(val);
753 }
754 },
755 "key": this.key('hi' + index)
756 });
757 },
758 makeRemoveIcon: function makeRemoveIcon(val, index) {
759 var _this3 = this;
760
761 var h = this.$createElement;
762 return h("AIcon", {
763 "attrs": {
764 "type": "delete"
765 },
766 "on": {
767 "click": function click() {
768 return _this3.handleRemove(val);
769 }
770 },
771 "key": this.key('ri' + index)
772 });
773 },
774 makeFiles: function makeFiles() {
775 var _this4 = this;
776
777 var h = this.$createElement;
778 return this.makeGroup(this.fileList.map(function (src, index) {
779 return _this4.makeItem(index, [h("AIcon", {
780 "attrs": {
781 "type": "file"
782 },
783 "on": {
784 "click": function click() {
785 return _this4.handleClick(src);
786 }
787 }
788 }), _this4.makeIcons(src, index)]);
789 }));
790 },
791 makeImages: function makeImages() {
792 var _this5 = this;
793
794 var h = this.$createElement;
795 return this.makeGroup(this.fileList.map(function (src, index) {
796 return _this5.makeItem(index, [h("img", {
797 "attrs": {
798 "src": _this5.getSrc(src)
799 }
800 }), _this5.makeIcons(src, index)]);
801 }));
802 },
803 makeBtn: function makeBtn() {
804 var _this6 = this;
805
806 var h = this.$createElement;
807 return h("div", {
808 "class": 'fc-upload-btn',
809 "on": {
810 "click": function click() {
811 return _this6.showModal();
812 }
813 },
814 "key": this.key('btn')
815 }, [h("AIcon", {
816 "attrs": {
817 "type": this.icon,
818 "theme": "filled"
819 }
820 })]);
821 },
822 handleClick: function handleClick(src) {
823 return this.onHandle(src);
824 },
825 handleRemove: function handleRemove(src) {
826 if (this.disabled) return;
827
828 if (false !== this.onBeforeRemove(src)) {
829 this.fileList.splice(this.fileList.indexOf(src), 1);
830 this.onRemove(src);
831 }
832 },
833 getSrc: function getSrc(src) {
834 return !this.srcKey ? src : src[this.srcKey];
835 },
836 frameLoad: function frameLoad(iframe) {
837 var _this7 = this;
838
839 this.onLoad(iframe);
840
841 try {
842 if (this.helper === true) {
843 iframe['form_create_helper'] = {
844 close: function close(field) {
845 _this7.valid(field);
846
847 _this7.closeModal();
848 },
849 set: function set(field, value) {
850 _this7.valid(field);
851
852 if (!_this7.disabled) _this7.$emit('input', value);
853 },
854 get: function get(field) {
855 _this7.valid(field);
856
857 return _this7.value;
858 },
859 onOk: function onOk(fn) {
860 return _this7.$on('$ok', fn);
861 },
862 onClose: function onClose(fn) {
863 return _this7.$on('$close', fn);
864 }
865 };
866 }
867 } catch (e) {
868 console.log(e);
869 }
870 },
871 makeFooter: function makeFooter() {
872 var _this8 = this;
873
874 var h = this.$createElement;
875 var _this$$props = this.$props,
876 okBtnText = _this$$props.okBtnText,
877 closeBtnText = _this$$props.closeBtnText,
878 closeBtn = _this$$props.closeBtn,
879 okBtn = _this$$props.okBtn,
880 footer = _this$$props.footer;
881 var node = [];
882 if (!footer) return node;
883 if (closeBtn) node.push(h("AButton", {
884 "on": {
885 "click": function click() {
886 return _this8.onCancel() !== false && _this8.closeModal(true);
887 }
888 }
889 }, [closeBtnText]));
890 if (okBtn) node.push(h("AButton", {
891 "attrs": {
892 "type": "primary"
893 },
894 "on": {
895 "click": function click() {
896 return _this8.onOk() !== false && _this8.closeModal();
897 }
898 }
899 }, [okBtnText]));
900 return node;
901 }
902 },
903 render: function render() {
904 var _this9 = this;
905
906 var h = arguments[0];
907 var type = this.type;
908 var Node;
909 if (type === 'input') Node = this.makeInput();else if (type === 'image') Node = this.makeImages();else Node = this.makeFiles();
910 var _this$$props2 = this.$props,
911 _this$$props2$width = _this$$props2.width,
912 width = _this$$props2$width === void 0 ? '30%' : _this$$props2$width,
913 height = _this$$props2.height,
914 src = _this$$props2.src,
915 title = _this$$props2.title,
916 modalTitle = _this$$props2.modalTitle;
917 this.$nextTick(function () {
918 if (_this9.$refs.frame) {
919 _this9.frameLoad(_this9.$refs.frame.contentWindow || {});
920 }
921 });
922 return h("div", {
923 "class": "_fc-frame"
924 }, [Node, h("aModal", {
925 "attrs": {
926 "mask": this.previewMask,
927 "title": modalTitle,
928 "footer": null
929 },
930 "model": {
931 value: _this9.previewVisible,
932 callback: function callback($$v) {
933 _this9.previewVisible = $$v;
934 }
935 }
936 }, [h("img", {
937 "attrs": {
938 "alt": "example",
939 "src": this.previewImage
940 },
941 "style": "width: 100%"
942 })]), h("aModal", helper([{}, {
943 "props": _objectSpread2({
944 width: width,
945 title: title
946 }, this.modal)
947 }, {
948 "attrs": {
949 "visible": this.frameVisible
950 },
951 "on": {
952 "cancel": function cancel() {
953 return _this9.closeModal(true);
954 }
955 }
956 }]), [this.frameVisible || !this.reload ? h("iframe", {
957 "ref": "frame",
958 "attrs": {
959 "src": src,
960 "frameborder": "0"
961 },
962 "style": {
963 'height': height,
964 'border': '0 none',
965 'width': '100%'
966 }
967 }) : null, h("div", {
968 "slot": "footer"
969 }, [this.makeFooter()])])]);
970 },
971 mounted: function mounted() {
972 this.$on('fc.closeModal', this.closeModal);
973 }
974 };
975
976 var NAME$2 = 'fcGroup';
977 var Group = {
978 name: NAME$2,
979 props: {
980 field: String,
981 rule: [Array, Object],
982 rules: Array,
983 expand: Number,
984 options: Object,
985 formCreateInject: {
986 type: Object,
987 required: true
988 },
989 button: {
990 type: Boolean,
991 "default": true
992 },
993 max: {
994 type: Number,
995 "default": 0
996 },
997 min: {
998 type: Number,
999 "default": 0
1000 },
1001 value: {
1002 type: Array,
1003 "default": function _default() {
1004 return [];
1005 }
1006 },
1007 disabled: {
1008 type: Boolean,
1009 "default": false
1010 },
1011 syncDisabled: {
1012 type: Boolean,
1013 "default": true
1014 },
1015 fontSize: {
1016 type: Number,
1017 "default": 28
1018 },
1019 onBeforeRemove: {
1020 type: Function,
1021 "default": function _default() {}
1022 },
1023 onBeforeAdd: {
1024 type: Function,
1025 "default": function _default() {}
1026 }
1027 },
1028 data: function data() {
1029 return {
1030 len: 0,
1031 cacheRule: {},
1032 cacheValue: {}
1033 };
1034 },
1035 computed: {
1036 formRule: function formRule() {
1037 if (this.rule) {
1038 return Array.isArray(this.rule) ? this.rule : [this.rule];
1039 }
1040
1041 if (this.rules) {
1042 return this.rules;
1043 }
1044
1045 return [];
1046 }
1047 },
1048 watch: {
1049 disabled: function disabled(n) {
1050 if (this.syncDisabled) {
1051 var lst = this.cacheRule;
1052 Object.keys(lst).forEach(function (k) {
1053 lst[k].$f.disabled(n);
1054 });
1055 }
1056 },
1057 expand: function expand(n) {
1058 var d = n - this.value.length;
1059
1060 if (d > 0) {
1061 this.expandRule(d);
1062 }
1063 },
1064 value: function value(n) {
1065 var _this = this;
1066
1067 n = n || [];
1068 var keys = Object.keys(this.cacheRule),
1069 total = keys.length,
1070 len = total - n.length;
1071
1072 if (len < 0) {
1073 for (var i = len; i < 0; i++) {
1074 this.addRule(n.length + i);
1075 }
1076
1077 for (var _i = 0; _i < total; _i++) {
1078 this.setValue(keys[_i], n[_i]);
1079 }
1080 } else {
1081 if (len > 0) {
1082 for (var _i2 = 0; _i2 < len; _i2++) {
1083 this.removeRule(keys[total - _i2 - 1]);
1084 }
1085
1086 this.subForm();
1087 }
1088
1089 n.forEach(function (val, i) {
1090 _this.setValue(keys[i], n[i]);
1091 });
1092 }
1093 }
1094 },
1095 methods: {
1096 _value: function _value(v) {
1097 return v && hasProperty(v, this.field) ? v[this.field] : v;
1098 },
1099 cache: function cache(k, val) {
1100 this.cacheValue[k] = JSON.stringify(val);
1101 },
1102 input: function input(value) {
1103 this.$emit('input', value);
1104 this.$emit('change', value);
1105 },
1106 formData: function formData(key, _formData) {
1107 var _this2 = this;
1108
1109 var cacheRule = this.cacheRule;
1110 var keys = Object.keys(cacheRule);
1111
1112 if (keys.filter(function (k) {
1113 return cacheRule[k].$f;
1114 }).length !== keys.length) {
1115 return;
1116 }
1117
1118 var value = keys.map(function (k) {
1119 var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
1120 var value = _this2.field ? data[_this2.field] || null : data;
1121
1122 _this2.cache(k, value);
1123
1124 return value;
1125 });
1126 this.input(value);
1127 },
1128 setValue: function setValue(key, value) {
1129 var field = this.field,
1130 $f = this.cacheRule[key].$f;
1131
1132 if (field) {
1133 value = _defineProperty({}, field, this._value(value));
1134 }
1135
1136 if (this.cacheValue[key] === JSON.stringify(field ? value[field] : value)) {
1137 return;
1138 }
1139
1140 this.cache(key, value);
1141 $f.coverValue(value || {});
1142 },
1143 addRule: function addRule(i, emit) {
1144 var _this3 = this;
1145
1146 var rule = this.formCreateInject.form.copyRules(this.formRule);
1147 var options = this.options ? _objectSpread2({}, this.options) : {
1148 submitBtn: false,
1149 resetBtn: false
1150 };
1151 options.formData = this.field ? _defineProperty({}, this.field, this._value(this.value[i])) : this.value[i] || {};
1152 this.$set(this.cacheRule, ++this.len, {
1153 rule: rule,
1154 options: options
1155 });
1156
1157 if (emit) {
1158 this.$nextTick(function () {
1159 return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
1160 });
1161 }
1162 },
1163 add$f: function add$f(i, key, $f) {
1164 var _this4 = this;
1165
1166 this.cacheRule[key].$f = $f;
1167 this.subForm();
1168 this.$nextTick(function () {
1169 if (_this4.syncDisabled) {
1170 $f.disabled(_this4.disabled);
1171 }
1172
1173 _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
1174 });
1175 },
1176 subForm: function subForm() {
1177 var _this5 = this;
1178
1179 this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
1180 return _this5.cacheRule[k].$f;
1181 }));
1182 },
1183 removeRule: function removeRule(key, emit) {
1184 var _this6 = this;
1185
1186 var index = Object.keys(this.cacheRule).indexOf(key);
1187 this.$delete(this.cacheRule, key);
1188 this.$delete(this.cacheValue, key);
1189
1190 if (emit) {
1191 this.$nextTick(function () {
1192 return _this6.$emit('remove', index);
1193 });
1194 }
1195 },
1196 add: function add(i) {
1197 if (this.disabled || false === this.onBeforeAdd(this.value)) {
1198 return;
1199 }
1200
1201 this.addRule(i, true);
1202 },
1203 del: function del(index, key) {
1204 if (this.disabled || false === this.onBeforeRemove(this.value)) {
1205 return;
1206 }
1207
1208 this.removeRule(key, true);
1209 this.subForm();
1210 this.value.splice(index, 1);
1211 this.input(this.value);
1212 },
1213 addIcon: function addIcon(key) {
1214 var h = this.$createElement;
1215 return h("AIcon", {
1216 "key": "a".concat(key),
1217 "attrs": {
1218 "type": "plus-circle"
1219 },
1220 "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer', ";"),
1221 "on": {
1222 "click": this.add
1223 }
1224 });
1225 },
1226 delIcon: function delIcon(index, key) {
1227 var _this7 = this;
1228
1229 var h = this.$createElement;
1230 return h("AIcon", {
1231 "key": "d".concat(key),
1232 "attrs": {
1233 "type": "minus-circle"
1234 },
1235 "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
1236 "on": {
1237 "click": function click() {
1238 return _this7.del(index, key);
1239 }
1240 }
1241 });
1242 },
1243 makeIcon: function makeIcon(total, index, key) {
1244 var _this8 = this;
1245
1246 if (this.$scopedSlots.button) {
1247 return this.$scopedSlots.button({
1248 total: total,
1249 index: index,
1250 vm: this,
1251 key: key,
1252 del: function del() {
1253 return _this8.del(index, key);
1254 },
1255 add: this.add
1256 });
1257 }
1258
1259 if (index === 0) {
1260 return [this.max !== 0 && total >= this.max ? null : this.addIcon(key), this.min === 0 || total > this.min ? this.delIcon(index, key) : null];
1261 }
1262
1263 if (index >= this.min) {
1264 return this.delIcon(index, key);
1265 }
1266 },
1267 emitEvent: function emitEvent(name, args, index, key) {
1268 this.$emit.apply(this, [name].concat(_toConsumableArray(args), [this.cacheRule[key].$f, index]));
1269 },
1270 expandRule: function expandRule(n) {
1271 for (var i = 0; i < n; i++) {
1272 this.value.push(this.field ? null : {});
1273 }
1274 }
1275 },
1276 created: function created() {
1277 var d = (this.expand || 0) - this.value.length;
1278
1279 if (d > 0) {
1280 this.expandRule(d);
1281 }
1282
1283 for (var i = 0; i < this.value.length; i++) {
1284 this.addRule(i);
1285 }
1286 },
1287 render: function render() {
1288 var _this9 = this;
1289
1290 var h = arguments[0];
1291 var keys = Object.keys(this.cacheRule);
1292 var button = this.button;
1293 return keys.length === 0 ? this.$scopedSlots["default"] ? this.$scopedSlots["default"]({
1294 vm: this,
1295 add: this.add
1296 }) : h("AIcon", {
1297 "key": 'a_def',
1298 "attrs": {
1299 "type": "plus-circle"
1300 },
1301 "style": "font-size:".concat(this.fontSize, "px;vertical-align:middle;color:").concat(this.disabled ? '#c9cdd4;cursor: not-allowed' : '#606266;cursor:pointer', ";"),
1302 "on": {
1303 "click": this.add
1304 }
1305 }) : h("div", {
1306 "key": 'con'
1307 }, [keys.map(function (key, index) {
1308 var _this9$cacheRule$key = _this9.cacheRule[key],
1309 rule = _this9$cacheRule$key.rule,
1310 options = _this9$cacheRule$key.options;
1311 return h("ARow", {
1312 "attrs": {
1313 "align": "middle",
1314 "type": "flex"
1315 },
1316 "key": key,
1317 "style": "border-bottom:1px dashed #d9d9d9;margin-bottom:10px;"
1318 }, [h("ACol", {
1319 "attrs": {
1320 "span": button ? 20 : 24
1321 }
1322 }, [h("FormCreate", helper([{
1323 "key": key
1324 }, {
1325 "on": {
1326 'update:value': function updateValue(formData) {
1327 return _this9.formData(key, formData);
1328 },
1329 'emit-event': function emitEvent(name) {
1330 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1331 args[_key - 1] = arguments[_key];
1332 }
1333
1334 return _this9.emitEvent(name, args, index, key);
1335 },
1336 input: function input($f) {
1337 return _this9.add$f(index, key, $f);
1338 }
1339 }
1340 }, {
1341 "attrs": {
1342 "rule": rule,
1343 "option": options,
1344 "extendOption": true
1345 }
1346 }]))]), button ? h("ACol", {
1347 "attrs": {
1348 "span": 2,
1349 "pull": 1,
1350 "push": 1
1351 }
1352 }, [_this9.makeIcon(keys.length, index, key)]) : null]);
1353 })]);
1354 },
1355 beforeMount: function beforeMount() {
1356 this.$options.components.FormCreate = this.formCreateInject.form.$form();
1357 }
1358 };
1359
1360 var NAME$3 = 'fcSubForm';
1361 var Sub = {
1362 name: NAME$3,
1363 props: {
1364 rule: Array,
1365 options: Object,
1366 formCreateInject: {
1367 type: Object,
1368 required: true
1369 },
1370 value: {
1371 type: Object,
1372 "default": function _default() {
1373 return {};
1374 }
1375 },
1376 disabled: {
1377 type: Boolean,
1378 "default": false
1379 },
1380 syncDisabled: {
1381 type: Boolean,
1382 "default": true
1383 }
1384 },
1385 data: function data() {
1386 return {
1387 cacheRule: {},
1388 cacheValue: {}
1389 };
1390 },
1391 watch: {
1392 disabled: function disabled(n) {
1393 this.syncDisabled && this.cacheRule.$f.disabled(n);
1394 },
1395 value: function value(n) {
1396 this.setValue(n);
1397 }
1398 },
1399 methods: {
1400 formData: function formData(value) {
1401 this.cacheValue = JSON.stringify(value);
1402 this.$emit('input', value);
1403 this.$emit('change', value);
1404 },
1405 setValue: function setValue(value) {
1406 var str = JSON.stringify(value);
1407
1408 if (this.cacheValue === str) {
1409 return;
1410 }
1411
1412 this.cacheValue = str;
1413 this.cacheRule.$f.coverValue(value || {});
1414 },
1415 addRule: function addRule() {
1416 var options = this.options ? this.options : {
1417 submitBtn: false,
1418 resetBtn: false
1419 };
1420 options.formData = _objectSpread2({}, this.value || {});
1421 this.cacheRule = {
1422 rule: this.rule,
1423 options: options
1424 };
1425 },
1426 add$f: function add$f($f) {
1427 var _this = this;
1428
1429 this.cacheRule.$f = $f;
1430 this.subForm();
1431 this.$nextTick(function () {
1432 _this.syncDisabled && $f.disabled(_this.disabled);
1433
1434 _this.$emit('itemMounted', $f);
1435 });
1436 },
1437 subForm: function subForm() {
1438 this.formCreateInject.subForm(this.cacheRule.$f);
1439 },
1440 emitEvent: function emitEvent(name) {
1441 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1442 args[_key - 1] = arguments[_key];
1443 }
1444
1445 this.$emit.apply(this, [name].concat(args));
1446 }
1447 },
1448 created: function created() {
1449 this.addRule();
1450 },
1451 render: function render() {
1452 var h = arguments[0];
1453 var _this$cacheRule = this.cacheRule,
1454 rule = _this$cacheRule.rule,
1455 options = _this$cacheRule.options;
1456 return h("FormCreate", helper([{}, {
1457 "on": {
1458 'update:value': this.formData,
1459 'emit-event': this.emitEvent,
1460 input: this.add$f
1461 }
1462 }, {
1463 "attrs": {
1464 "rule": rule,
1465 "option": options,
1466 "extendOption": true
1467 }
1468 }]));
1469 },
1470 beforeMount: function beforeMount() {
1471 this.$options.components.FormCreate = this.formCreateInject.form.$form();
1472 }
1473 };
1474
1475 var components = [Upload, Frame, Group, Sub];
1476
1477 var checkbox = {
1478 name: 'checkbox',
1479 mergeProp: function mergeProp(ctx) {
1480 var props = ctx.prop.props;
1481 if (!hasProperty(props, 'options')) props.options = ctx.prop.options || [];
1482 }
1483 };
1484
1485 var radio = _objectSpread2(_objectSpread2({}, checkbox), {}, {
1486 name: 'radio'
1487 });
1488
1489 var select = _objectSpread2(_objectSpread2({}, checkbox), {}, {
1490 name: 'select'
1491 });
1492
1493 var _extends$1 = Object.assign || function (a) {
1494 for (var b, c = 1; c < arguments.length; c++) {
1495 for (var d in b = arguments[c], b) {
1496 Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
1497 }
1498 }
1499
1500 return a;
1501 };
1502
1503 function extend() {
1504 return _extends$1.apply(this, arguments);
1505 }
1506
1507 var NAME$4 = 'FormCreate';
1508 function $FormCreate(FormCreate) {
1509 return {
1510 name: NAME$4,
1511 componentName: NAME$4,
1512 model: {
1513 prop: 'api'
1514 },
1515 provide: function provide() {
1516 return {
1517 $pfc: this
1518 };
1519 },
1520 inject: {
1521 $pfc: {
1522 "default": null
1523 }
1524 },
1525 props: {
1526 rule: {
1527 type: Array,
1528 required: true
1529 },
1530 option: {
1531 type: Object,
1532 "default": function _default() {
1533 return {};
1534 }
1535 },
1536 extendOption: Boolean,
1537 value: Object,
1538 api: Object
1539 },
1540 data: function data() {
1541 return {
1542 formData: undefined,
1543 destroyed: false,
1544 validate: {},
1545 $f: undefined,
1546 isShow: true,
1547 unique: 1,
1548 renderRule: _toConsumableArray(this.rule || []),
1549 ctxInject: {},
1550 updateValue: ''
1551 };
1552 },
1553 render: function render() {
1554 return this.formCreate.render();
1555 },
1556 methods: {
1557 _refresh: function _refresh() {
1558 ++this.unique;
1559 },
1560 _renderRule: function _renderRule() {
1561 this.renderRule = _toConsumableArray(this.rule || []);
1562 },
1563 _updateValue: function _updateValue(value) {
1564 if (this.destroyed) return;
1565 this.updateValue = JSON.stringify(value);
1566 this.$emit('update:value', value);
1567 }
1568 },
1569 watch: {
1570 value: {
1571 handler: function handler(n) {
1572 if (JSON.stringify(n) === this.updateValue) return;
1573 this.$f.setValue(n);
1574 },
1575 deep: true
1576 },
1577 option: {
1578 handler: function handler(n) {
1579 this.formCreate.initOptions(n);
1580 this.$f.refresh();
1581 },
1582 deep: true
1583 },
1584 rule: function rule(n) {
1585 var _this = this;
1586
1587 if (n.length === this.renderRule.length && n.every(function (v) {
1588 return _this.renderRule.indexOf(v) > -1;
1589 })) return;
1590 this.formCreate.$handle.reloadRule(n);
1591
1592 this._renderRule();
1593 }
1594 },
1595 beforeCreate: function beforeCreate() {
1596 var _this2 = this;
1597
1598 var _this$$options$propsD = this.$options.propsData,
1599 rule = _this$$options$propsD.rule,
1600 option = _this$$options$propsD.option;
1601 this.formCreate = new FormCreate(this, rule, option);
1602 Object.keys(this.formCreate.prop).forEach(function (k) {
1603 extend(_this2.$options[k], _this2.formCreate.prop[k]);
1604 });
1605 }
1606 };
1607 }
1608
1609 var normalMerge$1 = ['attrs', 'props', 'domProps', 'scopedSlots'];
1610 var toArrayMerge$1 = ['class', 'style', 'directives'];
1611 var functionalMerge$1 = ['on', 'nativeOn'];
1612
1613 var mergeProps = function mergeProps(objects) {
1614 var initial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1615 var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1616
1617 var _normalMerge = [].concat(normalMerge$1, _toConsumableArray(opt['normal'] || []));
1618
1619 var _toArrayMerge = [].concat(toArrayMerge$1, _toConsumableArray(opt['array'] || []));
1620
1621 var _functionalMerge = [].concat(functionalMerge$1, _toConsumableArray(opt['functional'] || []));
1622
1623 var propsMerge = opt['props'] || [];
1624 return objects.reduce(function (a, b) {
1625 for (var key in b) {
1626 if (a[key]) {
1627 if (propsMerge.indexOf(key) > -1) {
1628 a[key] = mergeProps([b[key]], a[key]);
1629 } else if (_normalMerge.indexOf(key) > -1) {
1630 a[key] = _objectSpread2(_objectSpread2({}, a[key]), b[key]);
1631 } else if (_toArrayMerge.indexOf(key) > -1) {
1632 var arrA = a[key] instanceof Array ? a[key] : [a[key]];
1633 var arrB = b[key] instanceof Array ? b[key] : [b[key]];
1634 a[key] = [].concat(_toConsumableArray(arrA), _toConsumableArray(arrB));
1635 } else if (_functionalMerge.indexOf(key) > -1) {
1636 for (var event in b[key]) {
1637 if (a[key][event]) {
1638 var _arrA = a[key][event] instanceof Array ? a[key][event] : [a[key][event]];
1639
1640 var _arrB = b[key][event] instanceof Array ? b[key][event] : [b[key][event]];
1641
1642 a[key][event] = [].concat(_toConsumableArray(_arrA), _toConsumableArray(_arrB));
1643 } else {
1644 a[key][event] = b[key][event];
1645 }
1646 }
1647 } else if (key === 'hook') {
1648 for (var hook in b[key]) {
1649 if (a[key][hook]) {
1650 a[key][hook] = mergeFn$1(a[key][hook], b[key][hook]);
1651 } else {
1652 a[key][hook] = b[key][hook];
1653 }
1654 }
1655 } else {
1656 a[key] = b[key];
1657 }
1658 } else {
1659 if (_normalMerge.indexOf(key) > -1 || _functionalMerge.indexOf(key) > -1 || propsMerge.indexOf(key) > -1) {
1660 a[key] = _objectSpread2({}, b[key]);
1661 } else if (_toArrayMerge.indexOf(key) > -1) {
1662 a[key] = b[key] instanceof Array ? _toConsumableArray(b[key]) : _typeof(b[key]) === 'object' ? _objectSpread2({}, b[key]) : b[key];
1663 } else a[key] = b[key];
1664 }
1665 }
1666
1667 return a;
1668 }, initial);
1669 };
1670
1671 var mergeFn$1 = function mergeFn(fn1, fn2) {
1672 return function () {
1673 fn1 && fn1.apply(this, arguments);
1674 fn2 && fn2.apply(this, arguments);
1675 };
1676 };
1677
1678 var keyAttrs = ['type', 'slot', 'emitPrefix', 'value', 'name', 'native', 'hidden', 'display', 'inject', 'options', 'emit', 'nativeEmit', 'link', 'prefix', 'suffix', 'update', 'sync', 'optionsTo', 'key'];
1679 var arrayAttrs = ['validate', 'children', 'control'];
1680 var normalAttrs = ['effect', 'deep'];
1681 function attrs() {
1682 return [].concat(keyAttrs, _toConsumableArray(normalMerge$1), _toConsumableArray(toArrayMerge$1), _toConsumableArray(functionalMerge$1), arrayAttrs, normalAttrs);
1683 }
1684
1685 function format(type, msg, rule) {
1686 return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : '');
1687 }
1688 function tip(msg, rule) {
1689 console.warn(format('tip', msg, rule));
1690 }
1691 function err(msg, rule) {
1692 console.error(format('err', msg, rule));
1693 }
1694 function logError(e) {
1695 err(e.toString());
1696 console.error(e);
1697 }
1698
1699 var PREFIX = '[[FORM-CREATE-PREFIX-';
1700 var SUFFIX = '-FORM-CREATE-SUFFIX]]';
1701 var $T = '$FN:';
1702 var $TX = '$FNX:';
1703 var FUNCTION = 'function';
1704 function toJson(obj, space) {
1705 return JSON.stringify(deepExtend([], obj, true), function (key, val) {
1706 if (val && val._isVue === true) return undefined;
1707
1708 if (_typeof(val) !== FUNCTION) {
1709 return val;
1710 }
1711
1712 if (hasProperty(val, '__json')) {
1713 return val.__json;
1714 }
1715
1716 if (val.__origin) val = val.__origin;
1717 if (val.__emit) return undefined;
1718 return PREFIX + val + SUFFIX;
1719 }, space);
1720 }
1721
1722 function makeFn(fn) {
1723 return eval('(' + FUNCTION + '(){return ' + fn + ' })()');
1724 }
1725
1726 function parseFn(fn, mode) {
1727 if (fn && is.String(fn) && fn.length > 4) {
1728 var v = fn.trim();
1729 var flag = false;
1730
1731 try {
1732 if (v.indexOf(SUFFIX) > 0 && v.indexOf(PREFIX) === 0) {
1733 v = v.replace(SUFFIX, '').replace(PREFIX, '');
1734 flag = true;
1735 } else if (v.indexOf($T) === 0) {
1736 v = v.replace($T, '');
1737 flag = true;
1738 } else if (v.indexOf($TX) === 0) {
1739 v = makeFn('function($inject){' + v.replace($TX, '') + '}');
1740 v.__json = fn;
1741 v.__inject = true;
1742 return v;
1743 } else if (!mode && v.indexOf(FUNCTION) === 0 && v !== FUNCTION) {
1744 flag = true;
1745 }
1746
1747 if (!flag) return fn;
1748 var val = makeFn(v.indexOf(FUNCTION) === -1 && v.indexOf('(') !== 0 ? FUNCTION + ' ' + v : v);
1749 val.__json = fn;
1750 return val;
1751 } catch (e) {
1752 err("\u89E3\u6790\u5931\u8D25:".concat(v, "\n\nerr: ").concat(e));
1753 return undefined;
1754 }
1755 }
1756
1757 return fn;
1758 }
1759 function parseJson(json, mode) {
1760 return JSON.parse(json, function (k, v) {
1761 if (is.Undef(v) || !v.indexOf) return v;
1762 return parseFn(v, mode);
1763 });
1764 }
1765
1766 function enumerable(value, writable) {
1767 return {
1768 value: value,
1769 enumerable: false,
1770 configurable: false,
1771 writable: !!writable
1772 };
1773 } //todo 优化位置
1774
1775 function copyRule(rule, mode) {
1776 return copyRules([rule], mode || false)[0];
1777 }
1778 function copyRules(rules, mode) {
1779 return deepExtend([], _toConsumableArray(rules), mode || false);
1780 }
1781 function mergeRule(rule, merge) {
1782 mergeProps(Array.isArray(merge) ? merge : [merge], rule, {
1783 array: arrayAttrs,
1784 normal: normalAttrs
1785 });
1786 return rule;
1787 }
1788 function getRule(rule) {
1789 return is.Function(rule.getRule) ? rule.getRule() : rule;
1790 }
1791 function mergeGlobal(target, merge) {
1792 if (!target) return merge;
1793 Object.keys(merge || {}).forEach(function (k) {
1794 if (merge[k]) {
1795 target[k] = mergeRule(target[k] || {}, merge[k]);
1796 }
1797 });
1798 return target;
1799 }
1800 function funcProxy(that, proxy) {
1801 Object.defineProperties(that, Object.keys(proxy).reduce(function (initial, k) {
1802 initial[k] = {
1803 get: function get() {
1804 return proxy[k]();
1805 }
1806 };
1807 return initial;
1808 }, {}));
1809 }
1810 function byCtx(rule) {
1811 return rule.__fc__ || (rule.__origin__ ? rule.__origin__.__fc__ : null);
1812 }
1813 function invoke(fn, def) {
1814 try {
1815 def = fn();
1816 } catch (e) {
1817 logError(e);
1818 }
1819
1820 return def;
1821 }
1822
1823 function toLine(name) {
1824 var line = name.replace(/([A-Z])/g, '-$1').toLocaleLowerCase();
1825 if (line.indexOf('-') === 0) line = line.substr(1);
1826 return line;
1827 }
1828
1829 var id = 0;
1830 function uniqueId() {
1831 return Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now()).concat(++id)).toString(36);
1832 }
1833
1834 function deepSet(data, idx, val) {
1835 var _data = data,
1836 to;
1837 (idx || '').split('.').forEach(function (v) {
1838 if (to) {
1839 if (!_data[to] || _typeof(_data[to]) != 'object') {
1840 _data[to] = {};
1841 }
1842
1843 _data = _data[to];
1844 }
1845
1846 to = v;
1847 });
1848 _data[to] = val;
1849 return _data;
1850 }
1851
1852 function baseRule() {
1853 return {
1854 props: {},
1855 on: {},
1856 options: [],
1857 children: [],
1858 hidden: false,
1859 display: true,
1860 value: undefined
1861 };
1862 }
1863 function creatorFactory(name, init) {
1864 return function (title, field, value) {
1865 var props = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1866 var maker = new Creator(name, title, field, value, props);
1867
1868 if (init) {
1869 if (is.Function(init)) init(maker);else maker.props(init);
1870 }
1871
1872 return maker;
1873 };
1874 }
1875 function Creator(type, title, field, value, props) {
1876 this._data = extend(baseRule(), {
1877 type: type,
1878 title: title,
1879 field: field,
1880 value: value,
1881 props: props || {}
1882 });
1883 this.event = this.on;
1884 }
1885 extend(Creator.prototype, {
1886 getRule: function getRule() {
1887 return this._data;
1888 },
1889 setProp: function setProp(key, value) {
1890 $set(this._data, key, value);
1891 return this;
1892 },
1893 _clone: function _clone() {
1894 var clone = new this.constructor();
1895 clone._data = copyRule(this._data);
1896 return clone;
1897 }
1898 });
1899 function appendProto(attrs) {
1900 attrs.forEach(function (name) {
1901 Creator.prototype[name] = function (key) {
1902 mergeRule(this._data, _defineProperty({}, name, arguments.length < 2 ? key : _defineProperty({}, key, arguments[1])));
1903 return this;
1904 };
1905 });
1906 }
1907 appendProto(attrs());
1908
1909 var commonMaker = creatorFactory('');
1910 function create(type, field, title) {
1911 var make = commonMaker('', field);
1912 make._data.type = type;
1913 make._data.title = title;
1914 return make;
1915 }
1916 function createTmp(template, vm, field, title) {
1917 var make = commonMaker('', field);
1918 make._data.type = 'template';
1919 make._data.template = template;
1920 make._data.title = title;
1921 make._data.vm = vm;
1922 return make;
1923 }
1924 function makerFactory() {
1925 return {
1926 create: create,
1927 createTmp: createTmp,
1928 template: createTmp,
1929 factory: creatorFactory
1930 };
1931 }
1932
1933 function copy(value) {
1934 return deepCopy(value);
1935 }
1936
1937 function Api(h) {
1938 function tidyFields(fields) {
1939 if (is.Undef(fields)) fields = h.fields();else if (!Array.isArray(fields)) fields = [fields];
1940 return fields;
1941 }
1942
1943 function props(fields, key, val) {
1944 tidyFields(fields).forEach(function (field) {
1945 h.getCtxs(field).forEach(function (ctx) {
1946 $set(ctx.rule, key, val);
1947 h.$render.clearCache(ctx);
1948 });
1949 });
1950 }
1951
1952 function allSubForm() {
1953 var subs = h.subForm;
1954 return Object.keys(subs).reduce(function (initial, k) {
1955 var sub = subs[k];
1956 if (!sub) return initial;
1957 if (Array.isArray(sub)) initial.push.apply(initial, _toConsumableArray(sub));else initial.push(sub);
1958 return initial;
1959 }, []);
1960 }
1961
1962 var api = {
1963 helper: {
1964 tidyFields: tidyFields,
1965 props: props
1966 },
1967
1968 get config() {
1969 return h.options;
1970 },
1971
1972 get options() {
1973 return h.options;
1974 },
1975
1976 get form() {
1977 return h.form;
1978 },
1979
1980 get rule() {
1981 return h.rules;
1982 },
1983
1984 get parent() {
1985 return h.vm.$pfc && h.vm.$pfc.$f;
1986 },
1987
1988 get children() {
1989 return allSubForm();
1990 },
1991
1992 formData: function formData(fields) {
1993 return tidyFields(fields).reduce(function (initial, id) {
1994 var ctx = h.getFieldCtx(id);
1995 if (!ctx) return initial;
1996 initial[ctx.field] = copy(ctx.rule.value);
1997 return initial;
1998 }, copy(h.appendData));
1999 },
2000 getValue: function getValue(field) {
2001 var ctx = h.getFieldCtx(field);
2002 if (!ctx) return;
2003 return copy(ctx.rule.value);
2004 },
2005 coverValue: function coverValue(formData) {
2006 h.deferSyncValue(function () {
2007 api.fields().forEach(function (key) {
2008 var ctxs = h.fieldCtx[key];
2009 if (!ctxs) return h.appendData[key] = formData[key];
2010 var flag = hasProperty(formData, key);
2011 ctxs.forEach(function (ctx) {
2012 ctx.rule.value = flag ? formData[key] : undefined;
2013 });
2014 });
2015 });
2016 },
2017 setValue: function setValue(field) {
2018 var formData = field;
2019 if (arguments.length >= 2) formData = _defineProperty({}, field, arguments[1]);
2020 h.deferSyncValue(function () {
2021 Object.keys(formData).forEach(function (key) {
2022 var ctxs = h.fieldCtx[key];
2023 if (!ctxs) return h.appendData[key] = formData[key];
2024 ctxs.forEach(function (ctx) {
2025 ctx.rule.value = formData[key];
2026 });
2027 });
2028 });
2029 },
2030 removeField: function removeField(field) {
2031 var ctx = h.getCtx(field);
2032 h.deferSyncValue(function () {
2033 h.getCtxs(field).forEach(function (ctx) {
2034 ctx.rm();
2035 });
2036 }, true);
2037 return ctx ? ctx.origin : undefined;
2038 },
2039 removeRule: function removeRule(rule) {
2040 var ctx = rule && byCtx(rule);
2041 if (!ctx) return;
2042 ctx.rm();
2043 return ctx.origin;
2044 },
2045 destroy: function destroy() {
2046 h.vm.$el.parentNode && h.vm.$el.parentNode.removeChild(h.vm.$el);
2047 h.vm.$destroy();
2048 },
2049 fields: function fields() {
2050 return h.fields();
2051 },
2052 append: function append(rule, after, child) {
2053 var index = h.sort.length - 1,
2054 rules;
2055 var ctx = h.getCtx(after);
2056
2057 if (ctx) {
2058 if (child) {
2059 rules = ctx.rule.children;
2060 index = ctx.rule.children.length - 1;
2061 } else {
2062 index = ctx.root.indexOf(ctx.origin);
2063 rules = ctx.root;
2064 }
2065 } else rules = h.rules;
2066
2067 rules.splice(index + 1, 0, rule);
2068 },
2069 prepend: function prepend(rule, after, child) {
2070 var index = 0,
2071 rules;
2072 var ctx = h.getCtx(after);
2073
2074 if (ctx) {
2075 if (child) {
2076 rules = ctx.rule.children;
2077 } else {
2078 index = ctx.root.indexOf(ctx.origin);
2079 rules = ctx.root;
2080 }
2081 } else rules = h.rules;
2082
2083 rules.splice(index, 0, rule);
2084 },
2085 hidden: function hidden(state, fields) {
2086 props(fields, 'hidden', !!state);
2087 h.refresh();
2088 },
2089 hiddenStatus: function hiddenStatus(id) {
2090 var ctx = h.getCtx(id);
2091 if (!ctx) return;
2092 return !!ctx.rule.hidden;
2093 },
2094 display: function display(state, fields) {
2095 props(fields, 'display', !!state);
2096 h.refresh();
2097 },
2098 displayStatus: function displayStatus(id) {
2099 var ctx = h.getCtx(id);
2100 if (!ctx) return;
2101 return !!ctx.rule.display;
2102 },
2103 disabled: function disabled(_disabled, fields) {
2104 tidyFields(fields).forEach(function (field) {
2105 h.getCtxs(field).forEach(function (ctx) {
2106 $set(ctx.rule.props, 'disabled', !!_disabled);
2107 });
2108 });
2109 h.refresh();
2110 },
2111 model: function model(origin) {
2112 return h.fields().reduce(function (initial, key) {
2113 var ctx = h.fieldCtx[key][0];
2114 initial[key] = origin ? ctx.origin : ctx.rule;
2115 return initial;
2116 }, {});
2117 },
2118 component: function component(origin) {
2119 return Object.keys(h.nameCtx).reduce(function (initial, key) {
2120 var ctx = h.nameCtx[key].map(function (ctx) {
2121 return origin ? ctx.origin : ctx.rule;
2122 });
2123 initial[key] = ctx.length === 1 ? ctx[0] : ctx;
2124 return initial;
2125 }, {});
2126 },
2127 bind: function bind() {
2128 return api.form;
2129 },
2130 reload: function reload(rules) {
2131 h.reloadRule(rules);
2132 },
2133 updateOptions: function updateOptions(options) {
2134 h.fc.updateOptions(options);
2135 api.refresh();
2136 },
2137 onSubmit: function onSubmit(fn) {
2138 api.updateOptions({
2139 onSubmit: fn
2140 });
2141 },
2142 sync: function sync(field) {
2143 if (Array.isArray(field)) {
2144 field.forEach(function (v) {
2145 return api.sync(v);
2146 });
2147 return;
2148 }
2149
2150 var ctxs = is.Object(field) ? byCtx(field) : h.getCtxs(field);
2151
2152 if (!ctxs) {
2153 return;
2154 }
2155
2156 ctxs = Array.isArray(ctxs) ? ctxs : [ctxs];
2157 ctxs.forEach(function (ctx) {
2158 if (!ctx.deleted) {
2159 var subForm = h.subForm[ctx.id];
2160
2161 if (subForm) {
2162 if (Array.isArray(subForm)) {
2163 subForm.forEach(function (form) {
2164 form.refresh();
2165 });
2166 } else if (subForm) {
2167 subForm.refresh();
2168 }
2169 } //ctx.updateKey(true);
2170
2171
2172 h.$render.clearCache(ctx);
2173 }
2174 });
2175 h.refresh();
2176 },
2177 refresh: function refresh() {
2178 allSubForm().forEach(function (sub) {
2179 sub.refresh();
2180 });
2181 h.$render.clearCacheAll();
2182 h.refresh();
2183 },
2184 refreshOptions: function refreshOptions() {
2185 h.$manager.updateOptions(h.options);
2186 api.refresh();
2187 },
2188 hideForm: function hideForm(hide) {
2189 $set(h.vm, 'isShow', !hide);
2190 },
2191 changeStatus: function changeStatus() {
2192 return h.changeStatus;
2193 },
2194 clearChangeStatus: function clearChangeStatus() {
2195 h.changeStatus = false;
2196 },
2197 updateRule: function updateRule(id, rule) {
2198 h.getCtxs(id).forEach(function (ctx) {
2199 extend(ctx.rule, rule);
2200 });
2201 },
2202 updateRules: function updateRules(rules) {
2203 Object.keys(rules).forEach(function (id) {
2204 api.updateRule(id, rules[id]);
2205 });
2206 },
2207 mergeRule: function mergeRule$1(id, rule) {
2208 h.getCtxs(id).forEach(function (ctx) {
2209 mergeRule(ctx.rule, rule);
2210 });
2211 },
2212 mergeRules: function mergeRules(rules) {
2213 Object.keys(rules).forEach(function (id) {
2214 api.mergeRule(id, rules[id]);
2215 });
2216 },
2217 getRule: function getRule(id, origin) {
2218 var ctx = h.getCtx(id);
2219
2220 if (ctx) {
2221 return origin ? ctx.origin : ctx.rule;
2222 }
2223 },
2224 updateValidate: function updateValidate(id, validate, merge) {
2225 if (merge) {
2226 api.mergeRule(id, {
2227 validate: validate
2228 });
2229 } else {
2230 props(id, 'validate', validate);
2231 }
2232 },
2233 updateValidates: function updateValidates(validates, merge) {
2234 Object.keys(validates).forEach(function (id) {
2235 api.updateValidate(id, validates[id], merge);
2236 });
2237 },
2238 refreshValidate: function refreshValidate() {
2239 h.vm.validate = {};
2240 api.refresh();
2241 },
2242 resetFields: function resetFields(fields) {
2243 tidyFields(fields).forEach(function (field) {
2244 h.getCtxs(field).forEach(function (ctx) {
2245 h.$render.clearCache(ctx);
2246 ctx.rule.value = copy(ctx.defaultValue);
2247 h.refreshControl(ctx);
2248 });
2249 });
2250 },
2251 method: function method(id, name) {
2252 var el = api.el(id);
2253 if (!el || !el[name]) throw new Error(format('err', "".concat(name, "\u65B9\u6CD5\u4E0D\u5B58\u5728")));
2254 return function () {
2255 return el[name].apply(el, arguments);
2256 };
2257 },
2258 exec: function exec(id, name) {
2259 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
2260 args[_key - 2] = arguments[_key];
2261 }
2262
2263 return invoke(function () {
2264 return api.method(id, name).apply(void 0, args);
2265 });
2266 },
2267 toJson: function toJson$1(space) {
2268 return toJson(api.rule, space);
2269 },
2270 trigger: function trigger(id, event) {
2271 var el = api.el(id);
2272
2273 for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
2274 args[_key2 - 2] = arguments[_key2];
2275 }
2276
2277 el && el.$emit.apply(el, [event].concat(args));
2278 },
2279 el: function el(id) {
2280 var ctx = h.getCtx(id);
2281 if (ctx) return ctx.el || h.vm.$refs[ctx.ref];
2282 },
2283 closeModal: function closeModal(id) {
2284 var el = api.el(id);
2285 el && el.$emit && el.$emit('close-modal');
2286 },
2287 getSubForm: function getSubForm(field) {
2288 var ctx = h.getCtx(field);
2289 return ctx ? h.subForm[ctx.id] : undefined;
2290 },
2291 nextTick: function nextTick(fn) {
2292 h.bus.$once('next-tick', fn);
2293 h.refresh();
2294 },
2295 nextRefresh: function nextRefresh(fn) {
2296 h.nextRefresh();
2297 fn && invoke(fn);
2298 }
2299 };
2300 ['on', 'once', 'off', 'set'].forEach(function (n) {
2301 api[n] = function () {
2302 var _h$vm;
2303
2304 (_h$vm = h.vm)["$".concat(n)].apply(_h$vm, arguments);
2305 };
2306 });
2307 api.changeValue = api.changeField = api.setValue;
2308 return api;
2309 }
2310
2311 function useCache(Render) {
2312 extend(Render.prototype, {
2313 initCache: function initCache() {
2314 this.clearCacheAll();
2315 },
2316 clearCache: function clearCache(ctx) {
2317 if (!this.cache[ctx.id]) {
2318 ctx.parent && this.clearCache(ctx.parent);
2319 return;
2320 }
2321
2322 if (this.cache[ctx.id].use === true || this.cache[ctx.id].parent) {
2323 this.$handle.refresh();
2324 }
2325
2326 var parent = this.cache[ctx.id].parent;
2327 this.cache[ctx.id] = null;
2328 parent && this.clearCache(parent);
2329 },
2330 clearCacheAll: function clearCacheAll() {
2331 this.cache = {};
2332 },
2333 setCache: function setCache(ctx, vnode, parent) {
2334 this.cache[ctx.id] = {
2335 vnode: vnode,
2336 use: false,
2337 parent: parent,
2338 slot: ctx.rule.slot
2339 };
2340 },
2341 getCache: function getCache(ctx) {
2342 var cache = this.cache[ctx.id];
2343 cache.use = true;
2344 return cache.vnode;
2345 }
2346 });
2347 }
2348
2349 function toCase(str) {
2350 var to = str.replace(/(-[a-z])/g, function (v) {
2351 return v.replace('-', '').toLocaleUpperCase();
2352 });
2353 return lower(to);
2354 }
2355 function lower(str) {
2356 return str.replace(str[0], str[0].toLowerCase());
2357 }
2358
2359 function useRender(Render) {
2360 extend(Render.prototype, {
2361 initRender: function initRender() {
2362 this.tempList = {};
2363 this.clearOrgChildren();
2364 },
2365 initOrgChildren: function initOrgChildren() {
2366 var ctxs = this.$handle.ctxs;
2367 this.orgChildren = Object.keys(ctxs).reduce(function (initial, id) {
2368 if (ctxs[id].parser.loadChildren !== false) {
2369 var children = ctxs[id].rule.children;
2370 initial[id] = is.trueArray(children) ? _toConsumableArray(children) : [];
2371 }
2372
2373 return initial;
2374 }, {});
2375 },
2376 clearOrgChildren: function clearOrgChildren() {
2377 this.orgChildren = {};
2378 },
2379 render: function render() {
2380 var _this = this;
2381
2382 if (!this.vm.isShow) {
2383 return;
2384 }
2385
2386 this.$h = this.vm.$createElement;
2387 this.$manager.beforeRender();
2388 var vn;
2389
2390 var make = function make() {
2391 return _this.renderList();
2392 };
2393
2394 make.renderSlot = function (slot) {
2395 return _this.renderList(slot);
2396 };
2397
2398 make.renderName = function (name) {
2399 return _this.renderId(name);
2400 };
2401
2402 make.renderField = function (field) {
2403 return _this.renderId(field, 'field');
2404 };
2405
2406 if (this.vm.$scopedSlots.container) {
2407 vn = [this.vm.$scopedSlots.container(make)];
2408 } else {
2409 vn = make();
2410 }
2411
2412 return this.$manager.render(vn);
2413 },
2414 renderList: function renderList(slot) {
2415 var _this2 = this;
2416
2417 return this.sort.map(function (id) {
2418 return slot ? _this2.renderSlot(_this2.$handle.ctxs[id], slot) : _this2.renderCtx(_this2.$handle.ctxs[id]);
2419 }).filter(function (val) {
2420 return val !== undefined;
2421 });
2422 },
2423 makeVm: function makeVm(rule) {
2424 var _this3 = this;
2425
2426 var vm = rule.vm;
2427 if (!vm) return new _vue();else if (is.Function(vm)) return invoke(function () {
2428 return rule.vm(_this3.$handle.getInjectData(rule));
2429 });else if (!vm._isVue) return new _vue(vm);
2430 return vm;
2431 },
2432 mergeGlobal: function mergeGlobal(ctx) {
2433 var g = this.$handle.options.global;
2434 if (!g) return; //todo 缓存配置,更新 option 更新
2435
2436 if (!ctx.cacheConfig) ctx.cacheConfig = g[ctx.originType] || g[ctx.type] || g[ctx.trueType] || {};
2437 ctx.prop = mergeRule({}, [g['*'], ctx.cacheConfig, ctx.prop]);
2438 },
2439 setOptions: function setOptions(ctx) {
2440 if (ctx.prop.optionsTo && ctx.prop.options) {
2441 deepSet(ctx.prop, ctx.prop.optionsTo, ctx.prop.options);
2442 }
2443 },
2444 deepSet: function deepSet$1(ctx) {
2445 var deep = ctx.rule.deep;
2446 deep && Object.keys(deep).sort(function (a, b) {
2447 return a.length < b.length ? -1 : 1;
2448 }).forEach(function (str) {
2449 deepSet(ctx.prop, str, deep[str]);
2450 });
2451 },
2452 setTempProps: function setTempProps(vm, ctx) {
2453 if (!vm.$props) return;
2454 var prop = ctx.prop;
2455 var keys = Object.keys(vm.$props);
2456 var inject = this.injectProp(ctx);
2457 var injectKeys = Object.keys(inject);
2458 keys.forEach(function (key) {
2459 if (hasProperty(prop.props, key)) vm.$props[key] = prop.props[key];else if (injectKeys.indexOf(key) > -1) vm.$props[key] = inject[key];
2460 });
2461 var key = vm.$options.model && vm.$options.model.prop || 'value';
2462
2463 if (keys.indexOf(key) > -1) {
2464 vm.$props[key] = prop.value;
2465 }
2466 },
2467 renderTemp: function renderTemp(ctx) {
2468 var _this4 = this;
2469
2470 if (!_vue.compile) {
2471 tip('当前使用的Vue构建版本不支持compile,无法使用template功能');
2472 return [];
2473 }
2474
2475 var rule = ctx.prop;
2476 var id = ctx.id,
2477 key = ctx.key;
2478
2479 if (!this.tempList[id]) {
2480 if (!ctx.el) {
2481 ctx.el = this.makeVm(rule);
2482 this.vm.$nextTick(function () {
2483 return ctx.parser.mounted(ctx);
2484 });
2485 }
2486
2487 var _vm = ctx.el;
2488 if (ctx.input) _vm.$on(_vm.$options.model && _vm.$options.model.event || 'input', function (value) {
2489 _this4.onInput(ctx, value);
2490 });
2491 this.tempList[id] = {
2492 vm: _vm,
2493 template: _vue.compile(rule.template)
2494 };
2495 }
2496
2497 var _this$tempList$id = this.tempList[id],
2498 vm = _this$tempList$id.vm,
2499 template = _this$tempList$id.template;
2500 this.setTempProps(vm, ctx);
2501 var vn = template.render.call(vm);
2502 if (is.Undef(vn.data)) vn.data = {};
2503 vn.key = key;
2504 vn.data.ref = ctx.ref;
2505 vn.data.key = key;
2506 return vn;
2507 },
2508 parseSide: function parseSide(side) {
2509 return is.Object(side) ? mergeRule({}, side) : side;
2510 },
2511 renderSides: function renderSides(vn, ctx, temp) {
2512 var prop = ctx[temp ? 'rule' : 'prop'];
2513 return [this.renderRule(this.parseSide(prop.prefix)), vn, this.renderRule(this.parseSide(prop.suffix))];
2514 },
2515 renderSlot: function renderSlot(ctx, slot) {
2516 return ctx.rule.slot === slot ? this.renderCtx(ctx) : undefined;
2517 },
2518 renderId: function renderId(name, type) {
2519 var _this5 = this;
2520
2521 var ctxs = this.$handle[type === 'field' ? 'fieldCtx' : 'nameCtx'][name];
2522 return ctxs ? ctxs.map(function (ctx) {
2523 return _this5.renderCtx(ctx, ctx.parent);
2524 }) : undefined;
2525 },
2526 renderCtx: function renderCtx(ctx, parent) {
2527 if (ctx.type === 'hidden') return;
2528 var rule = ctx.rule;
2529
2530 if (!this.cache[ctx.id] || this.cache[ctx.id].slot !== rule.slot) {
2531 var vn;
2532 var cacheFlag = true;
2533 var _type = ctx.trueType;
2534 var none = !(is.Undef(rule.display) || !!rule.display);
2535
2536 if (_type === 'template' && !rule.template) {
2537 vn = this.renderSides(this.renderChildren(ctx), ctx, true);
2538
2539 if (none) {
2540 this.display(vn);
2541 }
2542
2543 vn = this.item(ctx, vn);
2544 } else if (_type === 'fcFragment') {
2545 vn = this.renderChildren(ctx);
2546 } else {
2547 ctx.initProp();
2548 this.mergeGlobal(ctx);
2549 this.$manager.tidyRule(ctx);
2550 this.deepSet(ctx);
2551 this.setOptions(ctx);
2552 this.ctxProp(ctx);
2553 var prop = ctx.prop;
2554 prop.props.formCreateInject = this.injectProp(ctx);
2555
2556 if (prop.hidden) {
2557 this.setCache(ctx, undefined, parent);
2558 return;
2559 }
2560
2561 if (_type === 'template' && prop.template) {
2562 vn = this.renderTemp(ctx);
2563 cacheFlag = false;
2564 } else {
2565 var children = [];
2566
2567 if (ctx.parser.renderChildren) {
2568 children = ctx.parser.renderChildren(ctx);
2569 } else if (ctx.parser.loadChildren !== false) {
2570 children = this.renderChildren(ctx);
2571 }
2572
2573 var slot = 'type-' + toLine(ctx.type);
2574
2575 if (this.vm.$scopedSlots[slot]) {
2576 vn = this.vm.$scopedSlots[slot]({
2577 rule: rule,
2578 prop: prop,
2579 children: children,
2580 api: this.$handle.api,
2581 model: prop.model || {}
2582 });
2583 } else {
2584 vn = ctx.parser.render(children, ctx);
2585 }
2586 }
2587
2588 vn = this.renderSides(vn, ctx);
2589
2590 if (!(!ctx.input && is.Undef(prop["native"])) && prop["native"] !== true) {
2591 vn = this.$manager.makeWrap(ctx, vn);
2592 }
2593
2594 if (none) {
2595 vn = this.display(vn);
2596 }
2597
2598 vn = this.item(ctx, vn);
2599 }
2600
2601 if (cacheFlag) {
2602 this.setCache(ctx, vn, parent);
2603 }
2604
2605 return vn;
2606 }
2607
2608 return this.getCache(ctx);
2609 },
2610 display: function display(vn) {
2611 var _this6 = this;
2612
2613 if (Array.isArray(vn)) {
2614 var data = [];
2615 vn.forEach(function (v) {
2616 if (Array.isArray(v)) return _this6.display(v);
2617 if (_this6.none(v)) data.push(v);
2618 });
2619 return data;
2620 } else {
2621 return this.none(vn);
2622 }
2623 },
2624 none: function none(vn) {
2625 if (vn && vn.data) {
2626 if (Array.isArray(vn.data.style)) {
2627 vn.data.style.push({
2628 display: 'none'
2629 });
2630 } else {
2631 vn.data.style = [vn.data.style, {
2632 display: 'none'
2633 }];
2634 }
2635
2636 return vn;
2637 }
2638 },
2639 item: function item(ctx, vn) {
2640 return this.$h('fcFragment', {
2641 slot: ctx.rule.slot,
2642 key: ctx.key
2643 }, [vn]);
2644 },
2645 injectProp: function injectProp(ctx) {
2646 var _this7 = this;
2647
2648 if (!this.vm.ctxInject[ctx.id]) {
2649 $set(this.vm.ctxInject, ctx.id, {});
2650 }
2651
2652 var inject = this.vm.ctxInject[ctx.id];
2653 extend(inject, {
2654 api: this.$handle.api,
2655 form: this.fc.create,
2656 subForm: function subForm(_subForm) {
2657 _this7.$handle.addSubForm(ctx, _subForm);
2658 },
2659 field: ctx.field,
2660 options: ctx.prop.options,
2661 children: ctx.rule.children,
2662 rule: ctx.rule,
2663 prop: function () {
2664 var temp = _objectSpread2({}, ctx.prop);
2665
2666 temp.on = temp.on ? _objectSpread2({}, temp.on) : {};
2667 delete temp.model;
2668 return temp;
2669 }()
2670 });
2671 return inject;
2672 },
2673 ctxProp: function ctxProp(ctx, custom) {
2674 var _this8 = this;
2675
2676 var ref = ctx.ref,
2677 key = ctx.key,
2678 rule = ctx.rule;
2679 this.$manager.mergeProp(ctx, custom);
2680 ctx.parser.mergeProp(ctx, custom);
2681 var props = [{
2682 ref: ref,
2683 key: rule.key || "".concat(key, "fc"),
2684 slot: undefined,
2685 on: {
2686 'hook:mounted': function hookMounted() {
2687 _this8.onMounted(ctx);
2688 }
2689 }
2690 }];
2691
2692 if (!custom && ctx.input) {
2693 props.push({
2694 model: {
2695 value: this.$handle.getFormData(ctx),
2696 callback: function callback(value) {
2697 _this8.onInput(ctx, value);
2698 },
2699 expression: "formData.".concat(ctx.id)
2700 }
2701 });
2702 }
2703
2704 mergeProps(props, ctx.prop);
2705 return ctx.prop;
2706 },
2707 onMounted: function onMounted(ctx) {
2708 ctx.el = this.vm.$refs[ctx.ref];
2709
2710 if (ctx.el) {
2711 (ctx.el.$el || ctx.el).__rule__ = ctx.rule;
2712 }
2713
2714 ctx.parser.mounted(ctx);
2715 this.$handle.effect(ctx, 'mounted');
2716 },
2717 onInput: function onInput(ctx, value) {
2718 this.$handle.onInput(ctx, value);
2719 },
2720 renderChildren: function renderChildren(ctx) {
2721 var _this9 = this;
2722
2723 var children = ctx.rule.children,
2724 orgChildren = this.orgChildren[ctx.id];
2725
2726 var isRm = function isRm(child) {
2727 return !is.String(child) && child.__fc__ && !_this9.$handle.ctxs[child.__fc__.id];
2728 };
2729
2730 if (!is.trueArray(children) && orgChildren) {
2731 this.$handle.deferSyncValue(function () {
2732 orgChildren.forEach(function (child) {
2733 if (!child) return;
2734
2735 if (isRm(child)) {
2736 _this9.$handle.rmCtx(child.__fc__);
2737 }
2738 });
2739 });
2740 this.orgChildren[ctx.id] = [];
2741 return [];
2742 }
2743
2744 orgChildren && this.$handle.deferSyncValue(function () {
2745 orgChildren.forEach(function (child) {
2746 if (!child) return;
2747
2748 if (children.indexOf(child) === -1 && isRm(child)) {
2749 _this9.$handle.rmCtx(child.__fc__);
2750 }
2751 });
2752 });
2753 return children.map(function (child) {
2754 if (!child) return;
2755 if (is.String(child)) return child;
2756
2757 if (child.__fc__) {
2758 return _this9.renderCtx(child.__fc__, ctx);
2759 }
2760
2761 if (child.type) {
2762 _this9.vm.$nextTick(function () {
2763 _this9.$handle.loadChildren(children, ctx);
2764
2765 _this9.$handle.refresh();
2766 });
2767 }
2768 });
2769 },
2770 defaultRender: function defaultRender(ctx, children) {
2771 var prop = ctx.prop;
2772 if (this.vNode[ctx.type]) return this.vNode[ctx.type](prop, children);
2773 if (this.vNode[ctx.originType]) return this.vNode[ctx.originType](prop, children);
2774 return this.vNode.make(lower(ctx.originType), prop, children);
2775 },
2776 renderRule: function renderRule(rule, children, origin) {
2777 var _this10 = this;
2778
2779 if (!rule) return undefined;
2780 if (is.String(rule)) return rule;
2781 var type;
2782
2783 if (origin) {
2784 type = rule.type;
2785 } else {
2786 type = rule.is;
2787
2788 if (rule.type) {
2789 type = toCase(rule.type);
2790 var alias = this.vNode.aliasMap[type];
2791 if (alias) type = toCase(alias);
2792 }
2793 }
2794
2795 if (!type) return undefined;
2796 var data = [[children]];
2797
2798 if (is.trueArray(rule.children)) {
2799 data.push(rule.children.map(function (v) {
2800 return _this10.renderRule(v);
2801 }));
2802 }
2803
2804 return this.$h(type, _objectSpread2({}, rule), data);
2805 }
2806 });
2807 }
2808
2809 function Render(handle) {
2810 extend(this, {
2811 $handle: handle,
2812 fc: handle.fc,
2813 vm: handle.vm,
2814 $manager: handle.$manager,
2815 vNode: new handle.fc.CreateNode(handle.vm)
2816 });
2817 funcProxy(this, {
2818 options: function options() {
2819 return handle.options;
2820 },
2821 sort: function sort() {
2822 return handle.sort;
2823 }
2824 });
2825 this.initCache();
2826 this.initRender();
2827 }
2828 useCache(Render);
2829 useRender(Render);
2830
2831 function useInject(Handler) {
2832 extend(Handler.prototype, {
2833 parseInjectEvent: function parseInjectEvent(rule, on) {
2834 var inject = rule.inject || this.options.injectEvent;
2835 return this.parseEventLst(rule, on, inject);
2836 },
2837 parseEventLst: function parseEventLst(rule, data, inject, deep) {
2838 var _this = this;
2839
2840 Object.keys(data).forEach(function (k) {
2841 var fn = _this.parseEvent(rule, data[k], inject, deep);
2842
2843 if (fn) {
2844 data[k] = fn;
2845 }
2846 });
2847 return data;
2848 },
2849 parseEvent: function parseEvent(rule, fn, inject, deep) {
2850 if (is.Function(fn) && (inject !== false && !is.Undef(inject) || fn.__inject)) {
2851 return this.inject(rule, fn, inject);
2852 } else if (!deep && Array.isArray(fn) && fn[0] && (is.String(fn[0]) || is.Function(fn[0]))) {
2853 return this.parseEventLst(rule, fn, inject, true);
2854 } else if (is.String(fn)) {
2855 var val = parseFn(fn);
2856
2857 if (val && fn !== val) {
2858 return val.__inject ? this.parseEvent(rule, val, inject, true) : val;
2859 }
2860 }
2861 },
2862 parseEmit: function parseEmit(ctx, on) {
2863 var _this2 = this;
2864
2865 var event = {},
2866 rule = ctx.rule,
2867 emitPrefix = rule.emitPrefix,
2868 field = rule.field,
2869 name = rule.name,
2870 inject = rule.inject;
2871 var emit = rule[on ? 'emit' : 'nativeEmit'] || [];
2872
2873 if (is.trueArray(emit)) {
2874 var emitKey = emitPrefix || field || name;
2875
2876 if (emitKey) {
2877 if (!on) emitKey = "native-".concat(emitKey);
2878 emit.forEach(function (eventName) {
2879 if (!eventName) return;
2880 var eventInject;
2881
2882 if (is.Object(eventName)) {
2883 eventInject = eventName.inject;
2884 eventName = eventName.name;
2885 }
2886
2887 var fieldKey = toLine("".concat(emitKey, "-").concat(eventName));
2888
2889 var fn = function fn() {
2890 var _this2$vm, _this2$vm2;
2891
2892 for (var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++) {
2893 arg[_key] = arguments[_key];
2894 }
2895
2896 (_this2$vm = _this2.vm).$emit.apply(_this2$vm, [fieldKey].concat(arg));
2897
2898 (_this2$vm2 = _this2.vm).$emit.apply(_this2$vm2, ['emit-event', fieldKey].concat(arg));
2899 };
2900
2901 fn.__emit = true;
2902
2903 if (!eventInject && inject === false) {
2904 event[eventName] = fn;
2905 } else {
2906 var _inject = eventInject || inject || _this2.options.injectEvent;
2907
2908 event[eventName] = is.Undef(_inject) ? fn : _this2.inject(rule, fn, _inject);
2909 }
2910 });
2911 }
2912 }
2913
2914 ctx.computed[on ? 'on' : 'nativeOn'] = event;
2915 return event;
2916 },
2917 getInjectData: function getInjectData(self, inject) {
2918 var _this$vm$$options$pro = this.vm.$options.propsData,
2919 option = _this$vm$$options$pro.option,
2920 rule = _this$vm$$options$pro.rule;
2921 return {
2922 api: this.api,
2923 $f: this.api,
2924 rule: rule,
2925 self: self.__origin__,
2926 option: option,
2927 inject: inject
2928 };
2929 },
2930 inject: function inject(self, _fn, _inject2) {
2931 if (_fn.__origin) {
2932 if (this.watching && !this.loading) return _fn;
2933 _fn = _fn.__origin;
2934 }
2935
2936 var h = this;
2937
2938 var fn = function fn() {
2939 var data = h.getInjectData(self, _inject2);
2940
2941 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2942 args[_key2] = arguments[_key2];
2943 }
2944
2945 data.args = [].concat(args);
2946 args.unshift(data);
2947 return _fn.apply(this, args);
2948 };
2949
2950 fn.__origin = _fn;
2951 fn.__json = _fn.__json;
2952 return fn;
2953 }
2954 });
2955 }
2956
2957 var EVENT = ['hook:updated', 'hook:mounted'];
2958 function usePage(Handler) {
2959 extend(Handler.prototype, {
2960 usePage: function usePage() {
2961 var _this = this;
2962
2963 var page = this.options.page;
2964 if (!page) return;
2965 var first = 25;
2966 var limit = getLimit(this.rules);
2967
2968 if (is.Object(page)) {
2969 if (page.first) first = parseInt(page.first, 10) || first;
2970 if (page.limit) limit = parseInt(page.limit, 10) || limit;
2971 }
2972
2973 extend(this, {
2974 first: first,
2975 limit: limit,
2976 pageEnd: this.rules.length <= first
2977 });
2978 this.bus.$on('page-end', function () {
2979 return _this.vm.$emit('page-end', _this.api);
2980 });
2981 this.pageLoad();
2982 },
2983 pageLoad: function pageLoad() {
2984 var _this2 = this;
2985
2986 var pageFn = function pageFn() {
2987 if (_this2.pageEnd) {
2988 _this2.vm.$off(EVENT, pageFn);
2989
2990 _this2.bus.$emit('page-end');
2991 } else {
2992 _this2.first += _this2.limit;
2993 _this2.pageEnd = _this2.rules.length <= _this2.first;
2994
2995 _this2.loadRule();
2996
2997 _this2.refresh();
2998 }
2999 };
3000
3001 this.vm.$on(EVENT, pageFn);
3002 }
3003 });
3004 }
3005
3006 function getLimit(rules) {
3007 return rules.length < 31 ? 31 : Math.ceil(rules.length / 3);
3008 }
3009
3010 function useRender$1(Handler) {
3011 extend(Handler.prototype, {
3012 clearNextTick: function clearNextTick() {
3013 this.nextTick && clearTimeout(this.nextTick);
3014 this.nextTick = null;
3015 },
3016 bindNextTick: function bindNextTick(fn) {
3017 var _this = this;
3018
3019 this.clearNextTick();
3020 this.nextTick = setTimeout(function () {
3021 fn();
3022 _this.nextTick = null;
3023 }, 10);
3024 },
3025 render: function render() {
3026 // console.warn('%c render', 'color:green');
3027 ++this.loadedId;
3028 if (this.vm.unique > 0) return this.$render.render();else {
3029 this.vm.unique = 1;
3030 return [];
3031 }
3032 }
3033 });
3034 }
3035
3036 function bind(ctx) {
3037 Object.defineProperties(ctx.origin, {
3038 __fc__: enumerable(ctx, true)
3039 });
3040 }
3041
3042 function RuleContext(handle, rule) {
3043 var id = uniqueId();
3044 extend(this, {
3045 id: id,
3046 ref: id,
3047 wrapRef: id + 'fi',
3048 rule: rule,
3049 origin: rule.__origin__ || rule,
3050 name: rule.name,
3051 watch: [],
3052 linkOn: [],
3053 root: [],
3054 ctrlRule: [],
3055 parent: null,
3056 cacheConfig: null,
3057 prop: _objectSpread2({}, rule),
3058 computed: {},
3059 payload: {},
3060 input: !!rule.field,
3061 el: undefined,
3062 defaultValue: rule.field ? deepCopy(rule.value) : undefined,
3063 field: rule.field || undefined
3064 });
3065 this.updateType();
3066 this.updateKey();
3067 bind(this);
3068 this.update(handle, true);
3069 }
3070 extend(RuleContext.prototype, {
3071 effectData: function effectData(name) {
3072 if (!this.payload[name]) {
3073 this.payload[name] = {};
3074 }
3075
3076 return this.payload[name];
3077 },
3078 clearEffectData: function clearEffectData(name) {
3079 delete this.payload[name];
3080 },
3081 updateKey: function updateKey(flag) {
3082 this.key = uniqueId();
3083 flag && this.parent && this.parent.updateKey(flag);
3084 },
3085 updateType: function updateType() {
3086 this.originType = this.rule.type;
3087 this.type = toCase(this.rule.type);
3088 },
3089 setParser: function setParser(parser) {
3090 this.parser = parser;
3091 parser.init(this);
3092 },
3093 initProp: function initProp() {
3094 var _this = this;
3095
3096 var rule = _objectSpread2({}, this.rule);
3097
3098 delete rule.children;
3099 this.prop = mergeProps([rule].concat(_toConsumableArray(Object.keys(this.payload).map(function (k) {
3100 return _this.payload[k];
3101 })), [this.computed]));
3102 },
3103 check: function check(handle) {
3104 return this.vm === handle.vm;
3105 },
3106 unwatch: function unwatch() {
3107 this.watch.forEach(function (un) {
3108 return un();
3109 });
3110 this.watch = [];
3111 },
3112 unlink: function unlink() {
3113 this.linkOn.forEach(function (un) {
3114 return un();
3115 });
3116 this.linkOn = [];
3117 },
3118 link: function link() {
3119 this.unlink();
3120 this.$handle.appendLink(this);
3121 },
3122 watchTo: function watchTo() {
3123 this.$handle.watchCtx(this);
3124 },
3125 "delete": function _delete() {
3126 var undef = void 0;
3127 this.unwatch();
3128 this.unlink();
3129 this.rmCtrl();
3130 extend(this, {
3131 deleted: true,
3132 prop: _objectSpread2({}, this.rule),
3133 computed: {},
3134 el: undef,
3135 $handle: undef,
3136 $render: undef,
3137 $api: undef,
3138 vm: undef,
3139 vNode: undef,
3140 parent: null,
3141 cacheConfig: null
3142 });
3143 },
3144 rmCtrl: function rmCtrl() {
3145 this.ctrlRule.forEach(function (ctrl) {
3146 return ctrl.__fc__ && ctrl.__fc__.rm();
3147 });
3148 this.ctrlRule = [];
3149 },
3150 rm: function rm() {
3151 var _this2 = this;
3152
3153 var _rm = function _rm() {
3154 var index = _this2.root.indexOf(_this2.origin);
3155
3156 if (index > -1) {
3157 _this2.root.splice(index, 1);
3158
3159 _this2.$handle && _this2.$handle.refresh();
3160 }
3161 };
3162
3163 if (this.deleted) {
3164 _rm();
3165
3166 return;
3167 }
3168
3169 this.$handle.noWatch(function () {
3170 _this2.$handle.deferSyncValue(function () {
3171 _this2.rmCtrl();
3172
3173 _rm();
3174
3175 _this2.$handle.rmCtx(_this2);
3176
3177 extend(_this2, {
3178 root: []
3179 });
3180 }, _this2.input);
3181 });
3182 },
3183 update: function update(handle, init) {
3184 extend(this, {
3185 deleted: false,
3186 $handle: handle,
3187 $render: handle.$render,
3188 $api: handle.api,
3189 vm: handle.vm,
3190 trueType: handle.getType(this.originType),
3191 vNode: handle.$render.vNode,
3192 updated: false
3193 });
3194 !init && this.unwatch();
3195 this.watchTo();
3196 this.link();
3197 }
3198 });
3199
3200 function useLoader(Handler) {
3201 extend(Handler.prototype, {
3202 nextRefresh: function nextRefresh(fn) {
3203 var _this = this;
3204
3205 var id = this.loadedId;
3206 this.vm.$nextTick(function () {
3207 id === _this.loadedId && (fn ? fn() : _this.refresh());
3208 });
3209 },
3210 parseRule: function parseRule(_rule) {
3211 var _this2 = this;
3212
3213 var rule = getRule(_rule);
3214 Object.defineProperties(rule, {
3215 __origin__: enumerable(_rule, true)
3216 });
3217 fullRule(rule);
3218 this.appendValue(rule);
3219 rule.options = Array.isArray(rule.options) ? rule.options : [];
3220 [rule, rule['prefix'], rule['suffix']].forEach(function (item) {
3221 if (!item) {
3222 return;
3223 }
3224
3225 _this2.loadFn(item, rule);
3226 });
3227 this.loadCtrl(rule);
3228
3229 if (rule.update) {
3230 rule.update = parseFn(rule.update);
3231 }
3232
3233 return rule;
3234 },
3235 loadFn: function loadFn(item, rule) {
3236 var _this3 = this;
3237
3238 ['on', 'props', 'nativeOn', 'deep'].forEach(function (k) {
3239 item[k] && _this3.parseInjectEvent(rule, item[k]);
3240 });
3241 },
3242 loadCtrl: function loadCtrl(rule) {
3243 rule.control && rule.control.forEach(function (ctrl) {
3244 if (ctrl.handle) {
3245 ctrl.handle = parseFn(ctrl.handle);
3246 }
3247 });
3248 },
3249 syncProp: function syncProp(ctx) {
3250 var _this4 = this;
3251
3252 var rule = ctx.rule;
3253 is.trueArray(rule.sync) && mergeProps([{
3254 on: rule.sync.reduce(function (pre, prop) {
3255 pre["update:".concat(prop)] = function (val) {
3256 rule.props[prop] = val;
3257
3258 _this4.vm.$emit('sync', prop, val, rule, _this4.fapi);
3259 };
3260
3261 return pre;
3262 }, {})
3263 }], ctx.computed);
3264 },
3265 loadRule: function loadRule() {
3266 var _this5 = this;
3267
3268 // console.warn('%c load', 'color:blue');
3269 this.cycleLoad = false;
3270 this.loading = true;
3271
3272 if (this.pageEnd) {
3273 this.bus.$emit('load-start');
3274 }
3275
3276 this.deferSyncValue(function () {
3277 _this5._loadRule(_this5.rules);
3278
3279 _this5.loading = false;
3280
3281 if (_this5.cycleLoad && _this5.pageEnd) {
3282 return _this5.loadRule();
3283 }
3284
3285 if (_this5.pageEnd) {
3286 _this5.bus.$emit('load-end');
3287 }
3288
3289 _this5.vm._renderRule();
3290
3291 _this5.$render.initOrgChildren();
3292
3293 _this5.syncForm();
3294 });
3295 },
3296 loadChildren: function loadChildren(children, parent) {
3297 this.cycleLoad = false;
3298 this.loading = true;
3299 this.bus.$emit('load-start');
3300
3301 this._loadRule(children, parent);
3302
3303 this.loading = false;
3304
3305 if (this.cycleLoad) {
3306 return this.loadRule();
3307 } else {
3308 this.bus.$emit('load-end');
3309 this.syncForm();
3310 }
3311
3312 this.$render.clearCache(parent);
3313 },
3314 _loadRule: function _loadRule(rules, parent) {
3315 var _this6 = this;
3316
3317 var preIndex = function preIndex(i) {
3318 var pre = rules[i - 1];
3319
3320 if (!pre || !pre.__fc__) {
3321 return i > 0 ? preIndex(i - 1) : -1;
3322 }
3323
3324 var index = _this6.sort.indexOf(pre.__fc__.id);
3325
3326 return index > -1 ? index : preIndex(i - 1);
3327 };
3328
3329 var loadChildren = function loadChildren(children, parent) {
3330 if (is.trueArray(children)) {
3331 _this6._loadRule(children, parent);
3332 }
3333 };
3334
3335 rules.map(function (_rule, index) {
3336 if (parent && (is.String(_rule) || is.Undef(_rule))) return;
3337 if (!_this6.pageEnd && !parent && index >= _this6.first) return;
3338 if (!is.Object(_rule) || !getRule(_rule).type) return err('未定义生成规则的 type 字段', _rule);
3339
3340 if (_rule.__fc__ && _rule.__fc__.root === rules && _this6.ctxs[_rule.__fc__.id]) {
3341 loadChildren(_rule.__fc__.rule.children, _rule.__fc__);
3342 return _rule.__fc__;
3343 }
3344
3345 var rule = getRule(_rule);
3346
3347 var isRepeat = function isRepeat() {
3348 return !!(rule.field && _this6.fieldCtx[rule.field] && _this6.fieldCtx[rule.field][0] !== _rule.__fc__);
3349 };
3350
3351 _this6.ruleEffect(rule, 'init', {
3352 repeat: isRepeat()
3353 });
3354
3355 if (isRepeat()) {
3356 _this6.vm.$emit('repeat-field', _rule, _this6.api);
3357 }
3358
3359 var ctx;
3360 var isCopy = false;
3361 var isInit = !!_rule.__fc__;
3362
3363 if (isInit) {
3364 ctx = _rule.__fc__;
3365 var check = !ctx.check(_this6);
3366
3367 if (ctx.deleted) {
3368 if (check) {
3369 if (isCtrl(ctx)) {
3370 return;
3371 }
3372
3373 ctx.update(_this6);
3374 }
3375 } else {
3376 if (check) {
3377 if (isCtrl(ctx)) {
3378 return;
3379 }
3380
3381 rules[index] = _rule = _rule._clone ? _rule._clone() : copyRule(_rule);
3382 ctx = null;
3383 isCopy = true;
3384 }
3385 }
3386 }
3387
3388 if (!ctx) {
3389 ctx = new RuleContext(_this6, _this6.parseRule(_rule));
3390
3391 _this6.bindParser(ctx);
3392 } else {
3393 if (ctx.originType !== ctx.rule.type) {
3394 ctx.updateType();
3395
3396 _this6.bindParser(ctx);
3397 }
3398
3399 _this6.appendValue(ctx.rule);
3400 }
3401
3402 [false, true].forEach(function (b) {
3403 return _this6.parseEmit(ctx, b);
3404 });
3405
3406 _this6.syncProp(ctx);
3407
3408 ctx.parent = parent || null;
3409 ctx.root = rules;
3410
3411 _this6.setCtx(ctx);
3412
3413 !isCopy && !isInit && _this6.effect(ctx, 'load');
3414 ctx.parser.loadChildren === false || loadChildren(ctx.rule.children, ctx);
3415
3416 if (!parent) {
3417 var _preIndex = preIndex(index);
3418
3419 if (_preIndex > -1 || !index) {
3420 _this6.sort.splice(_preIndex + 1, 0, ctx.id);
3421 } else {
3422 _this6.sort.push(ctx.id);
3423 }
3424 }
3425
3426 var r = ctx.rule;
3427
3428 if (!ctx.updated) {
3429 ctx.updated = true;
3430
3431 if (is.Function(r.update)) {
3432 _this6.bus.$once('load-end', function () {
3433 _this6.refreshUpdate(ctx, r.value);
3434 });
3435 }
3436
3437 _this6.effect(ctx, 'loaded');
3438 }
3439
3440 if (ctx.input) Object.defineProperty(r, 'value', _this6.valueHandle(ctx));
3441 if (_this6.refreshControl(ctx)) _this6.cycleLoad = true;
3442 return ctx;
3443 });
3444 },
3445 refreshControl: function refreshControl(ctx) {
3446 return ctx.input && ctx.rule.control && this.useCtrl(ctx);
3447 },
3448 useCtrl: function useCtrl(ctx) {
3449 var _this7 = this;
3450
3451 var controls = getCtrl(ctx),
3452 validate = [],
3453 api = this.api;
3454 if (!controls.length) return false;
3455
3456 var _loop = function _loop(i) {
3457 var control = controls[i],
3458 handleFn = control.handle || function (val) {
3459 return val === control.value;
3460 };
3461
3462 if (!is.trueArray(control.rule)) return "continue";
3463
3464 var data = _objectSpread2(_objectSpread2({}, control), {}, {
3465 valid: invoke(function () {
3466 return handleFn(ctx.rule.value, api);
3467 }),
3468 ctrl: findCtrl(ctx, control.rule),
3469 isHidden: is.String(control.rule[0])
3470 });
3471
3472 if (data.valid && data.ctrl || !data.valid && !data.ctrl && !data.isHidden) return "continue";
3473 validate.push(data);
3474 };
3475
3476 for (var i = 0; i < controls.length; i++) {
3477 var _ret = _loop(i);
3478
3479 if (_ret === "continue") continue;
3480 }
3481
3482 if (!validate.length) return false;
3483 var flag = false;
3484 this.deferSyncValue(function () {
3485 validate.reverse().forEach(function (_ref) {
3486 var isHidden = _ref.isHidden,
3487 valid = _ref.valid,
3488 rule = _ref.rule,
3489 prepend = _ref.prepend,
3490 append = _ref.append,
3491 child = _ref.child,
3492 ctrl = _ref.ctrl;
3493
3494 if (isHidden) {
3495 valid ? ctx.ctrlRule.push({
3496 __ctrl: true,
3497 children: rule,
3498 valid: valid
3499 }) : ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3500
3501 _this7.vm.$nextTick(function () {
3502 _this7.api.hidden(!valid, rule);
3503 });
3504
3505 return;
3506 }
3507
3508 if (valid) {
3509 flag = true;
3510 var ruleCon = {
3511 type: 'fcFragment',
3512 "native": true,
3513 __ctrl: true,
3514 children: rule
3515 };
3516 ctx.ctrlRule.push(ruleCon);
3517
3518 _this7.bus.$once('load-start', function () {
3519 // this.cycleLoad = true;
3520 if (prepend) {
3521 api.prepend(ruleCon, prepend, child);
3522 } else if (append || child) {
3523 api.append(ruleCon, append || ctx.id, child);
3524 } else {
3525 ctx.root.splice(ctx.root.indexOf(ctx.origin) + 1, 0, ruleCon);
3526 }
3527 });
3528 } else {
3529 ctx.ctrlRule.splice(ctx.ctrlRule.indexOf(ctrl), 1);
3530 var ctrlCtx = byCtx(ctrl);
3531 ctrlCtx && ctrlCtx.rm();
3532 }
3533 });
3534 });
3535 this.vm.$emit('control', ctx.origin, this.api);
3536 this.effect(ctx, 'control');
3537 return flag;
3538 },
3539 reloadRule: function reloadRule(rules) {
3540 return this._reloadRule(rules);
3541 },
3542 _reloadRule: function _reloadRule(rules) {
3543 var _this8 = this;
3544
3545 // console.warn('%c reload', 'color:red');
3546 if (!rules) rules = this.rules;
3547
3548 var ctxs = _objectSpread2({}, this.ctxs);
3549
3550 this.clearNextTick();
3551 this.$render.clearOrgChildren();
3552 this.initData(rules);
3553 this.fc.rules = rules;
3554 this.bus.$once('load-end', function () {
3555 Object.keys(ctxs).filter(function (id) {
3556 return _this8.ctxs[id] === undefined;
3557 }).forEach(function (id) {
3558 return _this8.rmCtx(ctxs[id]);
3559 });
3560
3561 _this8.$render.clearCacheAll();
3562 });
3563 this.reloading = true;
3564 this.loadRule();
3565 this.reloading = false;
3566 this.refresh();
3567 this.bus.$off('next-tick', this.nextReload);
3568 this.bus.$once('next-tick', this.nextReload);
3569 },
3570 //todo 组件生成全部通过 alias
3571 refresh: function refresh() {
3572 this.vm._refresh();
3573 }
3574 });
3575 }
3576
3577 function fullRule(rule) {
3578 var def = baseRule();
3579 Object.keys(def).forEach(function (k) {
3580 if (!hasProperty(rule, k)) rule[k] = def[k];
3581 });
3582 return rule;
3583 }
3584
3585 function getCtrl(ctx) {
3586 var control = ctx.rule.control || [];
3587 if (is.Object(control)) return [control];else return control;
3588 }
3589
3590 function findCtrl(ctx, rule) {
3591 for (var i = 0; i < ctx.ctrlRule.length; i++) {
3592 var ctrl = ctx.ctrlRule[i];
3593 if (ctrl.children === rule) return ctrl;
3594 }
3595 }
3596
3597 function isCtrl(ctx) {
3598 return !!ctx.rule.__ctrl;
3599 }
3600
3601 function useInput(Handler) {
3602 extend(Handler.prototype, {
3603 getValue: function getValue(ctx) {
3604 if (!hasProperty(ctx, 'cacheValue')) {
3605 ctx.cacheValue = ctx.parser.toValue(this.getFormData(ctx), ctx);
3606 }
3607
3608 return ctx.cacheValue;
3609 },
3610 setValue: function setValue(ctx, value, formValue, setFlag) {
3611 if (ctx.deleted) return;
3612 ctx.cacheValue = value;
3613 this.changeStatus = true;
3614 this.nextRefresh();
3615 this.$render.clearCache(ctx);
3616 this.setFormData(ctx, formValue);
3617 this.syncValue();
3618 this.valueChange(ctx, value);
3619 this.vm.$emit('change', ctx.field, value, ctx.origin, this.api, setFlag);
3620 this.effect(ctx, 'value');
3621 },
3622 onInput: function onInput(ctx, value) {
3623 var val;
3624
3625 if (ctx.input && (this.isQuote(ctx, val = ctx.parser.toValue(value, ctx)) || this.isChange(ctx, val))) {
3626 this.setValue(ctx, val, value);
3627 }
3628 },
3629 setFormData: function setFormData(ctx, value) {
3630 $set(this.formData, ctx.id, value);
3631 },
3632 getFormData: function getFormData(ctx) {
3633 return this.formData[ctx.id];
3634 },
3635 validate: function validate() {
3636 var _this = this;
3637
3638 toEmpty(this.vm.validate);
3639 this.fields().forEach(function (id) {
3640 _this.fieldCtx[id].forEach(function (ctx) {
3641 _this.vm.validate[ctx.id] = toArray(ctx.rule.validate);
3642 });
3643 });
3644 return this.vm.validate;
3645 },
3646 syncForm: function syncForm() {
3647 var _this2 = this;
3648
3649 toEmpty(this.form);
3650 Object.defineProperties(this.form, this.fields().reduce(function (initial, field) {
3651 var ctx = _this2.getFieldCtx(field);
3652
3653 var handle = _this2.valueHandle(ctx);
3654
3655 handle.configurable = true;
3656 initial[field] = handle;
3657 return initial;
3658 }, Object.keys(this.appendData).reduce(function (initial, field) {
3659 initial[field] = {
3660 enumerable: true,
3661 configurable: true,
3662 get: function get() {
3663 return _this2.appendData[field];
3664 },
3665 set: function set(val) {
3666 _this2.appendData[field] = val;
3667 }
3668 };
3669 return initial;
3670 }, {})));
3671 this.syncValue();
3672 },
3673 valueHandle: function valueHandle(ctx) {
3674 var _this3 = this;
3675
3676 return {
3677 enumerable: true,
3678 get: function get() {
3679 return _this3.getValue(ctx);
3680 },
3681 set: function set(value) {
3682 if (_this3.isChange(ctx, value)) {
3683 _this3.setValue(ctx, value, ctx.parser.toFormValue(value, ctx), true);
3684 }
3685 }
3686 };
3687 },
3688 appendValue: function appendValue(rule) {
3689 if (!rule.field || !hasProperty(this.appendData, rule.field)) return;
3690 rule.value = this.appendData[rule.field];
3691 delete this.appendData[rule.field];
3692 },
3693 addSubForm: function addSubForm(ctx, subForm) {
3694 if (ctx.input) {
3695 this.subForm[ctx.id] = subForm;
3696 }
3697 },
3698 deferSyncValue: function deferSyncValue(fn, sync) {
3699 if (!this.deferSyncFn) {
3700 this.deferSyncFn = fn;
3701 }
3702
3703 if (!this.deferSyncFn.sync) {
3704 this.deferSyncFn.sync = sync;
3705 }
3706
3707 invoke(fn);
3708
3709 if (this.deferSyncFn === fn) {
3710 this.deferSyncFn = null;
3711
3712 if (fn.sync) {
3713 this.syncValue();
3714 }
3715 }
3716 },
3717 syncValue: function syncValue() {
3718 if (this.deferSyncFn) {
3719 return this.deferSyncFn.sync = true;
3720 }
3721
3722 this.vm._updateValue(_objectSpread2({}, this.form));
3723 },
3724 isChange: function isChange(ctx, value) {
3725 return JSON.stringify(ctx.rule.value) !== JSON.stringify(value);
3726 },
3727 isQuote: function isQuote(ctx, value) {
3728 return (is.Object(value) || Array.isArray(value)) && value === ctx.rule.value;
3729 },
3730 refreshUpdate: function refreshUpdate(ctx, val) {
3731 var _this4 = this;
3732
3733 if (is.Function(ctx.rule.update)) {
3734 var state = invoke(function () {
3735 return ctx.rule.update(val, ctx.origin, _this4.api);
3736 });
3737 if (state === undefined) return;
3738 ctx.rule.hidden = state === true;
3739 }
3740 },
3741 valueChange: function valueChange(ctx, val) {
3742 this.refreshRule(ctx, val);
3743 this.bus.$emit('change-' + ctx.field, val);
3744 },
3745 refreshRule: function refreshRule(ctx, val) {
3746 if (this.refreshControl(ctx)) {
3747 this.$render.clearCacheAll();
3748 this.loadRule();
3749 this.refresh();
3750 }
3751
3752 this.refreshUpdate(ctx, val);
3753 },
3754 appendLink: function appendLink(ctx) {
3755 var _this5 = this;
3756
3757 var link = ctx.rule.link;
3758 is.trueArray(link) && link.forEach(function (field) {
3759 var fn = function fn() {
3760 return _this5.refreshRule(ctx, ctx.rule.value);
3761 };
3762
3763 _this5.bus.$on('change-' + field, fn);
3764
3765 ctx.linkOn.push(function () {
3766 return _this5.bus.$off('change-' + field, fn);
3767 });
3768 });
3769 },
3770 fields: function fields() {
3771 return Object.keys(this.fieldCtx);
3772 }
3773 });
3774 }
3775
3776 function toEmpty(obj) {
3777 Object.keys(obj).forEach(function (k) {
3778 return delete obj[k];
3779 });
3780 }
3781
3782 var BaseParser = {
3783 init: function init(ctx) {},
3784 toFormValue: function toFormValue(value, ctx) {
3785 return value;
3786 },
3787 toValue: function toValue(formValue, ctx) {
3788 return formValue;
3789 },
3790 mounted: function mounted(ctx) {},
3791 render: function render(children, ctx) {
3792 return ctx.$render.defaultRender(ctx, children);
3793 },
3794 mergeProp: function mergeProp(ctx) {}
3795 };
3796
3797 function useContext(Handler) {
3798 extend(Handler.prototype, {
3799 getCtx: function getCtx(id) {
3800 return this.getFieldCtx(id) || this.getNameCtx(id)[0] || this.ctxs[id];
3801 },
3802 getCtxs: function getCtxs(id) {
3803 return this.fieldCtx[id] || this.nameCtx[id] || (this.ctxs[id] ? [this.ctxs[id]] : []);
3804 },
3805 setIdCtx: function setIdCtx(ctx, key, type) {
3806 var field = "".concat(type, "Ctx");
3807
3808 if (!this[field][key]) {
3809 this[field][key] = [ctx];
3810 } else {
3811 this[field][key].push(ctx);
3812 }
3813 },
3814 rmIdCtx: function rmIdCtx(ctx, key, type) {
3815 var field = "".concat(type, "Ctx");
3816 var lst = this[field][key];
3817 if (!lst) return false;
3818 var flag = lst.splice(lst.indexOf(ctx) >>> 0, 1).length > 0;
3819
3820 if (!lst.length) {
3821 delete this[field][key];
3822 }
3823
3824 return flag;
3825 },
3826 getFieldCtx: function getFieldCtx(field) {
3827 return (this.fieldCtx[field] || [])[0];
3828 },
3829 getNameCtx: function getNameCtx(name) {
3830 return this.nameCtx[name] || [];
3831 },
3832 setCtx: function setCtx(ctx) {
3833 var id = ctx.id,
3834 field = ctx.field,
3835 name = ctx.name,
3836 rule = ctx.rule;
3837 this.ctxs[id] = ctx;
3838 name && this.setIdCtx(ctx, name, 'name');
3839 if (!ctx.input) return;
3840 this.setIdCtx(ctx, field, 'field');
3841 this.setFormData(ctx, ctx.parser.toFormValue(rule.value, ctx));
3842
3843 if (this.isMounted && !this.reloading) {
3844 this.vm.$emit('change', ctx.field, rule.value, ctx.origin, this.api);
3845 }
3846 },
3847 getParser: function getParser(ctx) {
3848 var list = this.fc.parsers;
3849 return list[ctx.originType] || list[toCase(ctx.type)] || list[ctx.trueType] || BaseParser;
3850 },
3851 bindParser: function bindParser(ctx) {
3852 ctx.setParser(this.getParser(ctx));
3853 },
3854 getType: function getType(alias) {
3855 var map = this.fc.CreateNode.aliasMap;
3856 var type = map[alias] || map[toCase(alias)] || alias;
3857 return toCase(type);
3858 },
3859 noWatch: function noWatch(fn) {
3860 if (!this.noWatchFn) {
3861 this.noWatchFn = fn;
3862 }
3863
3864 invoke(fn);
3865
3866 if (this.noWatchFn === fn) {
3867 this.noWatchFn = null;
3868 }
3869 },
3870 watchCtx: function watchCtx(ctx) {
3871 var _this = this;
3872
3873 var vm = this.vm;
3874 var none = ['field', 'value', 'vm', 'template', 'name', 'config', 'control', 'inject', 'sync', 'payload', 'optionsTo', 'update'];
3875 Object.keys(ctx.rule).filter(function (k) {
3876 return none.indexOf(k) === -1;
3877 }).forEach(function (key) {
3878 var flag = key === 'children';
3879 ctx.watch.push(vm.$watch(function () {
3880 return ctx.rule[key];
3881 }, function (n, o) {
3882 if (_this.loading || _this.noWatchFn || _this.reloading) return;
3883
3884 if (flag && ctx.parser.loadChildren === false) {
3885 _this.$render.clearCache(ctx);
3886
3887 _this.nextRefresh();
3888
3889 return;
3890 }
3891
3892 _this.watching = true; // if (key === 'hidden')
3893 // ctx.updateKey(true);
3894 // else
3895
3896 if (key === 'link') {
3897 ctx.link();
3898 return;
3899 } else if (['props', 'on', 'nativeOn', 'deep'].indexOf(key) > -1) {
3900 _this.parseInjectEvent(ctx.rule, n || {});
3901
3902 if (key === 'props' && ctx.input) {
3903 _this.setFormData(ctx, ctx.parser.toFormValue(ctx.rule.value, ctx));
3904 }
3905 } else if (['emit', 'nativeEmit'].indexOf(key) > -1) _this.parseEmit(ctx, key === 'emit');else if (['prefix', 'suffix'].indexOf(key) > -1) n && _this.loadFn(n, ctx.rule);else if (key === 'type') {
3906 ctx.updateType();
3907
3908 _this.bindParser(ctx);
3909 } else if (key === 'children') {
3910 var _flag = is.trueArray(n);
3911
3912 _this.deferSyncValue(function () {
3913 if (n !== o) {
3914 _this.rmSub(o);
3915
3916 _this.$render.initOrgChildren();
3917 }
3918
3919 _flag && _this.loadChildren(n, ctx);
3920 });
3921 }
3922
3923 _this.$render.clearCache(ctx);
3924
3925 _this.watching = false;
3926 }, {
3927 deep: !flag,
3928 sync: flag
3929 }));
3930 });
3931 this.watchEffect(ctx);
3932 },
3933 rmSub: function rmSub(sub) {
3934 var _this2 = this;
3935
3936 is.trueArray(sub) && sub.forEach(function (r) {
3937 r && r.__fc__ && _this2.rmCtx(r.__fc__);
3938 });
3939 },
3940 rmCtx: function rmCtx(ctx) {
3941 var _this3 = this;
3942
3943 if (ctx.deleted) return;
3944 var id = ctx.id,
3945 field = ctx.field,
3946 input = ctx.input,
3947 name = ctx.name;
3948
3949 if (ctx.input) {
3950 Object.defineProperty(ctx.rule, 'value', {
3951 value: ctx.rule.value,
3952 writable: true
3953 });
3954 }
3955
3956 $del(this.ctxs, id);
3957 $del(this.$render.tempList, id);
3958 $del(this.$render.orgChildren, id);
3959 $del(this.vm.ctxInject, id);
3960 $del(this.formData, id);
3961 $del(this.subForm, id);
3962 $del(ctx, 'cacheValue');
3963 input && this.rmIdCtx(ctx, field, 'field');
3964 name && this.rmIdCtx(ctx, name, 'name');
3965 this.deferSyncValue(function () {
3966 if (!_this3.reloading) {
3967 if (ctx.parser.loadChildren !== false) {
3968 if (is.trueArray(ctx.rule.children)) {
3969 ctx.rule.children.forEach(function (h) {
3970 return h.__fc__ && _this3.rmCtx(h.__fc__);
3971 });
3972 }
3973 }
3974
3975 if (ctx.root === _this3.rules) {
3976 _this3.vm._renderRule();
3977 }
3978 }
3979 }, input);
3980 var index = this.sort.indexOf(id);
3981
3982 if (index > -1) {
3983 this.sort.splice(index, 1);
3984 }
3985
3986 this.$render.clearCache(ctx);
3987 ctx["delete"]();
3988 this.effect(ctx, 'deleted');
3989 input && !this.fieldCtx[field] && this.vm.$emit('removeField', field, ctx.rule, this.api);
3990 ctx.rule.__ctrl || this.vm.$emit('removeRule', ctx.rule, this.api);
3991 return ctx;
3992 }
3993 });
3994 }
3995
3996 function useLifecycle(Handler) {
3997 extend(Handler.prototype, {
3998 mounted: function mounted() {
3999 var _this = this;
4000
4001 var _mounted = function _mounted() {
4002 _this.isMounted = true;
4003
4004 _this.lifecycle('mounted');
4005 };
4006
4007 if (this.pageEnd) {
4008 _mounted();
4009 } else {
4010 this.bus.$once('page-end', _mounted);
4011 }
4012 },
4013 lifecycle: function lifecycle(name) {
4014 var _this2 = this;
4015
4016 var fn = this.options[name];
4017 is.Function(fn) && invoke(function () {
4018 return fn(_this2.api);
4019 });
4020 this.vm.$emit(name, this.api);
4021 }
4022 });
4023 }
4024
4025 function useEffect(Handler) {
4026 extend(Handler.prototype, {
4027 useProvider: function useProvider() {
4028 var _this = this;
4029
4030 var ps = this.fc.providers;
4031 Object.keys(ps).forEach(function (k) {
4032 var prop = ps[k];
4033 prop._c = getComponent(prop);
4034
4035 _this.onEffect(prop);
4036
4037 _this.providers[k] = prop;
4038 });
4039 },
4040 onEffect: function onEffect(provider) {
4041 var _this2 = this;
4042
4043 var used = [];
4044 (provider._c || ['*']).forEach(function (name) {
4045 var type = name === '*' ? '*' : _this2.getType(name);
4046 if (used.indexOf(type) > -1) return;
4047 used.push(type);
4048
4049 _this2.bus.$on("p:".concat(provider.name, ":").concat(type, ":").concat(provider.input ? 1 : 0), function (event, args) {
4050 provider[event] && provider[event].apply(provider, _toConsumableArray(args));
4051 });
4052 });
4053 provider._used = used;
4054 },
4055 watchEffect: function watchEffect(ctx) {
4056 var _this3 = this;
4057
4058 var vm = this.vm;
4059 Object.keys(ctx.rule.effect || {}).forEach(function (k) {
4060 ctx.watch.push(vm.$watch(function () {
4061 return ctx.rule.effect[k];
4062 }, function (n) {
4063 _this3.effect(ctx, 'watch', _defineProperty({}, k, n));
4064 }, {
4065 deep: true
4066 }));
4067 });
4068 },
4069 ruleEffect: function ruleEffect(rule, event, append) {
4070 this.emitEffect({
4071 rule: rule,
4072 input: !!rule.field,
4073 type: this.getType(rule.type)
4074 }, event, append);
4075 },
4076 effect: function effect(ctx, event, custom) {
4077 this.emitEffect({
4078 rule: ctx.rule,
4079 input: ctx.input,
4080 type: ctx.trueType,
4081 ctx: ctx,
4082 custom: custom
4083 }, event);
4084 },
4085 getEffect: function getEffect(rule, name) {
4086 if (hasProperty(rule, 'effect') && hasProperty(rule.effect, name)) return rule.effect[name];else return undefined;
4087 },
4088 emitEffect: function emitEffect(_ref, event, append) {
4089 var _this4 = this;
4090
4091 var ctx = _ref.ctx,
4092 rule = _ref.rule,
4093 input = _ref.input,
4094 type = _ref.type,
4095 custom = _ref.custom;
4096 if (!type || type === 'fcFragment') return;
4097 var effect = custom ? custom : rule.effect || {};
4098 Object.keys(effect).forEach(function (attr) {
4099 var p = _this4.providers[attr];
4100 if (!p || p.input && !input) return;
4101
4102 var _type;
4103
4104 if (!p._c) {
4105 _type = '*';
4106 } else if (p._used.indexOf(type) > -1) {
4107 _type = type;
4108 } else {
4109 return;
4110 }
4111
4112 var data = _objectSpread2({
4113 value: effect[attr],
4114 getValue: function getValue() {
4115 return _this4.getEffect(rule, attr);
4116 }
4117 }, append || {});
4118
4119 if (ctx) {
4120 data.getProp = function () {
4121 return ctx.effectData(attr);
4122 };
4123
4124 data.clearProp = function () {
4125 return ctx.clearEffectData(attr);
4126 };
4127
4128 data.mergeProp = function (prop) {
4129 return mergeProps([prop], data.getProp());
4130 };
4131 }
4132
4133 _this4.bus.$emit("p:".concat(attr, ":").concat(_type, ":").concat(p.input ? 1 : 0), event, [data, rule, _this4.api]);
4134 });
4135 }
4136 });
4137 }
4138
4139 function unique(arr) {
4140 return arr.filter(function (item, index, arr) {
4141 return arr.indexOf(item, 0) === index;
4142 });
4143 }
4144
4145 function getComponent(p) {
4146 var c = p.components;
4147 if (Array.isArray(c)) return unique(c.filter(function (v) {
4148 return v !== '*';
4149 }));else if (is.String(c)) return [c];else return false;
4150 }
4151
4152 function Handler(fc) {
4153 var _this = this;
4154
4155 extend(this, {
4156 fc: fc,
4157 vm: fc.vm,
4158 watching: false,
4159 loading: false,
4160 reloading: false,
4161 noWatchFn: null,
4162 deferSyncFn: null,
4163 isMounted: false,
4164 formData: {},
4165 subForm: {},
4166 form: {},
4167 appendData: {},
4168 providers: {},
4169 cycleLoad: null,
4170 loadedId: 1,
4171 nextTick: null,
4172 changeStatus: false,
4173 pageEnd: true,
4174 nextReload: function nextReload() {
4175 _this.lifecycle('reload');
4176 }
4177 });
4178 funcProxy(this, {
4179 options: function options() {
4180 return fc.options;
4181 },
4182 bus: function bus() {
4183 return fc.bus;
4184 }
4185 });
4186 this.initData(fc.rules);
4187 this.$manager = new fc.manager(this);
4188 this.$render = new Render(this);
4189 this.api = fc.extendApi(Api(this), this);
4190 }
4191 extend(Handler.prototype, {
4192 initData: function initData(rules) {
4193 extend(this, {
4194 ctxs: {},
4195 fieldCtx: {},
4196 nameCtx: {},
4197 sort: [],
4198 rules: rules
4199 });
4200 },
4201 init: function init() {
4202 this.appendData = _objectSpread2(_objectSpread2(_objectSpread2({}, this.fc.options.formData || {}), this.vm.value || {}), this.appendData);
4203 this.useProvider();
4204 this.usePage();
4205 this.loadRule();
4206
4207 this.$manager.__init();
4208
4209 this.vm.$set(this.vm, 'formData', this.formData);
4210 }
4211 });
4212 useInject(Handler);
4213 usePage(Handler);
4214 useRender$1(Handler);
4215 useLoader(Handler);
4216 useInput(Handler);
4217 useContext(Handler);
4218 useLifecycle(Handler);
4219 useEffect(Handler);
4220
4221 // https://github.com/ElemeFE/element/blob/dev/packages/upload/src/ajax.js
4222 function getError(action, option, xhr) {
4223 var msg = "fail to ".concat(action, " ").concat(xhr.status, "'");
4224 var err = new Error(msg);
4225 err.status = xhr.status;
4226 err.url = action;
4227 return err;
4228 }
4229
4230 function getBody(xhr) {
4231 var text = xhr.responseText || xhr.response;
4232
4233 if (!text) {
4234 return text;
4235 }
4236
4237 try {
4238 return JSON.parse(text);
4239 } catch (e) {
4240 return text;
4241 }
4242 }
4243
4244 function fetch(option) {
4245 if (typeof XMLHttpRequest === 'undefined') {
4246 return;
4247 }
4248
4249 var xhr = new XMLHttpRequest();
4250 var action = option.action;
4251
4252 xhr.onerror = function error(e) {
4253 option.onError(e);
4254 };
4255
4256 xhr.onload = function onload() {
4257 if (xhr.status < 200 || xhr.status >= 300) {
4258 return option.onError(getError(action, option, xhr), getBody(xhr));
4259 }
4260
4261 option.onSuccess(getBody(xhr));
4262 };
4263
4264 xhr.open(option.method || 'get', action, true);
4265 var formData;
4266
4267 if (option.data) {
4268 if ((option.dataType || '').toLowerCase() !== 'json') {
4269 formData = new FormData();
4270 Object.keys(option.data).map(function (key) {
4271 formData.append(key, option.data[key]);
4272 });
4273 } else {
4274 formData = JSON.stringify(option.data);
4275 xhr.setRequestHeader('content-type', 'application/json');
4276 }
4277 }
4278
4279 if (option.withCredentials && 'withCredentials' in xhr) {
4280 xhr.withCredentials = true;
4281 }
4282
4283 var headers = option.headers || {};
4284 Object.keys(headers).forEach(function (item) {
4285 if (headers[item] !== null) {
4286 xhr.setRequestHeader(item, headers[item]);
4287 }
4288 });
4289 xhr.send(formData);
4290 }
4291
4292 var NAME$5 = 'fcFragment';
4293 var fragment = {
4294 name: NAME$5,
4295 functional: true,
4296 props: ['vnode'],
4297 render: function render(h, ctx) {
4298 return ctx.props.vnode ? ctx.props.vnode : ctx.children;
4299 }
4300 };
4301
4302 function parseProp(prop) {
4303 if (is.String(prop)) return {
4304 domProps: {
4305 innerHTML: prop
4306 }
4307 };
4308 return prop;
4309 }
4310
4311 function CreateNodeFactory() {
4312 var aliasMap = {};
4313
4314 function CreateNode(vm) {
4315 vm && this.setVm(vm);
4316 }
4317
4318 extend(CreateNode.prototype, {
4319 setVm: function setVm(vm) {
4320 this.vm = vm;
4321 this.$h = vm.$createElement;
4322 },
4323 make: function make(tag, data, children) {
4324 if (Vue.config.isReservedTag(tag) && data.nativeOn) delete data.nativeOn;
4325 var Node = this.$h(tag, parseProp(data), children || []);
4326 Node.context = this.vm;
4327 return Node;
4328 },
4329 aliasMap: aliasMap
4330 });
4331 extend(CreateNode, {
4332 aliasMap: aliasMap,
4333 alias: function alias(_alias, name) {
4334 aliasMap[_alias] = name;
4335 },
4336 use: function use(nodes) {
4337 Object.keys(nodes).forEach(function (k) {
4338 var line = toLine(k);
4339 var lower = toString(k).toLocaleLowerCase();
4340 var v = nodes[k];
4341 [k, line, lower].forEach(function (n) {
4342 CreateNode.alias(k, v);
4343
4344 CreateNode.prototype[n] = function (data, children) {
4345 return this.make(v, data, children);
4346 };
4347 });
4348 });
4349 }
4350 });
4351 return CreateNode;
4352 }
4353
4354 function createManager(proto) {
4355 var CustomManager = /*#__PURE__*/function (_Manager) {
4356 _inherits(CustomManager, _Manager);
4357
4358 var _super = _createSuper(CustomManager);
4359
4360 function CustomManager() {
4361 _classCallCheck(this, CustomManager);
4362
4363 return _super.apply(this, arguments);
4364 }
4365
4366 return CustomManager;
4367 }(Manager);
4368
4369 Object.assign(CustomManager.prototype, proto);
4370 return CustomManager;
4371 }
4372 function Manager(handler) {
4373 extend(this, {
4374 $handle: handler,
4375 vm: handler.vm,
4376 options: {},
4377 ref: 'fcForm',
4378 mergeOptionsRule: {
4379 normal: ['form', 'row', 'info', 'submitBtn', 'resetBtn']
4380 }
4381 });
4382 this.updateKey();
4383 this.init();
4384 }
4385 extend(Manager.prototype, {
4386 __init: function __init() {
4387 var _this = this;
4388
4389 this.$render = this.$handle.$render;
4390
4391 this.$r = function () {
4392 var _this$$render;
4393
4394 return (_this$$render = _this.$render).renderRule.apply(_this$$render, arguments);
4395 };
4396 },
4397 updateKey: function updateKey() {
4398 this.key = uniqueId();
4399 },
4400 //TODO interface
4401 init: function init() {},
4402 update: function update() {},
4403 beforeRender: function beforeRender() {},
4404 form: function form() {
4405 return this.vm.$refs[this.ref];
4406 },
4407 mergeOptions: function mergeOptions(args, opt) {
4408 var _this2 = this;
4409
4410 return mergeProps(args.map(function (v) {
4411 return _this2.tidyOptions(v);
4412 }), opt, this.mergeOptionsRule);
4413 },
4414 updateOptions: function updateOptions(options) {
4415 this.options = this.mergeOptions([options], this.getDefaultOptions());
4416 this.update();
4417 },
4418 tidyOptions: function tidyOptions(options) {
4419 return options;
4420 },
4421 tidyRule: function tidyRule(ctx) {},
4422 mergeProp: function mergeProp(ctx) {},
4423 getDefaultOptions: function getDefaultOptions() {
4424 return {};
4425 },
4426 render: function render(children) {}
4427 });
4428
4429 var $fetch = {
4430 name: 'fetch',
4431 loaded: function loaded() {
4432 run.apply(void 0, arguments);
4433 },
4434 watch: function watch(inject, rule, api) {
4435 if (!run(inject, rule, api)) {
4436 inject.clearProp();
4437 api.sync(rule);
4438 }
4439 }
4440 };
4441
4442 function parseOpt(option) {
4443 if (is.String(option)) {
4444 option = {
4445 action: option,
4446 to: 'options'
4447 };
4448 }
4449
4450 return option;
4451 }
4452
4453 function run(inject, rule, api) {
4454 var option = inject.value;
4455 option = parseOpt(option);
4456
4457 if (!option || !option.action) {
4458 return false;
4459 }
4460
4461 if (!option.to) {
4462 option.to = 'options';
4463 }
4464
4465 var _onError = option.onError;
4466
4467 var check = function check() {
4468 if (!inject.getValue()) {
4469 inject.clearProp();
4470 api.sync(rule);
4471 return true;
4472 }
4473 };
4474
4475 var set = function set(val) {
4476 if (val === undefined) {
4477 inject.clearProp();
4478 api.sync(rule);
4479 } else {
4480 deepSet(inject.getProp(), option.to, val);
4481 }
4482 };
4483
4484 invoke(function () {
4485 return fetch(_objectSpread2(_objectSpread2({}, option), {}, {
4486 onSuccess: function onSuccess(body) {
4487 if (check()) return;
4488 set((option.parse || function (v) {
4489 return v.data;
4490 })(body, rule, api));
4491 api.sync(rule);
4492 },
4493 onError: function onError(e) {
4494 set(undefined);
4495 if (check()) return;
4496
4497 (_onError || function (e) {
4498 return err(e.message || 'fetch fail ' + option.action);
4499 })(e, rule, api);
4500 }
4501 }));
4502 });
4503 return true;
4504 }
4505
4506 var _vue = typeof window !== 'undefined' && window.Vue ? window.Vue : Vue;
4507
4508 function _parseProp(name, id) {
4509 var prop;
4510
4511 if (arguments.length === 2) {
4512 prop = arguments[1];
4513 id = prop[name];
4514 } else {
4515 prop = arguments[2];
4516 }
4517
4518 return {
4519 id: id,
4520 prop: prop
4521 };
4522 }
4523
4524 function nameProp() {
4525 return _parseProp.apply(void 0, ['name'].concat(Array.prototype.slice.call(arguments)));
4526 }
4527
4528 function _getEl(options) {
4529 if (!options || !options.el) return window.document.body;
4530 return is.Element(options.el) ? options.el : document.querySelector(options.el);
4531 }
4532
4533 function mountForm(rules, option) {
4534 var $vm = new _vue({
4535 data: function data() {
4536 //todo 外部无法修改
4537 return {
4538 rule: rules,
4539 option: option || {}
4540 };
4541 },
4542 render: function render(h) {
4543 return h('FormCreate', {
4544 ref: 'fc',
4545 props: this.$data
4546 });
4547 }
4548 });
4549 $vm.$mount();
4550 return $vm;
4551 }
4552
4553 function exportAttrs(attrs) {
4554 var key = attrs.key || [];
4555 var array = attrs.array || [];
4556 var normal = attrs.normal || [];
4557 keyAttrs.push.apply(keyAttrs, _toConsumableArray(key));
4558 arrayAttrs.push.apply(arrayAttrs, _toConsumableArray(array));
4559 normalAttrs.push.apply(normalAttrs, _toConsumableArray(normal));
4560 appendProto([].concat(_toConsumableArray(key), _toConsumableArray(array), _toConsumableArray(normal)));
4561 } //todo 表单嵌套
4562
4563
4564 function FormCreateFactory(config) {
4565 var _fragment = _vue.extend(fragment);
4566
4567 var components = _defineProperty({}, fragment.name, _fragment);
4568
4569 var parsers = {};
4570 var directives = {};
4571 var providers = {
4572 fetch: $fetch
4573 };
4574 var maker = makerFactory();
4575 var globalConfig = {
4576 global: {}
4577 };
4578 var data = {};
4579 var CreateNode = CreateNodeFactory();
4580 exportAttrs(config.attrs || {});
4581
4582 function directive() {
4583 var data = nameProp.apply(void 0, arguments);
4584 if (data.id && data.prop) directives[data.id] = data.prop;
4585 }
4586
4587 function register() {
4588 var data = nameProp.apply(void 0, arguments);
4589 if (data.id && data.prop) providers[data.id] = _objectSpread2(_objectSpread2({}, data.prop), {}, {
4590 name: data.id
4591 });
4592 }
4593
4594 function componentAlias(alias) {
4595 CreateNode.use(alias);
4596 }
4597
4598 function parser() {
4599 var data = nameProp.apply(void 0, arguments);
4600 if (!data.id || !data.prop) return;
4601 var name = toCase(data.id);
4602 var parser = data.prop;
4603 var base = parser.merge === true ? parsers[name] : undefined;
4604 parsers[name] = _objectSpread2(_objectSpread2({}, base || BaseParser), parser);
4605 maker[name] = creatorFactory(name);
4606 parser.maker && extend(maker, parser.maker);
4607 }
4608
4609 function component(id, component) {
4610 var name;
4611
4612 if (is.String(id)) {
4613 name = toCase(id);
4614
4615 if (['form-create', 'formcreate'].indexOf(name) > -1) {
4616 return $form();
4617 } else if (component === undefined) {
4618 return components[name];
4619 }
4620 } else {
4621 name = toCase(id.name);
4622 component = id;
4623 }
4624
4625 if (!name || !component) return;
4626 components[name] = component;
4627 if (component.formCreateParser) parser(name, component.formCreateParser);
4628 }
4629
4630 function $form() {
4631 return _vue.extend($FormCreate(FormCreate));
4632 } //todo 检查回调函数作用域
4633
4634
4635 function use(fn, opt) {
4636 if (is.Function(fn.install)) fn.install(create, opt);else if (is.Function(fn)) fn(create, opt);
4637 return this;
4638 }
4639
4640 function create(rules, _opt, parent) {
4641 var $vm = mountForm(rules, _opt || {});
4642 var _this = $vm.$refs.fc.formCreate;
4643 _this.$parent = parent;
4644
4645 _getEl(_this.options).appendChild($vm.$el);
4646
4647 return _this.api();
4648 }
4649
4650 function factory() {
4651 return FormCreateFactory(config);
4652 }
4653
4654 function FormCreate(vm, rules, options) {
4655 extend(this, {
4656 vm: vm,
4657 create: create,
4658 manager: createManager(config.manager),
4659 parsers: parsers,
4660 providers: providers,
4661 rules: Array.isArray(rules) ? rules : [],
4662 prop: {
4663 components: components,
4664 directives: directives
4665 },
4666 CreateNode: CreateNode,
4667 bus: new _vue(),
4668 unwatch: null,
4669 extendApi: config.extendApi || function (api) {
4670 return api;
4671 }
4672 });
4673 this.init();
4674 this.initOptions(options || {});
4675 }
4676
4677 extend(FormCreate.prototype, {
4678 init: function init() {
4679 var _this2 = this;
4680
4681 var vm = this.vm;
4682 var h = new Handler(this);
4683 this.$handle = h;
4684 vm.$f = h.api;
4685 vm.$emit('input', h.api);
4686 vm.$on('hook:created', function () {
4687 if (_this2.isSub()) {
4688 _this2.unwatch = vm.$watch(function () {
4689 return vm.$pfc.option;
4690 }, function () {
4691 _this2.initOptions(_this2.options);
4692
4693 vm.$f.refresh();
4694 }, {
4695 deep: true
4696 });
4697
4698 _this2.initOptions(_this2.options);
4699 }
4700
4701 _this2.created();
4702 });
4703 vm.$on('hook:mounted', function () {
4704 _this2.mounted();
4705 });
4706 vm.$on('hook:beforeDestroy', function () {
4707 vm.destroyed = true;
4708 _this2.unwatch && _this2.unwatch();
4709 h.reloadRule([]);
4710 });
4711 vm.$on('hook:updated', function () {
4712 h.bindNextTick(function () {
4713 return _this2.bus.$emit('next-tick', h.api);
4714 });
4715 });
4716 },
4717 isSub: function isSub() {
4718 return this.vm.$pfc && this.vm.extendOption;
4719 },
4720 initOptions: function initOptions(options) {
4721 this.options = _objectSpread2({
4722 formData: {},
4723 submitBtn: {},
4724 resetBtn: {}
4725 }, deepCopy(globalConfig));
4726
4727 if (this.isSub()) {
4728 this.mergeOptions(this.options, this.vm.$pfc.$f.config || {}, true);
4729 }
4730
4731 this.updateOptions(options);
4732 },
4733 mergeOptions: function mergeOptions(target, opt, parent) {
4734 opt = deepCopy(opt);
4735 parent && ['page', 'onSubmit', 'mounted', 'reload', 'formData', 'el'].forEach(function (n) {
4736 delete opt[n];
4737 });
4738
4739 if (opt.global) {
4740 target.global = mergeGlobal(target.global, opt.global);
4741 delete opt.global;
4742 }
4743
4744 this.$handle.$manager.mergeOptions([opt], target);
4745 return target;
4746 },
4747 updateOptions: function updateOptions(options) {
4748 this.mergeOptions(this.options, options);
4749 this.$handle.$manager.updateOptions(this.options);
4750 },
4751 created: function created() {
4752 this.$handle.init();
4753 },
4754 api: function api() {
4755 return this.$handle.api;
4756 },
4757 render: function render() {
4758 return this.$handle.render();
4759 },
4760 mounted: function mounted() {
4761 this.$handle.mounted();
4762 }
4763 });
4764
4765 function useAttr(formCreate) {
4766 extend(formCreate, {
4767 version: config.version,
4768 ui: config.ui,
4769 data: data,
4770 maker: maker,
4771 component: component,
4772 directive: directive,
4773 register: register,
4774 fragment: _fragment,
4775 parser: parser,
4776 use: use,
4777 factory: factory,
4778 componentAlias: componentAlias,
4779 copyRule: copyRule,
4780 copyRules: copyRules,
4781 fetch: fetch,
4782 $form: $form,
4783 parseJson: parseJson,
4784 toJson: toJson,
4785 init: function init(rules) {
4786 var _opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4787
4788 var $vm = mountForm(rules, _opt),
4789 _this = $vm.$refs.fc.formCreate;
4790 return {
4791 mount: function mount($el) {
4792 if ($el && is.Element($el)) _this.options.el = $el;
4793
4794 _getEl(_this.options).appendChild($vm.$el);
4795
4796 return _this.api();
4797 },
4798 remove: function remove() {
4799 $vm.$el.parentNode && $vm.$el.parentNode.removeChild($vm.$el);
4800 },
4801 destroy: function destroy() {
4802 this.remove();
4803 $vm.$destroy();
4804 },
4805 $f: _this.api()
4806 };
4807 }
4808 });
4809 }
4810
4811 function useStatic(formCreate) {
4812 extend(formCreate, {
4813 create: create,
4814 install: function install(Vue, options) {
4815 globalConfig = _objectSpread2(_objectSpread2({}, globalConfig), options || {});
4816 if (Vue._installedFormCreate === true) return;
4817 Vue._installedFormCreate = true;
4818 _vue = Vue;
4819
4820 var $formCreate = function $formCreate(rules) {
4821 var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
4822 return create(rules, opt, this);
4823 };
4824
4825 useAttr($formCreate);
4826 Vue.prototype.$formCreate = $formCreate;
4827 Vue.component('FormCreate', $form());
4828 Vue.component('FcFragment', _fragment);
4829 }
4830 });
4831 }
4832
4833 useAttr(create);
4834 useStatic(create);
4835 CreateNode.use({
4836 fragment: 'fcFragment'
4837 });
4838 if (config.install) create.use(config);
4839 return create;
4840 }
4841
4842 var FORMAT_TYPE = {
4843 date: 'YYYY-MM-DD',
4844 month: 'YYYY-MM',
4845 week: 'YYYY-wo',
4846 range: 'YYYY-MM-DD HH:mm:ss'
4847 };
4848
4849 var getType = function getType(ctx) {
4850 var type = ctx.prop.props.type;
4851 if (['date', 'month', 'week', 'range'].indexOf(type) === -1) return 'date';
4852 return type;
4853 };
4854
4855 var toMoment = function toMoment(val) {
4856 return val instanceof moment ? val : moment(val);
4857 };
4858
4859 function getFormat(ctx) {
4860 return ctx.prop.props.format || (ctx.el ? ctx.el.format : '') || FORMAT_TYPE[getType(ctx)];
4861 }
4862
4863 var name$1 = 'datePicker';
4864 var datePicker = {
4865 name: name$1,
4866 maker: function () {
4867 return ['date', 'month', 'week'].reduce(function (initial, type) {
4868 initial[type] = creatorFactory(name$1, {
4869 type: type
4870 });
4871 return initial;
4872 }, {
4873 dateRange: creatorFactory(name$1, {
4874 type: 'range'
4875 }),
4876 datetimeRange: creatorFactory(name$1, function (m) {
4877 return m.props({
4878 type: 'range',
4879 showTime: true
4880 });
4881 })
4882 });
4883 }(),
4884 toFormValue: function toFormValue(value, ctx) {
4885 var parseValue,
4886 type = getType(ctx);
4887 var isArr = Array.isArray(value);
4888
4889 if (type === 'range') {
4890 if (isArr) {
4891 parseValue = value.map(function (v) {
4892 return v ? toMoment(v) : null;
4893 });
4894 } else {
4895 parseValue = [];
4896 }
4897 } else {
4898 parseValue = isArr ? (value[0] ? toMoment(value[0]) : null) || null : value ? toMoment(value) : null;
4899 }
4900
4901 return parseValue;
4902 },
4903 toValue: function toValue(formValue, ctx) {
4904 var format = getFormat(ctx);
4905 if (Array.isArray(formValue)) return formValue.map(function (v) {
4906 return v ? v.format(format) : v;
4907 });else return formValue ? formValue.format(format) : formValue;
4908 },
4909 render: function render(children, ctx) {
4910 var type = getType(ctx) + 'Picker';
4911 return ctx.$render.vNode[type](ctx.prop, children);
4912 }
4913 };
4914
4915 var name$2 = 'hidden';
4916 var hidden = {
4917 name: name$2,
4918 maker: _defineProperty({}, name$2, function (field, value) {
4919 return creatorFactory(name$2)('', field, value);
4920 }),
4921 render: function render() {
4922 return [];
4923 }
4924 };
4925
4926 var name$3 = 'input';
4927 var input = {
4928 name: name$3,
4929 maker: function () {
4930 return ['password', 'url', 'email', 'text', 'textarea', 'search'].reduce(function (maker, type) {
4931 maker[type] = creatorFactory(name$3, {
4932 type: type
4933 });
4934 return maker;
4935 }, {
4936 idate: creatorFactory(name$3, {
4937 type: 'date'
4938 })
4939 });
4940 }(),
4941 render: function render(children, ctx) {
4942 var type = ctx.prop.props.type;
4943 if (['textarea', 'search'].indexOf(type) === -1) type = 'input';
4944 type = type === 'textarea' ? 'ATextarea' : type === 'search' ? 'AInputSearch' : 'AInput';
4945 return ctx.$render.vNode.make(type, ctx.prop, children);
4946 }
4947 };
4948
4949 var toMoment$1 = function toMoment(val, format) {
4950 return val instanceof moment ? val : moment(val, format);
4951 };
4952
4953 function getFormat$1(ctx) {
4954 return ctx.prop.props.format || (ctx.el ? ctx.el.format : '') || 'HH:mm:ss';
4955 }
4956
4957 var timePicker = {
4958 name: 'timePicker',
4959 toFormValue: function toFormValue(value, ctx) {
4960 return value ? toMoment$1(value, getFormat$1(ctx)) : null;
4961 },
4962 toValue: function toValue(formValue, ctx) {
4963 return formValue ? formValue.format(getFormat$1(ctx)) : formValue;
4964 }
4965 };
4966
4967 var tree = {
4968 name: 'tree',
4969 mergeProp: function mergeProp(ctx) {
4970 var props = ctx.prop.props;
4971 if (!props.replaceFields) props.replaceFields = {
4972 key: 'id'
4973 };else if (!props.replaceFields.key) props.replaceFields.key = 'id';
4974 props.checkedKeys = ctx.rule.value;
4975 props.checkable = true;
4976 }
4977 };
4978
4979 var row = {
4980 name: 'FcRow',
4981 render: function render(_, ctx) {
4982 return ctx.vNode.col({
4983 props: {
4984 span: 24
4985 }
4986 }, [ctx.vNode.row(ctx.prop, _)]);
4987 }
4988 };
4989
4990 var parsers = [checkbox, datePicker, hidden, input, timePicker, tree, radio, select, row];
4991
4992 var PRE = 'a';
4993 var alias = {
4994 tooltip: PRE + 'Tooltip',
4995 popover: PRE + 'Popover',
4996 button: PRE + 'Button',
4997 icon: PRE + 'Icon',
4998 slider: PRE + 'Slider',
4999 rate: PRE + 'Rate',
5000 upload: 'fcUpload',
5001 cascader: PRE + 'Cascader',
5002 timePicker: PRE + 'TimePicker',
5003 datePicker: PRE + 'DatePicker',
5004 rangePicker: PRE + 'RangePicker',
5005 weekPicker: PRE + 'WeekPicker',
5006 monthPicker: PRE + 'MonthPicker',
5007 'switch': PRE + 'Switch',
5008 select: PRE + 'Select',
5009 checkbox: PRE + 'CheckboxGroup',
5010 radio: PRE + 'RadioGroup',
5011 inputNumber: PRE + 'InputNumber',
5012 search: PRE + 'InputSearch',
5013 textarea: PRE + 'Textarea',
5014 formItem: PRE + 'FormModelItem',
5015 form: PRE + 'FormModel',
5016 frame: 'fcFrame',
5017 col: PRE + 'Col',
5018 row: PRE + 'Row',
5019 tree: PRE + 'Tree',
5020 autoComplete: PRE + 'AutoComplete',
5021 group: 'fcGroup',
5022 subForm: 'fcSubForm',
5023 object: 'fcSubForm'
5024 };
5025
5026 var UNDEF = undefined;
5027 function getConfig() {
5028 return {
5029 form: {
5030 hideRequiredMark: false,
5031 layout: 'horizontal',
5032 labelAlign: 'right',
5033 labelCol: {
5034 span: 3
5035 },
5036 wrapperCol: {
5037 span: 21
5038 },
5039 validateOnRuleChange: true
5040 },
5041 row: {
5042 gutter: 0
5043 },
5044 submitBtn: {
5045 disabled: false,
5046 loading: false,
5047 type: 'primary',
5048 innerText: '提交',
5049 show: true,
5050 col: UNDEF,
5051 click: UNDEF
5052 },
5053 resetBtn: {
5054 disabled: false,
5055 icon: 'sync',
5056 loading: false,
5057 type: 'default',
5058 innerText: '重置',
5059 show: false,
5060 col: UNDEF,
5061 click: UNDEF
5062 }
5063 };
5064 }
5065
5066 function isTooltip(info) {
5067 return info.type === 'tooltip';
5068 }
5069
5070 function tidy(props, name) {
5071 if (!hasProperty(props, name)) return;
5072
5073 if (is.String(props[name])) {
5074 var _props$name;
5075
5076 props[name] = (_props$name = {}, _defineProperty(_props$name, name, props[name]), _defineProperty(_props$name, "show", true), _props$name);
5077 }
5078 }
5079
5080 function isFalse(val) {
5081 return val === false;
5082 }
5083
5084 function tidyBool(opt, name) {
5085 if (hasProperty(opt, name) && !is.Object(opt[name])) {
5086 opt[name] = {
5087 show: !!opt[name]
5088 };
5089 }
5090 }
5091
5092 var manager = {
5093 validate: function validate(call) {
5094 this.form().validate(call);
5095 },
5096 validateField: function validateField(field, call) {
5097 this.form().validateField(field, call);
5098 },
5099 clearValidateState: function clearValidateState(ctx) {
5100 var fItem = this.vm.$refs[ctx.wrapRef];
5101
5102 if (fItem) {
5103 fItem.validateMessage = '';
5104 fItem.validateState = '';
5105 }
5106 },
5107 tidyOptions: function tidyOptions(options) {
5108 ['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col'].forEach(function (name) {
5109 tidyBool(options, name);
5110 });
5111 return options;
5112 },
5113 tidyRule: function tidyRule(_ref) {
5114 var prop = _ref.prop;
5115 tidy(prop, 'title');
5116 tidy(prop, 'info');
5117 return prop;
5118 },
5119 mergeProp: function mergeProp(ctx) {
5120 ctx.prop = mergeProps([{
5121 info: this.options.info || {},
5122 wrap: this.options.wrap || {},
5123 col: this.options.col || {}
5124 }, ctx.prop], {
5125 info: {
5126 type: 'popover',
5127 placement: 'topLeft',
5128 icon: 'question-circle-o'
5129 },
5130 title: {},
5131 col: {
5132 span: 24
5133 },
5134 wrap: {}
5135 }, {
5136 normal: ['title', 'info', 'col', 'wrap']
5137 });
5138 },
5139 getDefaultOptions: function getDefaultOptions() {
5140 return getConfig();
5141 },
5142 update: function update() {
5143 var form = this.options.form;
5144 this.rule = {
5145 props: _objectSpread2({}, form),
5146 nativeOn: {
5147 submit: function submit(e) {
5148 e.preventDefault();
5149 }
5150 },
5151 "class": [form.className, form["class"], 'form-create'],
5152 style: form.style,
5153 type: 'form'
5154 };
5155 },
5156 beforeRender: function beforeRender() {
5157 var key = this.key,
5158 ref = this.ref,
5159 $handle = this.$handle;
5160 extend(this.rule, {
5161 key: key,
5162 ref: ref
5163 });
5164 extend(this.rule.props, {
5165 model: $handle.formData,
5166 rules: $handle.validate()
5167 });
5168 },
5169 render: function render(children) {
5170 if (children.length) {
5171 children.push(this.makeFormBtn());
5172 }
5173
5174 return this.$r(this.rule, isFalse(this.options.row.show) ? children : [this.makeRow(children)]);
5175 },
5176 makeWrap: function makeWrap(ctx, children) {
5177 var rule = ctx.prop;
5178 var uni = "".concat(this.key).concat(ctx.key);
5179 var col = rule.col;
5180 var _this$rule$props = this.rule.props,
5181 layout = _this$rule$props.layout,
5182 _col = _this$rule$props.col;
5183 var item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
5184 props: _objectSpread2(_objectSpread2({}, rule.wrap || {}), {}, {
5185 prop: ctx.id,
5186 rules: rule.validate
5187 }, layout !== 'horizontal' ? {
5188 labelCol: {},
5189 wrapperCol: {}
5190 } : {}),
5191 "class": rule.className,
5192 key: "".concat(uni, "fi"),
5193 ref: ctx.wrapRef,
5194 type: 'formItem'
5195 }]), [children, this.makeInfo(rule, uni)]);
5196 return layout === 'inline' || isFalse(_col) || isFalse(col.show) ? item : this.makeCol(rule, uni, [item]);
5197 },
5198 makeInfo: function makeInfo(rule, uni) {
5199 var _this = this;
5200
5201 var titleProp = rule.title;
5202 var infoProp = rule.info;
5203 if (this.options.form.title === false) return false;
5204 if (!titleProp.title && !titleProp["native"] || isFalse(titleProp.show)) return;
5205 var isTool = isTooltip(infoProp);
5206 var children = [titleProp.title];
5207
5208 var titleFn = function titleFn(pop) {
5209 return _this.$r(mergeProps([titleProp, {
5210 props: titleProp,
5211 slot: titleProp.slot || (pop ? 'default' : 'label'),
5212 key: "".concat(uni, "tit"),
5213 type: titleProp.type || 'span'
5214 }]), children);
5215 };
5216
5217 if (!isFalse(infoProp.show) && (infoProp.info || infoProp["native"])) {
5218 if (infoProp.icon !== false) {
5219 children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r({
5220 type: 'icon',
5221 props: {
5222 type: infoProp.icon === true ? 'question-circle-o' : infoProp.icon
5223 },
5224 key: "".concat(uni, "i")
5225 }));
5226 }
5227
5228 var prop = {
5229 type: infoProp.type || 'popover',
5230 props: _objectSpread2({}, infoProp),
5231 key: "".concat(uni, "pop"),
5232 slot: 'label'
5233 };
5234 var field = isTool ? 'title' : 'content';
5235
5236 if (infoProp.info && !hasProperty(prop.props, field)) {
5237 prop.props[field] = infoProp.info;
5238 }
5239
5240 return this.$r(mergeProps([infoProp, prop]), [titleFn(true)]);
5241 }
5242
5243 return titleFn();
5244 },
5245 makeCol: function makeCol(rule, uni, children) {
5246 var col = rule.col;
5247 return this.$r({
5248 "class": col["class"],
5249 type: 'col',
5250 props: col || {
5251 span: 24
5252 },
5253 key: "".concat(uni, "col")
5254 }, children);
5255 },
5256 makeRow: function makeRow(children) {
5257 var row = this.options.row || {};
5258 return this.$r({
5259 type: 'row',
5260 props: row,
5261 "class": row["class"],
5262 key: "".concat(this.key, "row")
5263 }, children);
5264 },
5265 makeFormBtn: function makeFormBtn() {
5266 var vn = [];
5267
5268 if (!isFalse(this.options.submitBtn.show)) {
5269 vn.push(this.makeSubmitBtn());
5270 }
5271
5272 if (!isFalse(this.options.resetBtn.show)) {
5273 vn.push(this.makeResetBtn());
5274 }
5275
5276 if (!vn.length) {
5277 return;
5278 }
5279
5280 var _this$rule$props2 = this.rule.props,
5281 labelCol = _this$rule$props2.labelCol,
5282 wrapperCol = _this$rule$props2.wrapperCol,
5283 layout = _this$rule$props2.layout;
5284
5285 if (layout !== 'horizontal') {
5286 labelCol = wrapperCol = {};
5287 }
5288
5289 var item = this.$r({
5290 type: 'formItem',
5291 key: "".concat(this.key, "fb"),
5292 props: {
5293 labelCol: labelCol,
5294 wrapperCol: wrapperCol,
5295 label: ' ',
5296 colon: false
5297 }
5298 }, vn);
5299 return layout === 'inline' ? item : this.$r({
5300 type: 'col',
5301 props: {
5302 span: 24
5303 },
5304 key: "".concat(this.key, "fc")
5305 }, [item]);
5306 },
5307 makeResetBtn: function makeResetBtn() {
5308 var _this2 = this;
5309
5310 var resetBtn = this.options.resetBtn;
5311 return this.$r({
5312 type: 'button',
5313 props: resetBtn,
5314 style: {
5315 width: resetBtn.width,
5316 marginLeft: '10px'
5317 },
5318 on: {
5319 click: function click() {
5320 var fApi = _this2.$handle.api;
5321 resetBtn.click ? resetBtn.click(fApi) : fApi.resetFields();
5322 }
5323 },
5324 key: "".concat(this.key, "b2")
5325 }, [resetBtn.innerText]);
5326 },
5327 makeSubmitBtn: function makeSubmitBtn() {
5328 var _this3 = this;
5329
5330 var submitBtn = this.options.submitBtn;
5331 return this.$r({
5332 type: 'button',
5333 props: submitBtn,
5334 style: {
5335 width: submitBtn.width
5336 },
5337 on: {
5338 click: function click() {
5339 var fApi = _this3.$handle.api;
5340 submitBtn.click ? submitBtn.click(fApi) : fApi.submit();
5341 }
5342 },
5343 key: "".concat(this.key, "b1")
5344 }, [submitBtn.innerText]);
5345 }
5346 };
5347
5348 var maker = {};
5349
5350 function useAlias(maker) {
5351 ['upload', 'frame', 'autoComplete', 'cascader', 'datePicker', 'frame', 'inputNumber', 'radio', 'rate', 'switch', 'rate', 'slider', 'timePicker'].reduce(function (maker, name) {
5352 maker[name] = creatorFactory(name);
5353 return maker;
5354 }, maker);
5355 maker.auto = maker.autoComplete;
5356 maker.number = maker.inputNumber;
5357 maker.time = maker.timePicker;
5358 }
5359
5360 function useFrame(maker) {
5361 var types = {
5362 frameInputs: ['input', 0],
5363 frameFiles: ['file', 0],
5364 frameImages: ['image', 0],
5365 frameInputOne: ['input', 1],
5366 frameFileOne: ['file', 1],
5367 frameImageOne: ['image', 1]
5368 };
5369 Object.keys(types).reduce(function (maker, key) {
5370 maker[key] = creatorFactory('frame', function (m) {
5371 return m.props({
5372 type: types[key][0],
5373 maxLength: types[key][1]
5374 });
5375 });
5376 return maker;
5377 }, maker);
5378 maker.frameInput = maker.frameInputs;
5379 maker.frameFile = maker.frameFiles;
5380 maker.frameImage = maker.frameImages;
5381 }
5382
5383 function useSlider(maker) {
5384 maker['sliderRange'] = creatorFactory('slider', {
5385 range: true
5386 });
5387 }
5388
5389 function useSelect(m) {
5390 m.selectMultiple = creatorFactory(name, {
5391 mode: 'multiple'
5392 });
5393 m.selectTags = creatorFactory(name, {
5394 mode: 'tags'
5395 });
5396 m.selectCombobox = creatorFactory(name, {
5397 mode: 'combobox'
5398 });
5399 }
5400
5401 function useUpload(maker) {
5402 var types = {
5403 image: ['image', 0],
5404 file: ['file', 0],
5405 uploadFileOne: ['file', 1],
5406 uploadImageOne: ['image', 1]
5407 };
5408 Object.keys(types).reduce(function (maker, key) {
5409 maker[key] = creatorFactory('upload', function (m) {
5410 return m.props({
5411 uploadType: types[key][0],
5412 maxLength: types[key][1]
5413 });
5414 });
5415 return maker;
5416 }, maker);
5417 maker.uploadImage = maker.image;
5418 maker.uploadFile = maker.file;
5419 }
5420
5421 useAlias(maker);
5422 useSlider(maker);
5423 useFrame(maker);
5424 useUpload(maker);
5425 useSelect(maker);
5426
5427 var css_248z$1 = ".form-create .form-create .ant-form-item {\n margin-bottom: 22px;\n}\n\n.form-create .form-create .ant-form-item .ant-form-item {\n margin-bottom: 0px;\n}\n\n.form-create .form-create .ant-form-item.ant-form-item-with-help {\n margin-bottom: 3px;\n}\n\n.form-create .form-create .ant-form-item .ant-form-item.ant-form-item-with-help {\n margin-bottom: -22px;\n}\n\n.form-create{\n transform: rotateZ(0);\n}\n";
5428 styleInject(css_248z$1);
5429
5430 function tidyBtnProp(btn, def) {
5431 if (is.Boolean(btn)) btn = {
5432 show: btn
5433 };else if (!is.Undef(btn) && !is.Object(btn)) btn = {
5434 show: def
5435 };
5436 return btn;
5437 }
5438
5439 function extendApi(api, h) {
5440 extend(api, {
5441 validate: function validate(callback) {
5442 var flag;
5443 var forms = api.children;
5444 var len = forms.length;
5445
5446 var validate = function validate() {
5447 h.$manager.validate(function () {
5448 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5449 args[_key] = arguments[_key];
5450 }
5451
5452 if (!args[0] || !flag) {
5453 flag = args;
5454 }
5455
5456 callback && callback.apply(void 0, _toConsumableArray(flag));
5457 });
5458 };
5459
5460 var validFn = function validFn(args) {
5461 setTimeout(function () {
5462 if (!args[0]) {
5463 if (!flag) {
5464 flag = args;
5465 }
5466 }
5467
5468 if (! --len) {
5469 validate();
5470 }
5471 });
5472 };
5473
5474 forms.forEach(function (form) {
5475 form.validate(function () {
5476 for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
5477 args[_key2] = arguments[_key2];
5478 }
5479
5480 return validFn(args);
5481 });
5482 });
5483
5484 if (!len) {
5485 validate();
5486 }
5487 },
5488 validateField: function validateField(field, callback) {
5489 var ctx = h.getFieldCtx(field);
5490 if (!ctx) return;
5491 var sub = h.subForm[ctx.id];
5492 var len = 0;
5493 var flag;
5494
5495 var validate = function validate() {
5496 h.$manager.validateField(ctx.id, function () {
5497 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
5498 args[_key3] = arguments[_key3];
5499 }
5500
5501 if (args[0]) {
5502 flag = args;
5503 } else if (flag) {
5504 return callback && callback('子表单验证未通过', flag[1]);
5505 }
5506
5507 callback && callback.apply(void 0, _toConsumableArray(flag || args));
5508 });
5509 };
5510
5511 var validFn = function validFn(args) {
5512 setTimeout(function () {
5513 if (!args[0]) {
5514 if (!flag) {
5515 flag = args;
5516 }
5517 }
5518
5519 if (! --len) {
5520 validate();
5521 }
5522 });
5523 };
5524
5525 sub && toArray(sub).forEach(function (form) {
5526 len++;
5527 form.validate(function () {
5528 for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
5529 args[_key4] = arguments[_key4];
5530 }
5531
5532 return validFn(args);
5533 });
5534 });
5535
5536 if (!len) {
5537 validate();
5538 }
5539 },
5540 clearValidateState: function clearValidateState(fields) {
5541 var _this = this;
5542
5543 var clearSub = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
5544 api.helper.tidyFields(fields).forEach(function (field) {
5545 if (clearSub) _this.clearSubValidateState(field);
5546 h.getCtxs(field).forEach(function (ctx) {
5547 h.$manager.clearValidateState(ctx);
5548 });
5549 });
5550 },
5551 clearSubValidateState: function clearSubValidateState(fields) {
5552 api.helper.tidyFields(fields).forEach(function (field) {
5553 h.getCtxs(field).forEach(function (ctx) {
5554 var subForm = h.subForm[ctx.id];
5555 if (!subForm) return;
5556
5557 if (Array.isArray(subForm)) {
5558 subForm.forEach(function (form) {
5559 form.clearValidateState();
5560 });
5561 } else if (subForm) {
5562 subForm.clearValidateState();
5563 }
5564 });
5565 });
5566 },
5567 btn: {
5568 loading: function loading() {
5569 var _loading = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5570
5571 api.submitBtnProps({
5572 loading: !!_loading
5573 });
5574 },
5575 disabled: function disabled() {
5576 var _disabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5577
5578 api.submitBtnProps({
5579 disabled: !!_disabled
5580 });
5581 },
5582 show: function show() {
5583 var isShow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5584 api.submitBtnProps({
5585 show: !!isShow
5586 });
5587 }
5588 },
5589 resetBtn: {
5590 loading: function loading() {
5591 var _loading2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5592
5593 api.resetBtnProps({
5594 loading: !!_loading2
5595 });
5596 },
5597 disabled: function disabled() {
5598 var _disabled2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5599
5600 api.resetBtnProps({
5601 disabled: !!_disabled2
5602 });
5603 },
5604 show: function show() {
5605 var isShow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5606 api.resetBtnProps({
5607 show: !!isShow
5608 });
5609 }
5610 },
5611 submitBtnProps: function submitBtnProps() {
5612 var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
5613 var btn = tidyBtnProp(h.options.submitBtn, true);
5614 extend(btn, props);
5615 h.options.submitBtn = btn;
5616 api.refreshOptions();
5617 },
5618 resetBtnProps: function resetBtnProps() {
5619 var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
5620 var btn = tidyBtnProp(h.options.resetBtn, false);
5621 extend(btn, props);
5622 h.options.resetBtn = btn;
5623 api.refreshOptions();
5624 },
5625 submit: function submit(successFn, failFn) {
5626 var _arguments = arguments,
5627 _this2 = this;
5628
5629 api.validate(function (valid) {
5630 if (valid) {
5631 var formData = api.formData();
5632 if (is.Function(successFn)) invoke(function () {
5633 return successFn(formData, _this2);
5634 });else {
5635 is.Function(h.options.onSubmit) && invoke(function () {
5636 return h.options.onSubmit(formData, _this2);
5637 });
5638 h.vm.$emit('submit', formData, _this2);
5639 }
5640 } else {
5641 is.Function(failFn) && invoke(function () {
5642 return failFn.apply(void 0, [_this2].concat(_toConsumableArray(_arguments)));
5643 });
5644 }
5645 });
5646 }
5647 });
5648 return api;
5649 }
5650
5651 function install(FormCreate) {
5652 FormCreate.componentAlias(alias);
5653 components.forEach(function (component) {
5654 FormCreate.component(component.name, component);
5655 });
5656 parsers.forEach(function (parser) {
5657 FormCreate.parser(parser);
5658 });
5659 Object.keys(maker).forEach(function (name) {
5660 FormCreate.maker[name] = maker[name];
5661 });
5662 }
5663
5664 function antdvFormCreate() {
5665 return FormCreateFactory({
5666 ui: "".concat("ant-design-vue"),
5667 version: "".concat("2.5.11"),
5668 manager: manager,
5669 install: install,
5670 extendApi: extendApi,
5671 attrs: {
5672 normal: ['col', 'wrap'],
5673 array: ['className'],
5674 key: ['title', 'info']
5675 }
5676 });
5677 }
5678
5679 var FormCreate = antdvFormCreate();
5680
5681 if (typeof window !== 'undefined') {
5682 window.formCreate = FormCreate;
5683
5684 if (window.Vue) {
5685 FormCreate.install(window.Vue);
5686 }
5687 }
5688
5689 var maker$1 = FormCreate.maker;
5690
5691 exports.default = FormCreate;
5692 exports.maker = maker$1;
5693
5694 Object.defineProperty(exports, '__esModule', { value: true });
5695
5696})));