UNPKG

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