@form-create/component-elm-group 3.1.2 → 3.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +119 -30
- package/dist/index.esm.min.js +2 -2
- package/dist/index.js +119 -30
- package/dist/index.min.js +2 -2
- package/package.json +3 -3
- package/src/component.jsx +11 -8
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.4
|
|
3
3
|
* (c) 2018-2022 xaboy
|
|
4
4
|
* Github https://github.com/xaboy/form-create with group
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -120,9 +120,28 @@ var is = {
|
|
|
120
120
|
},
|
|
121
121
|
trueArray: function trueArray(data) {
|
|
122
122
|
return Array.isArray(data) && data.length > 0;
|
|
123
|
+
},
|
|
124
|
+
Function: function Function(v) {
|
|
125
|
+
var type = this.getType(v);
|
|
126
|
+
return type === 'Function' || type === 'AsyncFunction';
|
|
127
|
+
},
|
|
128
|
+
getType: function getType(v) {
|
|
129
|
+
var str = Object.prototype.toString.call(v);
|
|
130
|
+
return /^\[object (.*)\]$/.exec(str)[1];
|
|
131
|
+
},
|
|
132
|
+
empty: function empty(value) {
|
|
133
|
+
if (value === undefined || value === null) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (Array.isArray(value) && Array.isArray(value) && !value.length) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return typeof value === 'string' && !value;
|
|
123
142
|
}
|
|
124
143
|
};
|
|
125
|
-
['Date', 'Object', '
|
|
144
|
+
['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
|
|
126
145
|
is[t] = function (arg) {
|
|
127
146
|
return is.type(arg, t);
|
|
128
147
|
};
|
|
@@ -190,6 +209,78 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
|
190
209
|
|
|
191
210
|
script.render = render;
|
|
192
211
|
|
|
212
|
+
function $set(target, field, value) {
|
|
213
|
+
target[field] = value;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function deepExtend(origin) {
|
|
217
|
+
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
218
|
+
var mode = arguments.length > 2 ? arguments[2] : undefined;
|
|
219
|
+
var isArr = false;
|
|
220
|
+
|
|
221
|
+
for (var key in target) {
|
|
222
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
223
|
+
var clone = target[key];
|
|
224
|
+
|
|
225
|
+
if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
|
|
226
|
+
var nst = origin[key] === undefined;
|
|
227
|
+
|
|
228
|
+
if (isArr) {
|
|
229
|
+
isArr = false;
|
|
230
|
+
nst && $set(origin, key, []);
|
|
231
|
+
} else if (clone._clone && mode !== undefined) {
|
|
232
|
+
if (mode) {
|
|
233
|
+
clone = clone.getRule();
|
|
234
|
+
nst && $set(origin, key, {});
|
|
235
|
+
} else {
|
|
236
|
+
$set(origin, key, clone._clone());
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
nst && $set(origin, key, {});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
origin[key] = deepExtend(origin[key], clone, mode);
|
|
244
|
+
} else {
|
|
245
|
+
$set(origin, key, clone);
|
|
246
|
+
|
|
247
|
+
if (!is.Undef(clone)) {
|
|
248
|
+
if (!is.Undef(clone.__json)) {
|
|
249
|
+
origin[key].__json = clone.__json;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!is.Undef(clone.__origin)) {
|
|
253
|
+
origin[key].__origin = clone.__origin;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
|
|
261
|
+
return !v || !v.__ctrl;
|
|
262
|
+
}) : origin;
|
|
263
|
+
}
|
|
264
|
+
function deepCopy(value) {
|
|
265
|
+
return deepExtend({}, {
|
|
266
|
+
value: value
|
|
267
|
+
}).value;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
var _extends = Object.assign || function (a) {
|
|
271
|
+
for (var b, c = 1; c < arguments.length; c++) {
|
|
272
|
+
for (var d in b = arguments[c], b) {
|
|
273
|
+
Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return a;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function extend() {
|
|
281
|
+
return _extends.apply(this, arguments);
|
|
282
|
+
}
|
|
283
|
+
|
|
193
284
|
function _isSlot(s) {
|
|
194
285
|
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
|
|
195
286
|
}
|
|
@@ -220,6 +311,7 @@ var Group = defineComponent({
|
|
|
220
311
|
return [];
|
|
221
312
|
}
|
|
222
313
|
},
|
|
314
|
+
defaultValue: Object,
|
|
223
315
|
disabled: {
|
|
224
316
|
type: Boolean,
|
|
225
317
|
"default": false
|
|
@@ -289,8 +381,6 @@ var Group = defineComponent({
|
|
|
289
381
|
for (var _i2 = 0; _i2 < len; _i2++) {
|
|
290
382
|
this.removeRule(keys[total - _i2 - 1]);
|
|
291
383
|
}
|
|
292
|
-
|
|
293
|
-
this.subForm();
|
|
294
384
|
}
|
|
295
385
|
|
|
296
386
|
n.forEach(function (val, i) {
|
|
@@ -298,8 +388,7 @@ var Group = defineComponent({
|
|
|
298
388
|
});
|
|
299
389
|
}
|
|
300
390
|
},
|
|
301
|
-
deep: true
|
|
302
|
-
flush: 'post'
|
|
391
|
+
deep: true
|
|
303
392
|
}
|
|
304
393
|
},
|
|
305
394
|
methods: {
|
|
@@ -356,6 +445,13 @@ var Group = defineComponent({
|
|
|
356
445
|
submitBtn: false,
|
|
357
446
|
resetBtn: false
|
|
358
447
|
};
|
|
448
|
+
|
|
449
|
+
if (this.defaultValue) {
|
|
450
|
+
if (!options.formData) options.formData = {};
|
|
451
|
+
var defVal = deepCopy(this.defaultValue);
|
|
452
|
+
extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
|
|
453
|
+
}
|
|
454
|
+
|
|
359
455
|
this.cacheRule[++this.len] = {
|
|
360
456
|
rule: rule,
|
|
361
457
|
options: options
|
|
@@ -371,7 +467,7 @@ var Group = defineComponent({
|
|
|
371
467
|
var _this4 = this;
|
|
372
468
|
|
|
373
469
|
this.cacheRule[key].$f = $f;
|
|
374
|
-
this.
|
|
470
|
+
this.formData(key, $f.formData());
|
|
375
471
|
nextTick(function () {
|
|
376
472
|
if (_this4.syncDisabled) {
|
|
377
473
|
$f.disabled(_this4.disabled);
|
|
@@ -380,15 +476,8 @@ var Group = defineComponent({
|
|
|
380
476
|
_this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
|
|
381
477
|
});
|
|
382
478
|
},
|
|
383
|
-
subForm: function subForm() {
|
|
384
|
-
var _this5 = this;
|
|
385
|
-
|
|
386
|
-
this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
|
|
387
|
-
return _this5.cacheRule[k].$f;
|
|
388
|
-
}));
|
|
389
|
-
},
|
|
390
479
|
removeRule: function removeRule(key, emit) {
|
|
391
|
-
var
|
|
480
|
+
var _this5 = this;
|
|
392
481
|
|
|
393
482
|
var index = Object.keys(this.cacheRule).indexOf(key);
|
|
394
483
|
delete this.cacheRule[key];
|
|
@@ -396,7 +485,7 @@ var Group = defineComponent({
|
|
|
396
485
|
|
|
397
486
|
if (emit) {
|
|
398
487
|
nextTick(function () {
|
|
399
|
-
return
|
|
488
|
+
return _this5.$emit('remove', index);
|
|
400
489
|
});
|
|
401
490
|
}
|
|
402
491
|
},
|
|
@@ -414,7 +503,6 @@ var Group = defineComponent({
|
|
|
414
503
|
}
|
|
415
504
|
|
|
416
505
|
this.removeRule(key, true);
|
|
417
|
-
this.subForm();
|
|
418
506
|
this.modelValue.splice(index, 1);
|
|
419
507
|
this.input(this.modelValue);
|
|
420
508
|
},
|
|
@@ -430,14 +518,14 @@ var Group = defineComponent({
|
|
|
430
518
|
});
|
|
431
519
|
},
|
|
432
520
|
delIcon: function delIcon(index, key) {
|
|
433
|
-
var
|
|
521
|
+
var _this6 = this;
|
|
434
522
|
|
|
435
523
|
return createVNode(resolveComponent("ElIcon"), {
|
|
436
524
|
"key": "d".concat(key),
|
|
437
525
|
"class": "el-icon-remove-outline",
|
|
438
526
|
"style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
|
|
439
527
|
"onClick": function onClick() {
|
|
440
|
-
return
|
|
528
|
+
return _this6.del(index, key);
|
|
441
529
|
}
|
|
442
530
|
}, {
|
|
443
531
|
"default": function _default() {
|
|
@@ -446,7 +534,7 @@ var Group = defineComponent({
|
|
|
446
534
|
});
|
|
447
535
|
},
|
|
448
536
|
makeIcon: function makeIcon(total, index, key) {
|
|
449
|
-
var
|
|
537
|
+
var _this7 = this;
|
|
450
538
|
|
|
451
539
|
if (this.$slots.button) {
|
|
452
540
|
return this.$slots.button({
|
|
@@ -455,7 +543,7 @@ var Group = defineComponent({
|
|
|
455
543
|
vm: this,
|
|
456
544
|
key: key,
|
|
457
545
|
del: function del() {
|
|
458
|
-
return
|
|
546
|
+
return _this7.del(index, key);
|
|
459
547
|
},
|
|
460
548
|
add: this.add
|
|
461
549
|
});
|
|
@@ -490,7 +578,7 @@ var Group = defineComponent({
|
|
|
490
578
|
}
|
|
491
579
|
},
|
|
492
580
|
render: function render() {
|
|
493
|
-
var
|
|
581
|
+
var _this8 = this;
|
|
494
582
|
|
|
495
583
|
var keys = Object.keys(this.cacheRule);
|
|
496
584
|
var button = this.button;
|
|
@@ -511,9 +599,9 @@ var Group = defineComponent({
|
|
|
511
599
|
}, [keys.map(function (key, index) {
|
|
512
600
|
var _slot;
|
|
513
601
|
|
|
514
|
-
var
|
|
515
|
-
rule =
|
|
516
|
-
options =
|
|
602
|
+
var _this8$cacheRule$key = _this8.cacheRule[key],
|
|
603
|
+
rule = _this8$cacheRule$key.rule,
|
|
604
|
+
options = _this8$cacheRule$key.options;
|
|
517
605
|
return createVNode(resolveComponent("ElRow"), {
|
|
518
606
|
"align": "middle",
|
|
519
607
|
"type": "flex",
|
|
@@ -529,19 +617,20 @@ var Group = defineComponent({
|
|
|
529
617
|
"default": function _default() {
|
|
530
618
|
return [createVNode(Type, {
|
|
531
619
|
"key": key,
|
|
620
|
+
"inFor": true,
|
|
532
621
|
"onUpdate:modelValue": function onUpdateModelValue(formData) {
|
|
533
|
-
return
|
|
622
|
+
return _this8.formData(key, formData);
|
|
534
623
|
},
|
|
535
|
-
"modelValue":
|
|
624
|
+
"modelValue": _this8.field ? _defineProperty({}, _this8.field, _this8._value(_this8.modelValue[index])) : _this8.modelValue[index],
|
|
536
625
|
"onEmit-event": function onEmitEvent(name) {
|
|
537
626
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
538
627
|
args[_key - 1] = arguments[_key];
|
|
539
628
|
}
|
|
540
629
|
|
|
541
|
-
return
|
|
630
|
+
return _this8.emitEvent(name, args, index, key);
|
|
542
631
|
},
|
|
543
632
|
"onUpdate:api": function onUpdateApi($f) {
|
|
544
|
-
return
|
|
633
|
+
return _this8.add$f(index, key, $f);
|
|
545
634
|
},
|
|
546
635
|
"rule": rule,
|
|
547
636
|
"option": options,
|
|
@@ -554,7 +643,7 @@ var Group = defineComponent({
|
|
|
554
643
|
"span": 2,
|
|
555
644
|
"pull": 1,
|
|
556
645
|
"push": 1
|
|
557
|
-
}, _isSlot(_slot =
|
|
646
|
+
}, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
|
|
558
647
|
"default": function _default() {
|
|
559
648
|
return [_slot];
|
|
560
649
|
}
|
package/dist/index.esm.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.4
|
|
3
3
|
* (c) 2018-2022 xaboy
|
|
4
4
|
* Github https://github.com/xaboy/form-create with group
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
|
-
import{openBlock as e,createElementBlock as t,createElementVNode as n,defineComponent as
|
|
7
|
+
import{openBlock as e,createElementBlock as t,createElementVNode as n,defineComponent as r,markRaw as o,nextTick as i,createVNode as l,resolveComponent as a,isVNode as u}from"vue";function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){d(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return p(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return p(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var m={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===f(e)&&null!==e&&1===e.nodeType&&!m.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){m[e]=function(t){return m.type(t,e)}}));var y={name:"IconCirclePlus"},b={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},v=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];y.render=function(n,r,o,i,l,a){return e(),t("svg",b,v)};var g={name:"IconRemove"},O={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},j=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function V(e,t,n){e[t]=n}function w(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((r=Array.isArray(i))||m.Object(i)){var l=void 0===e[o];if(r)r=!1,l&&V(e,o,[]);else if(i._clone&&void 0!==n){if(!n){V(e,o,i._clone());continue}i=i.getRule(),l&&V(e,o,{})}else l&&V(e,o,{});e[o]=w(e[o],i,n)}else V(e,o,i),m.Undef(i)||(m.Undef(i.__json)||(e[o].__json=i.__json),m.Undef(i.__origin)||(e[o].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function R(e){return w({},{value:e}).value}g.render=function(n,r,o,i,l,a){return e(),t("svg",O,j)};var x=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&V(e,r,t[r]);return e};var A=r({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:o(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),r=n.length,o=r-e.length;if(o<0){for(var i=o;i<0;i++)this.addRule(e.length+i);for(var l=0;l<r;l++)this.setValue(n[l],e[l])}else{if(o>0)for(var a=0;a<o;a++)this.removeRule(n[r-a-1]);e.forEach((function(r,o){t.setValue(n[o],e[o])}))}},deep:!0}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,o=Object.keys(r);if(o.filter((function(e){return r[e].$f})).length===o.length){var i=o.map((function(r){var o=e===r?t:s({},n.cacheRule[r].$f.form),i=n.field?o[n.field]||null:o;return n.cache(r,i),i}));this.input(i)}},setValue:function(e,t){var n=this.field;n&&(t=d({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,t){var n=this,r=this.formCreateInject.form.copyRules(this.rule||[]),o=this.options?s({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){o.formData||(o.formData={});var l=R(this.defaultValue);!function(){x.apply(this,arguments)}(o.formData,this.field?d({},this.field,l):l)}this.cacheRule[++this.len]={rule:r,options:o},t&&i((function(){return n.$emit("add",r,Object.keys(n.cacheRule).length-1)}))},add$f:function(e,t,n){var r=this;this.cacheRule[t].$f=n,this.formData(t,n.formData()),i((function(){r.syncDisabled&&n.disabled(r.disabled),r.$emit("itemMounted",n,Object.keys(r.cacheRule).indexOf(t))}))},removeRule:function(e,t){var n=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],t&&i((function(){return n.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return l(a("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}})},delIcon:function(e,t){var n=this;return l(a("ElIcon"),{key:"d".concat(t),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return n.del(e,t)}},{default:function(){return[l(g,null,null)]}})},makeIcon:function(e,t,n){var r=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return r.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,r){this.$emit.apply(this,[e].concat(h(t),[this.cacheRule[r].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,t=Object.keys(this.cacheRule),n=this.button,r=this.form;return 0===t.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):l(a("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}}):l("div",{key:2},[t.map((function(o,i){var c,s=e.cacheRule[o],f=s.rule,h=s.options;return l(a("ElRow"),{align:"middle",type:"flex",key:o,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[l(a("ElCol"),{span:n?20:24},{default:function(){return[l(a("ElFormItem"),null,{default:function(){return[l(r,{key:o,inFor:!0,"onUpdate:modelValue":function(t){return e.formData(o,t)},modelValue:e.field?d({},e.field,e._value(e.modelValue[i])):e.modelValue[i],"onEmit-event":function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),l=1;l<n;l++)r[l-1]=arguments[l];return e.emitEvent(t,r,i,o)},"onUpdate:api":function(t){return e.add$f(i,o,t)},rule:f,option:h,extendOption:!0},null)]}})]}}),n?l(a("ElCol"),{span:2,pull:1,push:1},(s=c=e.makeIcon(t.length,i,o),"function"==typeof s||"[object Object]"===Object.prototype.toString.call(s)&&!u(s)?c:{default:function(){return[c]}})):null];var s}})}))])}});export{A as default};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.4
|
|
3
3
|
* (c) 2018-2022 xaboy
|
|
4
4
|
* Github https://github.com/xaboy/form-create with group
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -124,9 +124,28 @@
|
|
|
124
124
|
},
|
|
125
125
|
trueArray: function trueArray(data) {
|
|
126
126
|
return Array.isArray(data) && data.length > 0;
|
|
127
|
+
},
|
|
128
|
+
Function: function Function(v) {
|
|
129
|
+
var type = this.getType(v);
|
|
130
|
+
return type === 'Function' || type === 'AsyncFunction';
|
|
131
|
+
},
|
|
132
|
+
getType: function getType(v) {
|
|
133
|
+
var str = Object.prototype.toString.call(v);
|
|
134
|
+
return /^\[object (.*)\]$/.exec(str)[1];
|
|
135
|
+
},
|
|
136
|
+
empty: function empty(value) {
|
|
137
|
+
if (value === undefined || value === null) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (Array.isArray(value) && Array.isArray(value) && !value.length) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return typeof value === 'string' && !value;
|
|
127
146
|
}
|
|
128
147
|
};
|
|
129
|
-
['Date', 'Object', '
|
|
148
|
+
['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
|
|
130
149
|
is[t] = function (arg) {
|
|
131
150
|
return is.type(arg, t);
|
|
132
151
|
};
|
|
@@ -194,6 +213,78 @@
|
|
|
194
213
|
|
|
195
214
|
script.render = render;
|
|
196
215
|
|
|
216
|
+
function $set(target, field, value) {
|
|
217
|
+
target[field] = value;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function deepExtend(origin) {
|
|
221
|
+
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
222
|
+
var mode = arguments.length > 2 ? arguments[2] : undefined;
|
|
223
|
+
var isArr = false;
|
|
224
|
+
|
|
225
|
+
for (var key in target) {
|
|
226
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
227
|
+
var clone = target[key];
|
|
228
|
+
|
|
229
|
+
if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
|
|
230
|
+
var nst = origin[key] === undefined;
|
|
231
|
+
|
|
232
|
+
if (isArr) {
|
|
233
|
+
isArr = false;
|
|
234
|
+
nst && $set(origin, key, []);
|
|
235
|
+
} else if (clone._clone && mode !== undefined) {
|
|
236
|
+
if (mode) {
|
|
237
|
+
clone = clone.getRule();
|
|
238
|
+
nst && $set(origin, key, {});
|
|
239
|
+
} else {
|
|
240
|
+
$set(origin, key, clone._clone());
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
nst && $set(origin, key, {});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
origin[key] = deepExtend(origin[key], clone, mode);
|
|
248
|
+
} else {
|
|
249
|
+
$set(origin, key, clone);
|
|
250
|
+
|
|
251
|
+
if (!is.Undef(clone)) {
|
|
252
|
+
if (!is.Undef(clone.__json)) {
|
|
253
|
+
origin[key].__json = clone.__json;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!is.Undef(clone.__origin)) {
|
|
257
|
+
origin[key].__origin = clone.__origin;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
|
|
265
|
+
return !v || !v.__ctrl;
|
|
266
|
+
}) : origin;
|
|
267
|
+
}
|
|
268
|
+
function deepCopy(value) {
|
|
269
|
+
return deepExtend({}, {
|
|
270
|
+
value: value
|
|
271
|
+
}).value;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var _extends = Object.assign || function (a) {
|
|
275
|
+
for (var b, c = 1; c < arguments.length; c++) {
|
|
276
|
+
for (var d in b = arguments[c], b) {
|
|
277
|
+
Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return a;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
function extend() {
|
|
285
|
+
return _extends.apply(this, arguments);
|
|
286
|
+
}
|
|
287
|
+
|
|
197
288
|
function _isSlot(s) {
|
|
198
289
|
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
|
|
199
290
|
}
|
|
@@ -224,6 +315,7 @@
|
|
|
224
315
|
return [];
|
|
225
316
|
}
|
|
226
317
|
},
|
|
318
|
+
defaultValue: Object,
|
|
227
319
|
disabled: {
|
|
228
320
|
type: Boolean,
|
|
229
321
|
"default": false
|
|
@@ -293,8 +385,6 @@
|
|
|
293
385
|
for (var _i2 = 0; _i2 < len; _i2++) {
|
|
294
386
|
this.removeRule(keys[total - _i2 - 1]);
|
|
295
387
|
}
|
|
296
|
-
|
|
297
|
-
this.subForm();
|
|
298
388
|
}
|
|
299
389
|
|
|
300
390
|
n.forEach(function (val, i) {
|
|
@@ -302,8 +392,7 @@
|
|
|
302
392
|
});
|
|
303
393
|
}
|
|
304
394
|
},
|
|
305
|
-
deep: true
|
|
306
|
-
flush: 'post'
|
|
395
|
+
deep: true
|
|
307
396
|
}
|
|
308
397
|
},
|
|
309
398
|
methods: {
|
|
@@ -360,6 +449,13 @@
|
|
|
360
449
|
submitBtn: false,
|
|
361
450
|
resetBtn: false
|
|
362
451
|
};
|
|
452
|
+
|
|
453
|
+
if (this.defaultValue) {
|
|
454
|
+
if (!options.formData) options.formData = {};
|
|
455
|
+
var defVal = deepCopy(this.defaultValue);
|
|
456
|
+
extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
|
|
457
|
+
}
|
|
458
|
+
|
|
363
459
|
this.cacheRule[++this.len] = {
|
|
364
460
|
rule: rule,
|
|
365
461
|
options: options
|
|
@@ -375,7 +471,7 @@
|
|
|
375
471
|
var _this4 = this;
|
|
376
472
|
|
|
377
473
|
this.cacheRule[key].$f = $f;
|
|
378
|
-
this.
|
|
474
|
+
this.formData(key, $f.formData());
|
|
379
475
|
vue.nextTick(function () {
|
|
380
476
|
if (_this4.syncDisabled) {
|
|
381
477
|
$f.disabled(_this4.disabled);
|
|
@@ -384,15 +480,8 @@
|
|
|
384
480
|
_this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
|
|
385
481
|
});
|
|
386
482
|
},
|
|
387
|
-
subForm: function subForm() {
|
|
388
|
-
var _this5 = this;
|
|
389
|
-
|
|
390
|
-
this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
|
|
391
|
-
return _this5.cacheRule[k].$f;
|
|
392
|
-
}));
|
|
393
|
-
},
|
|
394
483
|
removeRule: function removeRule(key, emit) {
|
|
395
|
-
var
|
|
484
|
+
var _this5 = this;
|
|
396
485
|
|
|
397
486
|
var index = Object.keys(this.cacheRule).indexOf(key);
|
|
398
487
|
delete this.cacheRule[key];
|
|
@@ -400,7 +489,7 @@
|
|
|
400
489
|
|
|
401
490
|
if (emit) {
|
|
402
491
|
vue.nextTick(function () {
|
|
403
|
-
return
|
|
492
|
+
return _this5.$emit('remove', index);
|
|
404
493
|
});
|
|
405
494
|
}
|
|
406
495
|
},
|
|
@@ -418,7 +507,6 @@
|
|
|
418
507
|
}
|
|
419
508
|
|
|
420
509
|
this.removeRule(key, true);
|
|
421
|
-
this.subForm();
|
|
422
510
|
this.modelValue.splice(index, 1);
|
|
423
511
|
this.input(this.modelValue);
|
|
424
512
|
},
|
|
@@ -434,14 +522,14 @@
|
|
|
434
522
|
});
|
|
435
523
|
},
|
|
436
524
|
delIcon: function delIcon(index, key) {
|
|
437
|
-
var
|
|
525
|
+
var _this6 = this;
|
|
438
526
|
|
|
439
527
|
return vue.createVNode(vue.resolveComponent("ElIcon"), {
|
|
440
528
|
"key": "d".concat(key),
|
|
441
529
|
"class": "el-icon-remove-outline",
|
|
442
530
|
"style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
|
|
443
531
|
"onClick": function onClick() {
|
|
444
|
-
return
|
|
532
|
+
return _this6.del(index, key);
|
|
445
533
|
}
|
|
446
534
|
}, {
|
|
447
535
|
"default": function _default() {
|
|
@@ -450,7 +538,7 @@
|
|
|
450
538
|
});
|
|
451
539
|
},
|
|
452
540
|
makeIcon: function makeIcon(total, index, key) {
|
|
453
|
-
var
|
|
541
|
+
var _this7 = this;
|
|
454
542
|
|
|
455
543
|
if (this.$slots.button) {
|
|
456
544
|
return this.$slots.button({
|
|
@@ -459,7 +547,7 @@
|
|
|
459
547
|
vm: this,
|
|
460
548
|
key: key,
|
|
461
549
|
del: function del() {
|
|
462
|
-
return
|
|
550
|
+
return _this7.del(index, key);
|
|
463
551
|
},
|
|
464
552
|
add: this.add
|
|
465
553
|
});
|
|
@@ -494,7 +582,7 @@
|
|
|
494
582
|
}
|
|
495
583
|
},
|
|
496
584
|
render: function render() {
|
|
497
|
-
var
|
|
585
|
+
var _this8 = this;
|
|
498
586
|
|
|
499
587
|
var keys = Object.keys(this.cacheRule);
|
|
500
588
|
var button = this.button;
|
|
@@ -515,9 +603,9 @@
|
|
|
515
603
|
}, [keys.map(function (key, index) {
|
|
516
604
|
var _slot;
|
|
517
605
|
|
|
518
|
-
var
|
|
519
|
-
rule =
|
|
520
|
-
options =
|
|
606
|
+
var _this8$cacheRule$key = _this8.cacheRule[key],
|
|
607
|
+
rule = _this8$cacheRule$key.rule,
|
|
608
|
+
options = _this8$cacheRule$key.options;
|
|
521
609
|
return vue.createVNode(vue.resolveComponent("ElRow"), {
|
|
522
610
|
"align": "middle",
|
|
523
611
|
"type": "flex",
|
|
@@ -533,19 +621,20 @@
|
|
|
533
621
|
"default": function _default() {
|
|
534
622
|
return [vue.createVNode(Type, {
|
|
535
623
|
"key": key,
|
|
624
|
+
"inFor": true,
|
|
536
625
|
"onUpdate:modelValue": function onUpdateModelValue(formData) {
|
|
537
|
-
return
|
|
626
|
+
return _this8.formData(key, formData);
|
|
538
627
|
},
|
|
539
|
-
"modelValue":
|
|
628
|
+
"modelValue": _this8.field ? _defineProperty({}, _this8.field, _this8._value(_this8.modelValue[index])) : _this8.modelValue[index],
|
|
540
629
|
"onEmit-event": function onEmitEvent(name) {
|
|
541
630
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
542
631
|
args[_key - 1] = arguments[_key];
|
|
543
632
|
}
|
|
544
633
|
|
|
545
|
-
return
|
|
634
|
+
return _this8.emitEvent(name, args, index, key);
|
|
546
635
|
},
|
|
547
636
|
"onUpdate:api": function onUpdateApi($f) {
|
|
548
|
-
return
|
|
637
|
+
return _this8.add$f(index, key, $f);
|
|
549
638
|
},
|
|
550
639
|
"rule": rule,
|
|
551
640
|
"option": options,
|
|
@@ -558,7 +647,7 @@
|
|
|
558
647
|
"span": 2,
|
|
559
648
|
"pull": 1,
|
|
560
649
|
"push": 1
|
|
561
|
-
}, _isSlot(_slot =
|
|
650
|
+
}, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
|
|
562
651
|
"default": function _default() {
|
|
563
652
|
return [_slot];
|
|
564
653
|
}
|
package/dist/index.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.4
|
|
3
3
|
* (c) 2018-2022 xaboy
|
|
4
4
|
* Github https://github.com/xaboy/form-create with group
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FcGroup={},e.Vue)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){l(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var a={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===r(e)&&null!==e&&1===e.nodeType&&!a.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0}};["Date","Object","Function","String","Boolean","Array","Number"].forEach((function(e){a[e]=function(t){return a.type(t,e)}}));var c={name:"IconCirclePlus"},s={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},d=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];c.render=function(e,n,o,r,l,i){return t.openBlock(),t.createElementBlock("svg",s,d)};var f={name:"IconRemove"},h={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},m=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];f.render=function(e,n,o,r,l,i){return t.openBlock(),t.createElementBlock("svg",h,m)};var p=t.defineComponent({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),o=n.length,r=o-e.length;if(r<0){for(var l=r;l<0;l++)this.addRule(e.length+l);for(var i=0;i<o;i++)this.setValue(n[i],e[i])}else{if(r>0){for(var u=0;u<r;u++)this.removeRule(n[o-u-1]);this.subForm()}e.forEach((function(o,r){t.setValue(n[r],e[r])}))}},deep:!0,flush:"post"}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,l=Object.keys(r);if(l.filter((function(e){return r[e].$f})).length===l.length){var i=l.map((function(r){var l=e===r?t:o({},n.cacheRule[r].$f.form),i=n.field?l[n.field]||null:l;return n.cache(r,i),i}));this.input(i)}},setValue:function(e,t){var n=this.field;n&&(t=l({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,n){var r=this,l=this.formCreateInject.form.copyRules(this.rule||[]),i=this.options?o({},this.options):{submitBtn:!1,resetBtn:!1};this.cacheRule[++this.len]={rule:l,options:i},n&&t.nextTick((function(){return r.$emit("add",l,Object.keys(r.cacheRule).length-1)}))},add$f:function(e,n,o){var r=this;this.cacheRule[n].$f=o,this.subForm(),t.nextTick((function(){r.syncDisabled&&o.disabled(r.disabled),r.$emit("itemMounted",o,Object.keys(r.cacheRule).indexOf(n))}))},subForm:function(){var e=this;this.formCreateInject.subForm(Object.keys(this.cacheRule).map((function(t){return e.cacheRule[t].$f})))},removeRule:function(e,n){var o=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return o.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.subForm(),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return t.createVNode(t.resolveComponent("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}})},delIcon:function(e,n){var o=this;return t.createVNode(t.resolveComponent("ElIcon"),{key:"d".concat(n),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return o.del(e,n)}},{default:function(){return[t.createVNode(f,null,null)]}})},makeIcon:function(e,t,n){var o=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return o.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,o){this.$emit.apply(this,[e].concat(i(t),[this.cacheRule[o].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,n=Object.keys(this.cacheRule),o=this.button,r=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(t.resolveComponent("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}}):t.createVNode("div",{key:2},[n.map((function(i,u){var a,c=e.cacheRule[i],s=c.rule,d=c.options;return t.createVNode(t.resolveComponent("ElRow"),{align:"middle",type:"flex",key:i,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("ElCol"),{span:o?20:24},{default:function(){return[t.createVNode(t.resolveComponent("ElFormItem"),null,{default:function(){return[t.createVNode(r,{key:i,"onUpdate:modelValue":function(t){return e.formData(i,t)},modelValue:e.field?l({},e.field,e._value(e.modelValue[u])):e.modelValue[u],"onEmit-event":function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return e.emitEvent(t,o,u,i)},"onUpdate:api":function(t){return e.add$f(u,i,t)},rule:s,option:d,extendOption:!0},null)]}})]}}),o?t.createVNode(t.resolveComponent("ElCol"),{span:2,pull:1,push:1},(c=a=e.makeIcon(n.length,u,i),"function"==typeof c||"[object Object]"===Object.prototype.toString.call(c)&&!t.isVNode(c)?a:{default:function(){return[a]}})):null];var c}})}))])}});e.default=p,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
7
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FcGroup={},e.Vue)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){i(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var u={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===r(e)&&null!==e&&1===e.nodeType&&!u.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){u[e]=function(t){return u.type(t,e)}}));var c={name:"IconCirclePlus"},s={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},f=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];c.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",s,f)};var d={name:"IconRemove"},h={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},p=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function m(e,t,n){e[t]=n}function y(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,o=!1;for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];if((o=Array.isArray(i))||u.Object(i)){var l=void 0===e[r];if(o)o=!1,l&&m(e,r,[]);else if(i._clone&&void 0!==n){if(!n){m(e,r,i._clone());continue}i=i.getRule(),l&&m(e,r,{})}else l&&m(e,r,{});e[r]=y(e[r],i,n)}else m(e,r,i),u.Undef(i)||(u.Undef(i.__json)||(e[r].__json=i.__json),u.Undef(i.__origin)||(e[r].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function v(e){return y({},{value:e}).value}d.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",h,p)};var b=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&m(e,o,t[o]);return e};var g=t.defineComponent({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),o=n.length,r=o-e.length;if(r<0){for(var i=r;i<0;i++)this.addRule(e.length+i);for(var l=0;l<o;l++)this.setValue(n[l],e[l])}else{if(r>0)for(var a=0;a<r;a++)this.removeRule(n[o-a-1]);e.forEach((function(o,r){t.setValue(n[r],e[r])}))}},deep:!0}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,i=Object.keys(r);if(i.filter((function(e){return r[e].$f})).length===i.length){var l=i.map((function(r){var i=e===r?t:o({},n.cacheRule[r].$f.form),l=n.field?i[n.field]||null:i;return n.cache(r,l),l}));this.input(l)}},setValue:function(e,t){var n=this.field;n&&(t=i({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,n){var r=this,l=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?o({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var u=v(this.defaultValue);!function(){b.apply(this,arguments)}(a.formData,this.field?i({},this.field,u):u)}this.cacheRule[++this.len]={rule:l,options:a},n&&t.nextTick((function(){return r.$emit("add",l,Object.keys(r.cacheRule).length-1)}))},add$f:function(e,n,o){var r=this;this.cacheRule[n].$f=o,this.formData(n,o.formData()),t.nextTick((function(){r.syncDisabled&&o.disabled(r.disabled),r.$emit("itemMounted",o,Object.keys(r.cacheRule).indexOf(n))}))},removeRule:function(e,n){var o=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return o.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return t.createVNode(t.resolveComponent("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}})},delIcon:function(e,n){var o=this;return t.createVNode(t.resolveComponent("ElIcon"),{key:"d".concat(n),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return o.del(e,n)}},{default:function(){return[t.createVNode(d,null,null)]}})},makeIcon:function(e,t,n){var o=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return o.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,o){this.$emit.apply(this,[e].concat(l(t),[this.cacheRule[o].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,n=Object.keys(this.cacheRule),o=this.button,r=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(t.resolveComponent("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}}):t.createVNode("div",{key:2},[n.map((function(l,a){var u,c=e.cacheRule[l],s=c.rule,f=c.options;return t.createVNode(t.resolveComponent("ElRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("ElCol"),{span:o?20:24},{default:function(){return[t.createVNode(t.resolveComponent("ElFormItem"),null,{default:function(){return[t.createVNode(r,{key:l,inFor:!0,"onUpdate:modelValue":function(t){return e.formData(l,t)},modelValue:e.field?i({},e.field,e._value(e.modelValue[a])):e.modelValue[a],"onEmit-event":function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return e.emitEvent(t,o,a,l)},"onUpdate:api":function(t){return e.add$f(a,l,t)},rule:s,option:f,extendOption:!0},null)]}})]}}),o?t.createVNode(t.resolveComponent("ElCol"),{span:2,pull:1,push:1},(c=u=e.makeIcon(n.length,a,l),"function"==typeof c||"[object Object]"===Object.prototype.toString.call(c)&&!t.isVNode(c)?u:{default:function(){return[u]}})):null];var c}})}))])}});e.default=g,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@form-create/component-elm-group",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
4
4
|
"description": "@form-create/element-ui 内置组件",
|
|
5
5
|
"main": "./dist/index.min.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"author": "xaboy",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@form-create/utils": "^3.1.
|
|
33
|
+
"@form-create/utils": "^3.1.3"
|
|
34
34
|
},
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/xaboy/form-create/issues"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"esm"
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b5de4ac94ee1ca6cc33170dc5894a4a715a7e491"
|
|
51
51
|
}
|
package/src/component.jsx
CHANGED
|
@@ -2,9 +2,12 @@ import {hasProperty} from '@form-create/utils/lib/type';
|
|
|
2
2
|
import {defineComponent, markRaw, nextTick} from 'vue';
|
|
3
3
|
import IconCirclePlus from './IconCirclePlus.vue';
|
|
4
4
|
import IconRemove from './IconRemove.vue';
|
|
5
|
+
import {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
6
|
+
import extend from '@form-create/utils/lib/extend';
|
|
5
7
|
|
|
6
8
|
const NAME = 'fcGroup';
|
|
7
9
|
|
|
10
|
+
|
|
8
11
|
export default defineComponent({
|
|
9
12
|
name: NAME,
|
|
10
13
|
props: {
|
|
@@ -28,6 +31,7 @@ export default defineComponent({
|
|
|
28
31
|
type: Array,
|
|
29
32
|
default: () => []
|
|
30
33
|
},
|
|
34
|
+
defaultValue: Object,
|
|
31
35
|
disabled: {
|
|
32
36
|
type: Boolean,
|
|
33
37
|
default: false
|
|
@@ -92,7 +96,6 @@ export default defineComponent({
|
|
|
92
96
|
for (let i = 0; i < len; i++) {
|
|
93
97
|
this.removeRule(keys[total - i - 1]);
|
|
94
98
|
}
|
|
95
|
-
this.subForm();
|
|
96
99
|
}
|
|
97
100
|
n.forEach((val, i) => {
|
|
98
101
|
this.setValue(keys[i], n[i]);
|
|
@@ -100,7 +103,6 @@ export default defineComponent({
|
|
|
100
103
|
}
|
|
101
104
|
},
|
|
102
105
|
deep: true,
|
|
103
|
-
flush: 'post',
|
|
104
106
|
}
|
|
105
107
|
},
|
|
106
108
|
methods: {
|
|
@@ -144,6 +146,11 @@ export default defineComponent({
|
|
|
144
146
|
submitBtn: false,
|
|
145
147
|
resetBtn: false,
|
|
146
148
|
};
|
|
149
|
+
if (this.defaultValue) {
|
|
150
|
+
if (!options.formData) options.formData = {};
|
|
151
|
+
const defVal = deepCopy(this.defaultValue);
|
|
152
|
+
extend(options.formData, this.field ? {[this.field]: defVal} : defVal);
|
|
153
|
+
}
|
|
147
154
|
this.cacheRule[++this.len] = {rule, options};
|
|
148
155
|
if (emit) {
|
|
149
156
|
nextTick(() => this.$emit('add', rule, Object.keys(this.cacheRule).length - 1));
|
|
@@ -151,7 +158,7 @@ export default defineComponent({
|
|
|
151
158
|
},
|
|
152
159
|
add$f(i, key, $f) {
|
|
153
160
|
this.cacheRule[key].$f = $f;
|
|
154
|
-
this.
|
|
161
|
+
this.formData(key, $f.formData());
|
|
155
162
|
nextTick(() => {
|
|
156
163
|
if (this.syncDisabled) {
|
|
157
164
|
$f.disabled(this.disabled);
|
|
@@ -159,9 +166,6 @@ export default defineComponent({
|
|
|
159
166
|
this.$emit('itemMounted', $f, Object.keys(this.cacheRule).indexOf(key));
|
|
160
167
|
});
|
|
161
168
|
},
|
|
162
|
-
subForm() {
|
|
163
|
-
this.formCreateInject.subForm(Object.keys(this.cacheRule).map(k => this.cacheRule[k].$f));
|
|
164
|
-
},
|
|
165
169
|
removeRule(key, emit) {
|
|
166
170
|
const index = Object.keys(this.cacheRule).indexOf(key);
|
|
167
171
|
delete this.cacheRule[key];
|
|
@@ -182,7 +186,6 @@ export default defineComponent({
|
|
|
182
186
|
return;
|
|
183
187
|
}
|
|
184
188
|
this.removeRule(key, true);
|
|
185
|
-
this.subForm();
|
|
186
189
|
this.modelValue.splice(index, 1);
|
|
187
190
|
this.input(this.modelValue);
|
|
188
191
|
},
|
|
@@ -254,7 +257,7 @@ export default defineComponent({
|
|
|
254
257
|
return <ElRow align="middle" type="flex" key={key}
|
|
255
258
|
style="border-bottom:1px dashed #DCDFE6;margin-bottom:10px;">
|
|
256
259
|
<ElCol span={button ? 20 : 24}><ElFormItem><Type
|
|
257
|
-
key={key}
|
|
260
|
+
key={key} inFor={true}
|
|
258
261
|
onUpdate:modelValue={(formData) => this.formData(key, formData)}
|
|
259
262
|
modelValue={this.field ? {[this.field]: this._value(this.modelValue[index])} : this.modelValue[index]}
|
|
260
263
|
onEmit-event={(name, ...args) => this.emitEvent(name, args, index, key)}
|