@form-create/component-antdv-group 3.1.3 → 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.3
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),
@@ -378,17 +398,14 @@ var Group = defineComponent({
378
398
  for (var _i2 = 0; _i2 < len; _i2++) {
379
399
  this.removeRule(keys[total - _i2 - 1]);
380
400
  }
381
-
382
- this.subForm();
383
401
  }
384
402
 
385
403
  n.forEach(function (val, i) {
386
- _this.setValue(keys[i], n[i]);
404
+ _this2.setValue(keys[i], n[i]);
387
405
  });
388
406
  }
389
407
  },
390
- deep: true,
391
- flush: 'post'
408
+ deep: true
392
409
  }
393
410
  },
394
411
  methods: {
@@ -403,7 +420,7 @@ var Group = defineComponent({
403
420
  this.$emit('change', value);
404
421
  },
405
422
  formData: function formData(key, _formData) {
406
- var _this2 = this;
423
+ var _this3 = this;
407
424
 
408
425
  var cacheRule = this.cacheRule;
409
426
  var keys = Object.keys(cacheRule);
@@ -415,10 +432,10 @@ var Group = defineComponent({
415
432
  }
416
433
 
417
434
  var value = keys.map(function (k) {
418
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
419
- 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;
420
437
 
421
- _this2.cache(k, value);
438
+ _this3.cache(k, value);
422
439
 
423
440
  return value;
424
441
  });
@@ -438,7 +455,7 @@ var Group = defineComponent({
438
455
  this.cache(key, value);
439
456
  },
440
457
  addRule: function addRule(i, emit) {
441
- var _this3 = this;
458
+ var _this4 = this;
442
459
 
443
460
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
444
461
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -459,31 +476,23 @@ var Group = defineComponent({
459
476
 
460
477
  if (emit) {
461
478
  nextTick(function () {
462
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
479
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
463
480
  });
464
481
  }
465
482
  },
466
483
  add$f: function add$f(i, key, $f) {
467
- var _this4 = this;
484
+ var _this5 = this;
468
485
 
469
486
  this.cacheRule[key].$f = $f;
470
- this.subForm();
471
487
  this.formData(key, $f.formData());
472
488
  nextTick(function () {
473
- if (_this4.syncDisabled) {
474
- $f.disabled(_this4.disabled);
489
+ if (_this5.syncDisabled) {
490
+ $f.disabled(_this5.disabled);
475
491
  }
476
492
 
477
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
493
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
478
494
  });
479
495
  },
480
- subForm: function subForm() {
481
- var _this5 = this;
482
-
483
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
484
- return _this5.cacheRule[k].$f;
485
- }));
486
- },
487
496
  removeRule: function removeRule(key, emit) {
488
497
  var _this6 = this;
489
498
 
@@ -511,7 +520,6 @@ var Group = defineComponent({
511
520
  }
512
521
 
513
522
  this.removeRule(key, true);
514
- this.subForm();
515
523
  this.modelValue.splice(index, 1);
516
524
  this.input(this.modelValue);
517
525
  },
@@ -611,6 +619,7 @@ var Group = defineComponent({
611
619
  "default": function _default() {
612
620
  return [createVNode(Type, {
613
621
  "key": key,
622
+ "inFor": true,
614
623
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
615
624
  return _this9.formData(key, formData);
616
625
  },
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-antdv-group v3.1.3
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 m(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 m(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 m(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 m(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 p={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&&!p.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){p[e]=function(t){return p.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))||p.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),p.Undef(i)||(p.Undef(i.__json)||(e[o].__json=i.__json),p.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]);this.subForm()}e.forEach((function(r,o){t.setValue(n[o],e[o])}))}},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,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.subForm(),this.formData(t,n.formData()),i((function(){r.syncDisabled&&n.disabled(r.disabled),r.$emit("itemMounted",n,Object.keys(r.cacheRule).indexOf(t))}))},subForm:function(){var e=this;this.formCreateInject.subForm(Object.keys(this.cacheRule).map((function(t){return e.cacheRule[t].$f})))},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.subForm(),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,"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.3
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),
@@ -382,17 +402,14 @@
382
402
  for (var _i2 = 0; _i2 < len; _i2++) {
383
403
  this.removeRule(keys[total - _i2 - 1]);
384
404
  }
385
-
386
- this.subForm();
387
405
  }
388
406
 
389
407
  n.forEach(function (val, i) {
390
- _this.setValue(keys[i], n[i]);
408
+ _this2.setValue(keys[i], n[i]);
391
409
  });
392
410
  }
393
411
  },
394
- deep: true,
395
- flush: 'post'
412
+ deep: true
396
413
  }
397
414
  },
398
415
  methods: {
@@ -407,7 +424,7 @@
407
424
  this.$emit('change', value);
408
425
  },
409
426
  formData: function formData(key, _formData) {
410
- var _this2 = this;
427
+ var _this3 = this;
411
428
 
412
429
  var cacheRule = this.cacheRule;
413
430
  var keys = Object.keys(cacheRule);
@@ -419,10 +436,10 @@
419
436
  }
420
437
 
421
438
  var value = keys.map(function (k) {
422
- var data = key === k ? _formData : _objectSpread2({}, _this2.cacheRule[k].$f.form);
423
- 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;
424
441
 
425
- _this2.cache(k, value);
442
+ _this3.cache(k, value);
426
443
 
427
444
  return value;
428
445
  });
@@ -442,7 +459,7 @@
442
459
  this.cache(key, value);
443
460
  },
444
461
  addRule: function addRule(i, emit) {
445
- var _this3 = this;
462
+ var _this4 = this;
446
463
 
447
464
  var rule = this.formCreateInject.form.copyRules(this.rule || []);
448
465
  var options = this.options ? _objectSpread2({}, this.options) : {
@@ -463,31 +480,23 @@
463
480
 
464
481
  if (emit) {
465
482
  vue.nextTick(function () {
466
- return _this3.$emit('add', rule, Object.keys(_this3.cacheRule).length - 1);
483
+ return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1);
467
484
  });
468
485
  }
469
486
  },
470
487
  add$f: function add$f(i, key, $f) {
471
- var _this4 = this;
488
+ var _this5 = this;
472
489
 
473
490
  this.cacheRule[key].$f = $f;
474
- this.subForm();
475
491
  this.formData(key, $f.formData());
476
492
  vue.nextTick(function () {
477
- if (_this4.syncDisabled) {
478
- $f.disabled(_this4.disabled);
493
+ if (_this5.syncDisabled) {
494
+ $f.disabled(_this5.disabled);
479
495
  }
480
496
 
481
- _this4.$emit('itemMounted', $f, Object.keys(_this4.cacheRule).indexOf(key));
497
+ _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key));
482
498
  });
483
499
  },
484
- subForm: function subForm() {
485
- var _this5 = this;
486
-
487
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(function (k) {
488
- return _this5.cacheRule[k].$f;
489
- }));
490
- },
491
500
  removeRule: function removeRule(key, emit) {
492
501
  var _this6 = this;
493
502
 
@@ -515,7 +524,6 @@
515
524
  }
516
525
 
517
526
  this.removeRule(key, true);
518
- this.subForm();
519
527
  this.modelValue.splice(index, 1);
520
528
  this.input(this.modelValue);
521
529
  },
@@ -615,6 +623,7 @@
615
623
  "default": function _default() {
616
624
  return [vue.createVNode(Type, {
617
625
  "key": key,
626
+ "inFor": true,
618
627
  "onUpdate:modelValue": function onUpdateModelValue(formData) {
619
628
  return _this9.formData(key, formData);
620
629
  },
package/dist/index.min.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @form-create/component-antdv-group v3.1.3
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"},m=[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 p(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&&p(e,o,[]);else if(i._clone&&void 0!==n){if(!n){p(e,o,i._clone());continue}i=i.getRule(),l&&p(e,o,{})}else l&&p(e,o,{});e[o]=y(e[o],i,n)}else p(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 b(e){return y({},{value:e}).value}d.render=function(e,n,r,o,i,l){return t.openBlock(),t.createElementBlock("span",h,m)};var v=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)&&p(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]);this.subForm()}e.forEach((function(r,o){t.setValue(n[o],e[o])}))}},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,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=b(this.defaultValue);!function(){v.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.subForm(),this.formData(n,r.formData()),t.nextTick((function(){o.syncDisabled&&r.disabled(o.disabled),o.$emit("itemMounted",r,Object.keys(o.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 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.subForm(),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,"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.3",
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": "7188700dc7590edc798b756d6d4d353b9b004512"
59
+ "gitHead": "9d63687a68a176d73b663191119d01271430b682"
60
60
  }
package/src/component.jsx CHANGED
@@ -2,11 +2,12 @@ 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';
9
9
 
10
+
10
11
  export default defineComponent({
11
12
  name: NAME,
12
13
  props: {
@@ -65,6 +66,23 @@ export default defineComponent({
65
66
  },
66
67
  emits: ['update:modelValue', 'change', 'itemMounted', 'remove'],
67
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
+ },
68
86
  disabled(n) {
69
87
  if (this.syncDisabled) {
70
88
  const lst = this.cacheRule;
@@ -95,7 +113,6 @@ export default defineComponent({
95
113
  for (let i = 0; i < len; i++) {
96
114
  this.removeRule(keys[total - i - 1]);
97
115
  }
98
- this.subForm();
99
116
  }
100
117
  n.forEach((val, i) => {
101
118
  this.setValue(keys[i], n[i]);
@@ -103,7 +120,6 @@ export default defineComponent({
103
120
  }
104
121
  },
105
122
  deep: true,
106
- flush: 'post',
107
123
  }
108
124
  },
109
125
  methods: {
@@ -159,7 +175,6 @@ export default defineComponent({
159
175
  },
160
176
  add$f(i, key, $f) {
161
177
  this.cacheRule[key].$f = $f;
162
- this.subForm();
163
178
  this.formData(key, $f.formData());
164
179
  nextTick(() => {
165
180
  if (this.syncDisabled) {
@@ -168,9 +183,6 @@ export default defineComponent({
168
183
  this.$emit('itemMounted', $f, Object.keys(this.cacheRule).indexOf(key));
169
184
  });
170
185
  },
171
- subForm() {
172
- this.formCreateInject.subForm(Object.keys(this.cacheRule).map(k => this.cacheRule[k].$f));
173
- },
174
186
  removeRule(key, emit) {
175
187
  const index = Object.keys(this.cacheRule).indexOf(key);
176
188
  delete this.cacheRule[key];
@@ -191,7 +203,6 @@ export default defineComponent({
191
203
  return;
192
204
  }
193
205
  this.removeRule(key, true);
194
- this.subForm();
195
206
  this.modelValue.splice(index, 1);
196
207
  this.input(this.modelValue);
197
208
  },
@@ -257,7 +268,7 @@ export default defineComponent({
257
268
  return <aRow align="middle" type="flex" key={key}
258
269
  style="border-bottom:1px dashed #DCDFE6;margin-bottom:10px;">
259
270
  <aCol span={button ? 20 : 24}><Type
260
- key={key}
271
+ key={key} inFor={true}
261
272
  onUpdate:modelValue={(formData) => this.formData(key, formData)}
262
273
  modelValue={this.field ? {[this.field]: this._value(this.modelValue[index])} : this.modelValue[index]}
263
274
  onEmit-event={(name, ...args) => this.emitEvent(name, args, index, key)}