UNPKG

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