@form-create/component-antdv-group 3.1.5 → 3.1.6

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @form-create/component-antdv-group v3.1.4
2
+ * @form-create/component-antdv-group v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
@@ -341,6 +341,26 @@ var Group = defineComponent({
341
341
  },
342
342
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
343
343
  watch: {
344
+ rule: {
345
+ handler: function handler(n, o) {
346
+ var _this = this;
347
+
348
+ Object.keys(this.cacheRule).forEach(function (v) {
349
+ var item = _this.cacheRule[v];
350
+
351
+ if (n === o) {
352
+ deepExtend(item.rule, n);
353
+ } else {
354
+ var val = item.$f.formData();
355
+ item.$f.once('reloading', function () {
356
+ item.$f.setValue(val);
357
+ });
358
+ item.rule = deepCopy(n);
359
+ }
360
+ });
361
+ },
362
+ deep: true
363
+ },
344
364
  disabled: function disabled(n) {
345
365
  if (this.syncDisabled) {
346
366
  var lst = this.cacheRule;
@@ -358,7 +378,7 @@ var Group = defineComponent({
358
378
  },
359
379
  modelValue: {
360
380
  handler: function handler(n) {
361
- var _this = this;
381
+ var _this2 = this;
362
382
 
363
383
  n = n || [];
364
384
  var keys = Object.keys(this.cacheRule),
@@ -381,7 +401,7 @@ var Group = defineComponent({
381
401
  }
382
402
 
383
403
  n.forEach(function (val, i) {
384
- _this.setValue(keys[i], n[i]);
404
+ _this2.setValue(keys[i], n[i]);
385
405
  });
386
406
  }
387
407
  },
@@ -400,7 +420,7 @@ var Group = defineComponent({
400
420
  this.$emit('change', value);
401
421
  },
402
422
  formData: function formData(key, _formData) {
403
- var _this2 = this;
423
+ var _this3 = this;
404
424
 
405
425
  var cacheRule = this.cacheRule;
406
426
  var keys = Object.keys(cacheRule);
@@ -412,10 +432,10 @@ var Group = defineComponent({
412
432
  }
413
433
 
414
434
  var value = keys.map(function (k) {
415
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
416
- var value = _this2.field ? data[_this2.field] || null : data;
435
+ var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form);
436
+ var value = _this3.field ? data[_this3.field] || null : data;
417
437
 
418
- _this2.cache(k, value);
438
+ _this3.cache(k, value);
419
439
 
420
440
  return value;
421
441
  });
@@ -435,7 +455,7 @@ var Group = defineComponent({
435
455
  this.cache(key, value);
436
456
  },
437
457
  addRule: function addRule(i, emit) {
438
- var _this3 = this;
458
+ var _this4 = this;
439
459
 
440
460
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
441
461
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -456,25 +476,25 @@ var Group = defineComponent({
456
476
 
457
477
  if (emit) {
458
478
  nextTick(function () {
459
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
479
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
460
480
  });
461
481
  }
462
482
  },
463
483
  add$f: function add$f(i, key, $f) {
464
- var _this4 = this;
484
+ var _this5 = this;
465
485
 
466
486
  this.cacheRule[key].$f = $f;
467
487
  this.formData(key, $f.formData());
468
488
  nextTick(function () {
469
- if (_this4.syncDisabled) {
470
- $f.disabled(_this4.disabled);
489
+ if (_this5.syncDisabled) {
490
+ $f.disabled(_this5.disabled);
471
491
  }
472
492
 
473
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
493
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
474
494
  });
475
495
  },
476
496
  removeRule: function removeRule(key, emit) {
477
- var _this5 = this;
497
+ var _this6 = this;
478
498
 
479
499
  var index = Object.keys(this.cacheRule).indexOf(key);
480
500
  delete this.cacheRule[key];
@@ -482,7 +502,7 @@ var Group = defineComponent({
482
502
 
483
503
  if (emit) {
484
504
  nextTick(function () {
485
- return _this5.$emit('remove', index);
505
+ return _this6.$emit('remove', index);
486
506
  });
487
507
  }
488
508
  },
@@ -511,18 +531,18 @@ var Group = defineComponent({
511
531
  }, null);
512
532
  },
513
533
  delIcon: function delIcon(index, key) {
514
- var _this6 = this;
534
+ var _this7 = this;
515
535
 
516
536
  return createVNode(script$1, {
517
537
  "key": "d".concat(key),
518
538
  "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
519
539
  "onClick": function onClick() {
520
- return _this6.del(index, key);
540
+ return _this7.del(index, key);
521
541
  }
522
542
  }, null);
523
543
  },
524
544
  makeIcon: function makeIcon(total, index, key) {
525
- var _this7 = this;
545
+ var _this8 = this;
526
546
 
527
547
  if (this.$slots.button) {
528
548
  return this.$slots.button({
@@ -531,7 +551,7 @@ var Group = defineComponent({
531
551
  vm: this,
532
552
  key: key,
533
553
  del: function del() {
534
- return _this7.del(index, key);
554
+ return _this8.del(index, key);
535
555
  },
536
556
  add: this.add
537
557
  });
@@ -566,7 +586,7 @@ var Group = defineComponent({
566
586
  }
567
587
  },
568
588
  render: function render() {
569
- var _this8 = this;
589
+ var _this9 = this;
570
590
 
571
591
  var keys = Object.keys(this.cacheRule);
572
592
  var button = this.button;
@@ -583,9 +603,9 @@ var Group = defineComponent({
583
603
  }, [keys.map(function (key, index) {
584
604
  var _slot;
585
605
 
586
- var _this8$cacheRule$key = _this8.cacheRule[key],
587
- rule = _this8$cacheRule$key.rule,
588
- options = _this8$cacheRule$key.options;
606
+ var _this9$cacheRule$key = _this9.cacheRule[key],
607
+ rule = _this9$cacheRule$key.rule,
608
+ options = _this9$cacheRule$key.options;
589
609
  return createVNode(resolveComponent("aRow"), {
590
610
  "align": "middle",
591
611
  "type": "flex",
@@ -601,18 +621,18 @@ var Group = defineComponent({
601
621
  "key": key,
602
622
  "inFor": true,
603
623
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
604
- return _this8.formData(key, formData);
624
+ return _this9.formData(key, formData);
605
625
  },
606
- "modelValue": _this8.field ? _defineProperty({}, _this8.field, _this8._value(_this8.modelValue[index])) : _this8.modelValue[index],
626
+ "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
607
627
  "onEmit-event": function onEmitEvent(name) {
608
628
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
609
629
  args[_key - 1] = arguments[_key];
610
630
  }
611
631
 
612
- return _this8.emitEvent(name, args, index, key);
632
+ return _this9.emitEvent(name, args, index, key);
613
633
  },
614
634
  "onUpdate:api": function onUpdateApi($f) {
615
- return _this8.add$f(index, key, $f);
635
+ return _this9.add$f(index, key, $f);
616
636
  },
617
637
  "rule": rule,
618
638
  "option": options,
@@ -623,7 +643,7 @@ var Group = defineComponent({
623
643
  "span": 2,
624
644
  "pull": 1,
625
645
  "push": 1
626
- }, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
646
+ }, _isSlot(_slot = _this9.makeIcon(keys.length, index, key)) ? _slot : {
627
647
  "default": function _default() {
628
648
  return [_slot];
629
649
  }
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-antdv-group v3.1.4
2
+ * @form-create/component-antdv-group v3.1.6
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 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:"MinusCircleOutlined"},b={class:"anticon"},v=[n("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[n("path",{d:"M696 480H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h368c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),n("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-1)];y.render=function(n,r,o,i,l,a){return e(),t("span",b,v)};var g={name:"PlusCircleOutlined"},O={class:"anticon"},j=[n("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[n("path",{d:"M696 480H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),n("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-1)];function w(e,t,n){e[t]=n}function V(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&&w(e,o,[]);else if(i._clone&&void 0!==n){if(!n){w(e,o,i._clone());continue}i=i.getRule(),l&&w(e,o,{})}else l&&w(e,o,{});e[o]=V(e[o],i,n)}else w(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 V({},{value:e}).value}g.render=function(n,r,o,i,l,a){return e(),t("span",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)&&w(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(g,{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},null)},delIcon:function(e,t){var n=this;return l(y,{key:"d".concat(t),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)}},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(g,{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},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("aRow"),{align:"middle",type:"flex",key:o,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[l(a("aCol"),{span:n?20:24},{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("aCol"),{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};
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:"MinusCircleOutlined"},v={class:"anticon"},b=[n("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[n("path",{d:"M696 480H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h368c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),n("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-1)];y.render=function(n,r,o,i,l,a){return e(),t("span",v,b)};var g={name:"PlusCircleOutlined"},O={class:"anticon"},j=[n("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[n("path",{d:"M696 480H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),n("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-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("span",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:{rule:{handler:function(e,t){var n=this;Object.keys(this.cacheRule).forEach((function(r){var o=n.cacheRule[r];if(e===t)w(o.rule,e);else{var i=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(i)})),o.rule=R(e)}}))},deep:!0},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(g,{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},null)},delIcon:function(e,t){var n=this;return l(y,{key:"d".concat(t),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)}},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(g,{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},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("aRow"),{align:"middle",type:"flex",key:o,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[l(a("aCol"),{span:n?20:24},{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("aCol"),{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-antdv-group v3.1.4
2
+ * @form-create/component-antdv-group v3.1.6
3
3
  * (c) 2018-2022 xaboy
4
4
  * Github https://github.com/xaboy/form-create with group
5
5
  * Released under the MIT License.
@@ -345,6 +345,26 @@
345
345
  },
346
346
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
347
347
  watch: {
348
+ rule: {
349
+ handler: function handler(n, o) {
350
+ var _this = this;
351
+
352
+ Object.keys(this.cacheRule).forEach(function (v) {
353
+ var item = _this.cacheRule[v];
354
+
355
+ if (n === o) {
356
+ deepExtend(item.rule, n);
357
+ } else {
358
+ var val = item.$f.formData();
359
+ item.$f.once('reloading', function () {
360
+ item.$f.setValue(val);
361
+ });
362
+ item.rule = deepCopy(n);
363
+ }
364
+ });
365
+ },
366
+ deep: true
367
+ },
348
368
  disabled: function disabled(n) {
349
369
  if (this.syncDisabled) {
350
370
  var lst = this.cacheRule;
@@ -362,7 +382,7 @@
362
382
  },
363
383
  modelValue: {
364
384
  handler: function handler(n) {
365
- var _this = this;
385
+ var _this2 = this;
366
386
 
367
387
  n = n || [];
368
388
  var keys = Object.keys(this.cacheRule),
@@ -385,7 +405,7 @@
385
405
  }
386
406
 
387
407
  n.forEach(function (val, i) {
388
- _this.setValue(keys[i], n[i]);
408
+ _this2.setValue(keys[i], n[i]);
389
409
  });
390
410
  }
391
411
  },
@@ -404,7 +424,7 @@
404
424
  this.$emit('change', value);
405
425
  },
406
426
  formData: function formData(key, _formData) {
407
- var _this2 = this;
427
+ var _this3 = this;
408
428
 
409
429
  var cacheRule = this.cacheRule;
410
430
  var keys = Object.keys(cacheRule);
@@ -416,10 +436,10 @@
416
436
  }
417
437
 
418
438
  var value = keys.map(function (k) {
419
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
420
- var value = _this2.field ? data[_this2.field] || null : data;
439
+ var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form);
440
+ var value = _this3.field ? data[_this3.field] || null : data;
421
441
 
422
- _this2.cache(k, value);
442
+ _this3.cache(k, value);
423
443
 
424
444
  return value;
425
445
  });
@@ -439,7 +459,7 @@
439
459
  this.cache(key, value);
440
460
  },
441
461
  addRule: function addRule(i, emit) {
442
- var _this3 = this;
462
+ var _this4 = this;
443
463
 
444
464
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
445
465
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -460,25 +480,25 @@
460
480
 
461
481
  if (emit) {
462
482
  vue.nextTick(function () {
463
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
483
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
464
484
  });
465
485
  }
466
486
  },
467
487
  add$f: function add$f(i, key, $f) {
468
- var _this4 = this;
488
+ var _this5 = this;
469
489
 
470
490
  this.cacheRule[key].$f = $f;
471
491
  this.formData(key, $f.formData());
472
492
  vue.nextTick(function () {
473
- if (_this4.syncDisabled) {
474
- $f.disabled(_this4.disabled);
493
+ if (_this5.syncDisabled) {
494
+ $f.disabled(_this5.disabled);
475
495
  }
476
496
 
477
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
497
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
478
498
  });
479
499
  },
480
500
  removeRule: function removeRule(key, emit) {
481
- var _this5 = this;
501
+ var _this6 = this;
482
502
 
483
503
  var index = Object.keys(this.cacheRule).indexOf(key);
484
504
  delete this.cacheRule[key];
@@ -486,7 +506,7 @@
486
506
 
487
507
  if (emit) {
488
508
  vue.nextTick(function () {
489
- return _this5.$emit('remove', index);
509
+ return _this6.$emit('remove', index);
490
510
  });
491
511
  }
492
512
  },
@@ -515,18 +535,18 @@
515
535
  }, null);
516
536
  },
517
537
  delIcon: function delIcon(index, key) {
518
- var _this6 = this;
538
+ var _this7 = this;
519
539
 
520
540
  return vue.createVNode(script$1, {
521
541
  "key": "d".concat(key),
522
542
  "style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266', ";"),
523
543
  "onClick": function onClick() {
524
- return _this6.del(index, key);
544
+ return _this7.del(index, key);
525
545
  }
526
546
  }, null);
527
547
  },
528
548
  makeIcon: function makeIcon(total, index, key) {
529
- var _this7 = this;
549
+ var _this8 = this;
530
550
 
531
551
  if (this.$slots.button) {
532
552
  return this.$slots.button({
@@ -535,7 +555,7 @@
535
555
  vm: this,
536
556
  key: key,
537
557
  del: function del() {
538
- return _this7.del(index, key);
558
+ return _this8.del(index, key);
539
559
  },
540
560
  add: this.add
541
561
  });
@@ -570,7 +590,7 @@
570
590
  }
571
591
  },
572
592
  render: function render() {
573
- var _this8 = this;
593
+ var _this9 = this;
574
594
 
575
595
  var keys = Object.keys(this.cacheRule);
576
596
  var button = this.button;
@@ -587,9 +607,9 @@
587
607
  }, [keys.map(function (key, index) {
588
608
  var _slot;
589
609
 
590
- var _this8$cacheRule$key = _this8.cacheRule[key],
591
- rule = _this8$cacheRule$key.rule,
592
- options = _this8$cacheRule$key.options;
610
+ var _this9$cacheRule$key = _this9.cacheRule[key],
611
+ rule = _this9$cacheRule$key.rule,
612
+ options = _this9$cacheRule$key.options;
593
613
  return vue.createVNode(vue.resolveComponent("aRow"), {
594
614
  "align": "middle",
595
615
  "type": "flex",
@@ -605,18 +625,18 @@
605
625
  "key": key,
606
626
  "inFor": true,
607
627
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
608
- return _this8.formData(key, formData);
628
+ return _this9.formData(key, formData);
609
629
  },
610
- "modelValue": _this8.field ? _defineProperty({}, _this8.field, _this8._value(_this8.modelValue[index])) : _this8.modelValue[index],
630
+ "modelValue": _this9.field ? _defineProperty({}, _this9.field, _this9._value(_this9.modelValue[index])) : _this9.modelValue[index],
611
631
  "onEmit-event": function onEmitEvent(name) {
612
632
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
613
633
  args[_key - 1] = arguments[_key];
614
634
  }
615
635
 
616
- return _this8.emitEvent(name, args, index, key);
636
+ return _this9.emitEvent(name, args, index, key);
617
637
  },
618
638
  "onUpdate:api": function onUpdateApi($f) {
619
- return _this8.add$f(index, key, $f);
639
+ return _this9.add$f(index, key, $f);
620
640
  },
621
641
  "rule": rule,
622
642
  "option": options,
@@ -627,7 +647,7 @@
627
647
  "span": 2,
628
648
  "pull": 1,
629
649
  "push": 1
630
- }, _isSlot(_slot = _this8.makeIcon(keys.length, index, key)) ? _slot : {
650
+ }, _isSlot(_slot = _this9.makeIcon(keys.length, index, key)) ? _slot : {
631
651
  "default": function _default() {
632
652
  return [_slot];
633
653
  }
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-antdv-group v3.1.4
2
+ * @form-create/component-antdv-group v3.1.6
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 r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function r(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function o(e){return o="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},o(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,r=new Array(t);n<t;n++)r[n]=e[n];return r}var c={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===o(e)&&null!==e&&1===e.nodeType&&!c.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){c[e]=function(t){return c.type(t,e)}}));var u={name:"MinusCircleOutlined"},s={class:"anticon"},f=[t.createElementVNode("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[t.createElementVNode("path",{d:"M696 480H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h368c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),t.createElementVNode("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-1)];u.render=function(e,n,r,o,i,l){return t.openBlock(),t.createElementBlock("span",s,f)};var d={name:"PlusCircleOutlined"},h={class:"anticon"},p=[t.createElementVNode("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[t.createElementVNode("path",{d:"M696 480H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),t.createElementVNode("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-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,r=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((r=Array.isArray(i))||c.Object(i)){var l=void 0===e[o];if(r)r=!1,l&&m(e,o,[]);else if(i._clone&&void 0!==n){if(!n){m(e,o,i._clone());continue}i=i.getRule(),l&&m(e,o,{})}else l&&m(e,o,{});e[o]=y(e[o],i,n)}else m(e,o,i),c.Undef(i)||(c.Undef(i.__json)||(e[o].__json=i.__json),c.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 v(e){return y({},{value:e}).value}d.render=function(e,n,r,o,i,l){return t.openBlock(),t.createElementBlock("span",h,p)};var b=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)&&m(e,r,t[r]);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),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,o=this.cacheRule,i=Object.keys(o);if(i.filter((function(e){return o[e].$f})).length===i.length){var l=i.map((function(o){var i=e===o?t:r({},n.cacheRule[o].$f.form),l=n.field?i[n.field]||null:i;return n.cache(o,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 o=this,l=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?r({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var c=v(this.defaultValue);!function(){b.apply(this,arguments)}(a.formData,this.field?i({},this.field,c):c)}this.cacheRule[++this.len]={rule:l,options:a},n&&t.nextTick((function(){return o.$emit("add",l,Object.keys(o.cacheRule).length-1)}))},add$f:function(e,n,r){var o=this;this.cacheRule[n].$f=r,this.formData(n,r.formData()),t.nextTick((function(){o.syncDisabled&&r.disabled(o.disabled),o.$emit("itemMounted",r,Object.keys(o.cacheRule).indexOf(n))}))},removeRule:function(e,n){var r=this,o=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return r.$emit("remove",o)}))},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(d,{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},null)},delIcon:function(e,n){var r=this;return t.createVNode(u,{key:"d".concat(n),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return r.del(e,n)}},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(l(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,n=Object.keys(this.cacheRule),r=this.button,o=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(d,{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},null):t.createVNode("div",{key:2},[n.map((function(l,a){var c,u=e.cacheRule[l],s=u.rule,f=u.options;return t.createVNode(t.resolveComponent("aRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("aCol"),{span:r?20:24},{default:function(){return[t.createVNode(o,{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,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return e.emitEvent(t,r,a,l)},"onUpdate:api":function(t){return e.add$f(a,l,t)},rule:s,option:f,extendOption:!0},null)]}}),r?t.createVNode(t.resolveComponent("aCol"),{span:2,pull:1,push:1},(u=c=e.makeIcon(n.length,a,l),"function"==typeof u||"[object Object]"===Object.prototype.toString.call(u)&&!t.isVNode(u)?c:{default:function(){return[c]}})):null];var u}})}))])}});e.default=g,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 r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function r(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function o(e){return o="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},o(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,r=new Array(t);n<t;n++)r[n]=e[n];return r}var c={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===o(e)&&null!==e&&1===e.nodeType&&!c.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){c[e]=function(t){return c.type(t,e)}}));var u={name:"MinusCircleOutlined"},s={class:"anticon"},f=[t.createElementVNode("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[t.createElementVNode("path",{d:"M696 480H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h368c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),t.createElementVNode("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-1)];u.render=function(e,n,r,o,i,l){return t.openBlock(),t.createElementBlock("span",s,f)};var d={name:"PlusCircleOutlined"},h={class:"anticon"},p=[t.createElementVNode("svg",{height:"1em",width:"1em",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 1024 1024"},[t.createElementVNode("path",{d:"M696 480H544V328c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v152H328c-4.4 0-8 3.6-8 8v48c0 4.4 3.6 8 8 8h152v152c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V544h152c4.4 0 8-3.6 8-8v-48c0-4.4-3.6-8-8-8z",fill:"currentColor"}),t.createElementVNode("path",{d:"M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",fill:"currentColor"})],-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,r=!1;for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];if((r=Array.isArray(i))||c.Object(i)){var l=void 0===e[o];if(r)r=!1,l&&m(e,o,[]);else if(i._clone&&void 0!==n){if(!n){m(e,o,i._clone());continue}i=i.getRule(),l&&m(e,o,{})}else l&&m(e,o,{});e[o]=y(e[o],i,n)}else m(e,o,i),c.Undef(i)||(c.Undef(i.__json)||(e[o].__json=i.__json),c.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 v(e){return y({},{value:e}).value}d.render=function(e,n,r,o,i,l){return t.openBlock(),t.createElementBlock("span",h,p)};var b=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)&&m(e,r,t[r]);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:{rule:{handler:function(e,t){var n=this;Object.keys(this.cacheRule).forEach((function(r){var o=n.cacheRule[r];if(e===t)y(o.rule,e);else{var i=o.$f.formData();o.$f.once("reloading",(function(){o.$f.setValue(i)})),o.rule=v(e)}}))},deep:!0},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,o=this.cacheRule,i=Object.keys(o);if(i.filter((function(e){return o[e].$f})).length===i.length){var l=i.map((function(o){var i=e===o?t:r({},n.cacheRule[o].$f.form),l=n.field?i[n.field]||null:i;return n.cache(o,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 o=this,l=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?r({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var c=v(this.defaultValue);!function(){b.apply(this,arguments)}(a.formData,this.field?i({},this.field,c):c)}this.cacheRule[++this.len]={rule:l,options:a},n&&t.nextTick((function(){return o.$emit("add",l,Object.keys(o.cacheRule).length-1)}))},add$f:function(e,n,r){var o=this;this.cacheRule[n].$f=r,this.formData(n,r.formData()),t.nextTick((function(){o.syncDisabled&&r.disabled(o.disabled),o.$emit("itemMounted",r,Object.keys(o.cacheRule).indexOf(n))}))},removeRule:function(e,n){var r=this,o=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return r.$emit("remove",o)}))},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(d,{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},null)},delIcon:function(e,n){var r=this;return t.createVNode(u,{key:"d".concat(n),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return r.del(e,n)}},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(l(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,n=Object.keys(this.cacheRule),r=this.button,o=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(d,{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},null):t.createVNode("div",{key:2},[n.map((function(l,a){var c,u=e.cacheRule[l],s=u.rule,f=u.options;return t.createVNode(t.resolveComponent("aRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("aCol"),{span:r?20:24},{default:function(){return[t.createVNode(o,{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,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return e.emitEvent(t,r,a,l)},"onUpdate:api":function(t){return e.add$f(a,l,t)},rule:s,option:f,extendOption:!0},null)]}}),r?t.createVNode(t.resolveComponent("aCol"),{span:2,pull:1,push:1},(u=c=e.makeIcon(n.length,a,l),"function"==typeof u||"[object Object]"===Object.prototype.toString.call(u)&&!t.isVNode(u)?c:{default:function(){return[c]}})):null];var u}})}))])}});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-antdv-group",
3
- "version": "3.1.5",
3
+ "version": "3.1.6",
4
4
  "description": "@form-create/ant-design-vue 内置组件",
5
5
  "main": "./dist/index.min.js",
6
6
  "module": "./dist/index.esm.js",
@@ -56,5 +56,5 @@
56
56
  "esm"
57
57
  ]
58
58
  },
59
- "gitHead": "b5de4ac94ee1ca6cc33170dc5894a4a715a7e491"
59
+ "gitHead": "9d63687a68a176d73b663191119d01271430b682"
60
60
  }
package/src/component.jsx CHANGED
@@ -2,7 +2,7 @@ import {hasProperty} from '@form-create/utils/lib/type';
2
2
  import {defineComponent, markRaw, nextTick} from 'vue';
3
3
  import MinusCircleOutlined from './MinusCircleOutlined.vue';
4
4
  import PlusCircleOutlined from './PlusCircleOutlined.vue';
5
- import {deepCopy} from '@form-create/utils/lib/deepextend';
5
+ import deepExtend, {deepCopy} from '@form-create/utils/lib/deepextend';
6
6
  import extend from '@form-create/utils/lib/extend';
7
7
 
8
8
  const NAME = 'fcGroup';
@@ -66,6 +66,23 @@ export default defineComponent({
66
66
  },
67
67
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
68
68
  watch: {
69
+ rule: {
70
+ handler(n, o) {
71
+ Object.keys(this.cacheRule).forEach(v => {
72
+ const item = this.cacheRule[v];
73
+ if (n === o) {
74
+ deepExtend(item.rule, n)
75
+ } else {
76
+ const val = item.$f.formData();
77
+ item.$f.once('reloading', () => {
78
+ item.$f.setValue(val);
79
+ })
80
+ item.rule = deepCopy(n);
81
+ }
82
+ })
83
+ },
84
+ deep: true
85
+ },
69
86
  disabled(n) {
70
87
  if (this.syncDisabled) {
71
88
  const lst = this.cacheRule;