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