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