@form-create/component-elm-group 3.1.0 → 3.1.3
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 +171 -9
- package/dist/index.esm.min.js +2 -2
- package/dist/index.js +170 -8
- package/dist/index.min.js +2 -2
- package/package.json +3 -3
- package/src/IconCirclePlus.vue +14 -0
- package/src/IconRemove.vue +13 -0
- package/src/component.jsx +19 -6
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.3
|
|
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 { defineComponent, markRaw, nextTick, createVNode, resolveComponent, isVNode } from 'vue';
|
|
7
|
+
import { openBlock, createElementBlock, createElementVNode, defineComponent, markRaw, nextTick, createVNode, resolveComponent, isVNode } from 'vue';
|
|
8
8
|
|
|
9
9
|
function ownKeys(object, enumerableOnly) {
|
|
10
10
|
var keys = Object.keys(object);
|
|
@@ -120,9 +120,28 @@ var is = {
|
|
|
120
120
|
},
|
|
121
121
|
trueArray: function trueArray(data) {
|
|
122
122
|
return Array.isArray(data) && data.length > 0;
|
|
123
|
+
},
|
|
124
|
+
Function: function Function(v) {
|
|
125
|
+
var type = this.getType(v);
|
|
126
|
+
return type === 'Function' || type === 'AsyncFunction';
|
|
127
|
+
},
|
|
128
|
+
getType: function getType(v) {
|
|
129
|
+
var str = Object.prototype.toString.call(v);
|
|
130
|
+
return /^\[object (.*)\]$/.exec(str)[1];
|
|
131
|
+
},
|
|
132
|
+
empty: function empty(value) {
|
|
133
|
+
if (value === undefined || value === null) {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (Array.isArray(value) && Array.isArray(value) && !value.length) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return typeof value === 'string' && !value;
|
|
123
142
|
}
|
|
124
143
|
};
|
|
125
|
-
['Date', 'Object', '
|
|
144
|
+
['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
|
|
126
145
|
is[t] = function (arg) {
|
|
127
146
|
return is.type(arg, t);
|
|
128
147
|
};
|
|
@@ -131,6 +150,137 @@ function hasProperty(rule, k) {
|
|
|
131
150
|
return {}.hasOwnProperty.call(rule, k);
|
|
132
151
|
}
|
|
133
152
|
|
|
153
|
+
var script$1 = {
|
|
154
|
+
name: 'IconCirclePlus'
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
var _hoisted_1$1 = {
|
|
158
|
+
"class": "icon",
|
|
159
|
+
viewBox: "0 0 1024 1024",
|
|
160
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
var _hoisted_2$1 = /*#__PURE__*/createElementVNode("path", {
|
|
164
|
+
fill: "currentColor",
|
|
165
|
+
d: "M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"
|
|
166
|
+
}, null, -1);
|
|
167
|
+
|
|
168
|
+
var _hoisted_3$1 = /*#__PURE__*/createElementVNode("path", {
|
|
169
|
+
fill: "currentColor",
|
|
170
|
+
d: "M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"
|
|
171
|
+
}, null, -1);
|
|
172
|
+
|
|
173
|
+
var _hoisted_4$1 = /*#__PURE__*/createElementVNode("path", {
|
|
174
|
+
fill: "currentColor",
|
|
175
|
+
d: "M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"
|
|
176
|
+
}, null, -1);
|
|
177
|
+
|
|
178
|
+
var _hoisted_5 = [_hoisted_2$1, _hoisted_3$1, _hoisted_4$1];
|
|
179
|
+
function render$1(_ctx, _cache, $props, $setup, $data, $options) {
|
|
180
|
+
return openBlock(), createElementBlock("svg", _hoisted_1$1, _hoisted_5);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
script$1.render = render$1;
|
|
184
|
+
|
|
185
|
+
var script = {
|
|
186
|
+
name: 'IconRemove'
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
var _hoisted_1 = {
|
|
190
|
+
"class": "icon",
|
|
191
|
+
viewBox: "0 0 1024 1024",
|
|
192
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
var _hoisted_2 = /*#__PURE__*/createElementVNode("path", {
|
|
196
|
+
fill: "currentColor",
|
|
197
|
+
d: "M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"
|
|
198
|
+
}, null, -1);
|
|
199
|
+
|
|
200
|
+
var _hoisted_3 = /*#__PURE__*/createElementVNode("path", {
|
|
201
|
+
fill: "currentColor",
|
|
202
|
+
d: "M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"
|
|
203
|
+
}, null, -1);
|
|
204
|
+
|
|
205
|
+
var _hoisted_4 = [_hoisted_2, _hoisted_3];
|
|
206
|
+
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
207
|
+
return openBlock(), createElementBlock("svg", _hoisted_1, _hoisted_4);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
script.render = render;
|
|
211
|
+
|
|
212
|
+
function $set(target, field, value) {
|
|
213
|
+
target[field] = value;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function deepExtend(origin) {
|
|
217
|
+
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
218
|
+
var mode = arguments.length > 2 ? arguments[2] : undefined;
|
|
219
|
+
var isArr = false;
|
|
220
|
+
|
|
221
|
+
for (var key in target) {
|
|
222
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
223
|
+
var clone = target[key];
|
|
224
|
+
|
|
225
|
+
if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
|
|
226
|
+
var nst = origin[key] === undefined;
|
|
227
|
+
|
|
228
|
+
if (isArr) {
|
|
229
|
+
isArr = false;
|
|
230
|
+
nst && $set(origin, key, []);
|
|
231
|
+
} else if (clone._clone && mode !== undefined) {
|
|
232
|
+
if (mode) {
|
|
233
|
+
clone = clone.getRule();
|
|
234
|
+
nst && $set(origin, key, {});
|
|
235
|
+
} else {
|
|
236
|
+
$set(origin, key, clone._clone());
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
nst && $set(origin, key, {});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
origin[key] = deepExtend(origin[key], clone, mode);
|
|
244
|
+
} else {
|
|
245
|
+
$set(origin, key, clone);
|
|
246
|
+
|
|
247
|
+
if (!is.Undef(clone)) {
|
|
248
|
+
if (!is.Undef(clone.__json)) {
|
|
249
|
+
origin[key].__json = clone.__json;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!is.Undef(clone.__origin)) {
|
|
253
|
+
origin[key].__origin = clone.__origin;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
|
|
261
|
+
return !v || !v.__ctrl;
|
|
262
|
+
}) : origin;
|
|
263
|
+
}
|
|
264
|
+
function deepCopy(value) {
|
|
265
|
+
return deepExtend({}, {
|
|
266
|
+
value: value
|
|
267
|
+
}).value;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
var _extends = Object.assign || function (a) {
|
|
271
|
+
for (var b, c = 1; c < arguments.length; c++) {
|
|
272
|
+
for (var d in b = arguments[c], b) {
|
|
273
|
+
Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return a;
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
function extend() {
|
|
281
|
+
return _extends.apply(this, arguments);
|
|
282
|
+
}
|
|
283
|
+
|
|
134
284
|
function _isSlot(s) {
|
|
135
285
|
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
|
|
136
286
|
}
|
|
@@ -161,6 +311,7 @@ var Group = defineComponent({
|
|
|
161
311
|
return [];
|
|
162
312
|
}
|
|
163
313
|
},
|
|
314
|
+
defaultValue: Object,
|
|
164
315
|
disabled: {
|
|
165
316
|
type: Boolean,
|
|
166
317
|
"default": false
|
|
@@ -297,6 +448,13 @@ var Group = defineComponent({
|
|
|
297
448
|
submitBtn: false,
|
|
298
449
|
resetBtn: false
|
|
299
450
|
};
|
|
451
|
+
|
|
452
|
+
if (this.defaultValue) {
|
|
453
|
+
if (!options.formData) options.formData = {};
|
|
454
|
+
var defVal = deepCopy(this.defaultValue);
|
|
455
|
+
extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
|
|
456
|
+
}
|
|
457
|
+
|
|
300
458
|
this.cacheRule[++this.len] = {
|
|
301
459
|
rule: rule,
|
|
302
460
|
options: options
|
|
@@ -313,6 +471,7 @@ var Group = defineComponent({
|
|
|
313
471
|
|
|
314
472
|
this.cacheRule[key].$f = $f;
|
|
315
473
|
this.subForm();
|
|
474
|
+
this.formData(key, $f.formData());
|
|
316
475
|
nextTick(function () {
|
|
317
476
|
if (_this4.syncDisabled) {
|
|
318
477
|
$f.disabled(_this4.disabled);
|
|
@@ -360,13 +519,13 @@ var Group = defineComponent({
|
|
|
360
519
|
this.input(this.modelValue);
|
|
361
520
|
},
|
|
362
521
|
addIcon: function addIcon(key) {
|
|
363
|
-
return createVNode(resolveComponent("
|
|
522
|
+
return createVNode(resolveComponent("ElIcon"), {
|
|
364
523
|
"key": "a".concat(key),
|
|
365
524
|
"style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer', ";"),
|
|
366
525
|
"onClick": this.add
|
|
367
526
|
}, {
|
|
368
527
|
"default": function _default() {
|
|
369
|
-
return [createVNode(
|
|
528
|
+
return [createVNode(script$1, null, null)];
|
|
370
529
|
}
|
|
371
530
|
});
|
|
372
531
|
},
|
|
@@ -382,7 +541,7 @@ var Group = defineComponent({
|
|
|
382
541
|
}
|
|
383
542
|
}, {
|
|
384
543
|
"default": function _default() {
|
|
385
|
-
return [createVNode(
|
|
544
|
+
return [createVNode(script, null, null)];
|
|
386
545
|
}
|
|
387
546
|
});
|
|
388
547
|
},
|
|
@@ -439,12 +598,15 @@ var Group = defineComponent({
|
|
|
439
598
|
return keys.length === 0 ? this.$slots["default"] ? this.$slots["default"]({
|
|
440
599
|
vm: this,
|
|
441
600
|
add: this.add
|
|
442
|
-
}) : createVNode("
|
|
601
|
+
}) : createVNode(resolveComponent("ElIcon"), {
|
|
443
602
|
"key": 1,
|
|
444
|
-
"class": "el-icon-circle-plus-outline",
|
|
445
603
|
"style": "font-size:".concat(this.fontSize, "px;vertical-align:middle;color:").concat(this.disabled ? '#c9cdd4;cursor: not-allowed' : '#606266;cursor:pointer', ";"),
|
|
446
604
|
"onClick": this.add
|
|
447
|
-
},
|
|
605
|
+
}, {
|
|
606
|
+
"default": function _default() {
|
|
607
|
+
return [createVNode(script$1, null, null)];
|
|
608
|
+
}
|
|
609
|
+
}) : createVNode("div", {
|
|
448
610
|
"key": 2
|
|
449
611
|
}, [keys.map(function (key, index) {
|
|
450
612
|
var _slot;
|
package/dist/index.esm.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.3
|
|
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{
|
|
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 u,isVNode as a}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:"IconCirclePlus"},b={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},v=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];y.render=function(n,r,o,i,l,u){return e(),t("svg",b,v)};var g={name:"IconRemove"},O={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},j=[n("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),n("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];function R(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&&R(e,o,[]);else if(i._clone&&void 0!==n){if(!n){R(e,o,i._clone());continue}i=i.getRule(),l&&R(e,o,{})}else l&&R(e,o,{});e[o]=V(e[o],i,n)}else R(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 w(e){return V({},{value:e}).value}g.render=function(n,r,o,i,l,u){return e(),t("svg",O,j)};var x=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&R(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 u=0;u<o;u++)this.removeRule(n[r-u-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=w(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(u("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}})},delIcon:function(e,t){var n=this;return l(u("ElIcon"),{key:"d".concat(t),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return n.del(e,t)}},{default:function(){return[l(g,null,null)]}})},makeIcon:function(e,t,n){var r=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return r.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,r){this.$emit.apply(this,[e].concat(h(t),[this.cacheRule[r].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,t=Object.keys(this.cacheRule),n=this.button,r=this.form;return 0===t.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):l(u("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[l(y,null,null)]}}):l("div",{key:2},[t.map((function(o,i){var c,s=e.cacheRule[o],f=s.rule,h=s.options;return l(u("ElRow"),{align:"middle",type:"flex",key:o,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[l(u("ElCol"),{span:n?20:24},{default:function(){return[l(u("ElFormItem"),null,{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(u("ElCol"),{span:2,pull:1,push:1},(s=c=e.makeIcon(t.length,i,o),"function"==typeof s||"[object Object]"===Object.prototype.toString.call(s)&&!a(s)?c:{default:function(){return[c]}})):null];var s}})}))])}});export{A as default};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.3
|
|
3
3
|
* (c) 2018-2022 xaboy
|
|
4
4
|
* Github https://github.com/xaboy/form-create with group
|
|
5
5
|
* Released under the MIT License.
|
|
@@ -124,9 +124,28 @@
|
|
|
124
124
|
},
|
|
125
125
|
trueArray: function trueArray(data) {
|
|
126
126
|
return Array.isArray(data) && data.length > 0;
|
|
127
|
+
},
|
|
128
|
+
Function: function Function(v) {
|
|
129
|
+
var type = this.getType(v);
|
|
130
|
+
return type === 'Function' || type === 'AsyncFunction';
|
|
131
|
+
},
|
|
132
|
+
getType: function getType(v) {
|
|
133
|
+
var str = Object.prototype.toString.call(v);
|
|
134
|
+
return /^\[object (.*)\]$/.exec(str)[1];
|
|
135
|
+
},
|
|
136
|
+
empty: function empty(value) {
|
|
137
|
+
if (value === undefined || value === null) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (Array.isArray(value) && Array.isArray(value) && !value.length) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return typeof value === 'string' && !value;
|
|
127
146
|
}
|
|
128
147
|
};
|
|
129
|
-
['Date', 'Object', '
|
|
148
|
+
['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) {
|
|
130
149
|
is[t] = function (arg) {
|
|
131
150
|
return is.type(arg, t);
|
|
132
151
|
};
|
|
@@ -135,6 +154,137 @@
|
|
|
135
154
|
return {}.hasOwnProperty.call(rule, k);
|
|
136
155
|
}
|
|
137
156
|
|
|
157
|
+
var script$1 = {
|
|
158
|
+
name: 'IconCirclePlus'
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
var _hoisted_1$1 = {
|
|
162
|
+
"class": "icon",
|
|
163
|
+
viewBox: "0 0 1024 1024",
|
|
164
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
var _hoisted_2$1 = /*#__PURE__*/vue.createElementVNode("path", {
|
|
168
|
+
fill: "currentColor",
|
|
169
|
+
d: "M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"
|
|
170
|
+
}, null, -1);
|
|
171
|
+
|
|
172
|
+
var _hoisted_3$1 = /*#__PURE__*/vue.createElementVNode("path", {
|
|
173
|
+
fill: "currentColor",
|
|
174
|
+
d: "M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"
|
|
175
|
+
}, null, -1);
|
|
176
|
+
|
|
177
|
+
var _hoisted_4$1 = /*#__PURE__*/vue.createElementVNode("path", {
|
|
178
|
+
fill: "currentColor",
|
|
179
|
+
d: "M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"
|
|
180
|
+
}, null, -1);
|
|
181
|
+
|
|
182
|
+
var _hoisted_5 = [_hoisted_2$1, _hoisted_3$1, _hoisted_4$1];
|
|
183
|
+
function render$1(_ctx, _cache, $props, $setup, $data, $options) {
|
|
184
|
+
return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$1, _hoisted_5);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
script$1.render = render$1;
|
|
188
|
+
|
|
189
|
+
var script = {
|
|
190
|
+
name: 'IconRemove'
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
var _hoisted_1 = {
|
|
194
|
+
"class": "icon",
|
|
195
|
+
viewBox: "0 0 1024 1024",
|
|
196
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
var _hoisted_2 = /*#__PURE__*/vue.createElementVNode("path", {
|
|
200
|
+
fill: "currentColor",
|
|
201
|
+
d: "M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"
|
|
202
|
+
}, null, -1);
|
|
203
|
+
|
|
204
|
+
var _hoisted_3 = /*#__PURE__*/vue.createElementVNode("path", {
|
|
205
|
+
fill: "currentColor",
|
|
206
|
+
d: "M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"
|
|
207
|
+
}, null, -1);
|
|
208
|
+
|
|
209
|
+
var _hoisted_4 = [_hoisted_2, _hoisted_3];
|
|
210
|
+
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
211
|
+
return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1, _hoisted_4);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
script.render = render;
|
|
215
|
+
|
|
216
|
+
function $set(target, field, value) {
|
|
217
|
+
target[field] = value;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function deepExtend(origin) {
|
|
221
|
+
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
222
|
+
var mode = arguments.length > 2 ? arguments[2] : undefined;
|
|
223
|
+
var isArr = false;
|
|
224
|
+
|
|
225
|
+
for (var key in target) {
|
|
226
|
+
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
|
227
|
+
var clone = target[key];
|
|
228
|
+
|
|
229
|
+
if ((isArr = Array.isArray(clone)) || is.Object(clone)) {
|
|
230
|
+
var nst = origin[key] === undefined;
|
|
231
|
+
|
|
232
|
+
if (isArr) {
|
|
233
|
+
isArr = false;
|
|
234
|
+
nst && $set(origin, key, []);
|
|
235
|
+
} else if (clone._clone && mode !== undefined) {
|
|
236
|
+
if (mode) {
|
|
237
|
+
clone = clone.getRule();
|
|
238
|
+
nst && $set(origin, key, {});
|
|
239
|
+
} else {
|
|
240
|
+
$set(origin, key, clone._clone());
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
nst && $set(origin, key, {});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
origin[key] = deepExtend(origin[key], clone, mode);
|
|
248
|
+
} else {
|
|
249
|
+
$set(origin, key, clone);
|
|
250
|
+
|
|
251
|
+
if (!is.Undef(clone)) {
|
|
252
|
+
if (!is.Undef(clone.__json)) {
|
|
253
|
+
origin[key].__json = clone.__json;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!is.Undef(clone.__origin)) {
|
|
257
|
+
origin[key].__origin = clone.__origin;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) {
|
|
265
|
+
return !v || !v.__ctrl;
|
|
266
|
+
}) : origin;
|
|
267
|
+
}
|
|
268
|
+
function deepCopy(value) {
|
|
269
|
+
return deepExtend({}, {
|
|
270
|
+
value: value
|
|
271
|
+
}).value;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var _extends = Object.assign || function (a) {
|
|
275
|
+
for (var b, c = 1; c < arguments.length; c++) {
|
|
276
|
+
for (var d in b = arguments[c], b) {
|
|
277
|
+
Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return a;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
function extend() {
|
|
285
|
+
return _extends.apply(this, arguments);
|
|
286
|
+
}
|
|
287
|
+
|
|
138
288
|
function _isSlot(s) {
|
|
139
289
|
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
|
|
140
290
|
}
|
|
@@ -165,6 +315,7 @@
|
|
|
165
315
|
return [];
|
|
166
316
|
}
|
|
167
317
|
},
|
|
318
|
+
defaultValue: Object,
|
|
168
319
|
disabled: {
|
|
169
320
|
type: Boolean,
|
|
170
321
|
"default": false
|
|
@@ -301,6 +452,13 @@
|
|
|
301
452
|
submitBtn: false,
|
|
302
453
|
resetBtn: false
|
|
303
454
|
};
|
|
455
|
+
|
|
456
|
+
if (this.defaultValue) {
|
|
457
|
+
if (!options.formData) options.formData = {};
|
|
458
|
+
var defVal = deepCopy(this.defaultValue);
|
|
459
|
+
extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal);
|
|
460
|
+
}
|
|
461
|
+
|
|
304
462
|
this.cacheRule[++this.len] = {
|
|
305
463
|
rule: rule,
|
|
306
464
|
options: options
|
|
@@ -317,6 +475,7 @@
|
|
|
317
475
|
|
|
318
476
|
this.cacheRule[key].$f = $f;
|
|
319
477
|
this.subForm();
|
|
478
|
+
this.formData(key, $f.formData());
|
|
320
479
|
vue.nextTick(function () {
|
|
321
480
|
if (_this4.syncDisabled) {
|
|
322
481
|
$f.disabled(_this4.disabled);
|
|
@@ -364,13 +523,13 @@
|
|
|
364
523
|
this.input(this.modelValue);
|
|
365
524
|
},
|
|
366
525
|
addIcon: function addIcon(key) {
|
|
367
|
-
return vue.createVNode(vue.resolveComponent("
|
|
526
|
+
return vue.createVNode(vue.resolveComponent("ElIcon"), {
|
|
368
527
|
"key": "a".concat(key),
|
|
369
528
|
"style": "font-size:".concat(this.fontSize, "px;cursor:").concat(this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer', ";"),
|
|
370
529
|
"onClick": this.add
|
|
371
530
|
}, {
|
|
372
531
|
"default": function _default() {
|
|
373
|
-
return [vue.createVNode(
|
|
532
|
+
return [vue.createVNode(script$1, null, null)];
|
|
374
533
|
}
|
|
375
534
|
});
|
|
376
535
|
},
|
|
@@ -386,7 +545,7 @@
|
|
|
386
545
|
}
|
|
387
546
|
}, {
|
|
388
547
|
"default": function _default() {
|
|
389
|
-
return [vue.createVNode(
|
|
548
|
+
return [vue.createVNode(script, null, null)];
|
|
390
549
|
}
|
|
391
550
|
});
|
|
392
551
|
},
|
|
@@ -443,12 +602,15 @@
|
|
|
443
602
|
return keys.length === 0 ? this.$slots["default"] ? this.$slots["default"]({
|
|
444
603
|
vm: this,
|
|
445
604
|
add: this.add
|
|
446
|
-
}) : vue.createVNode("
|
|
605
|
+
}) : vue.createVNode(vue.resolveComponent("ElIcon"), {
|
|
447
606
|
"key": 1,
|
|
448
|
-
"class": "el-icon-circle-plus-outline",
|
|
449
607
|
"style": "font-size:".concat(this.fontSize, "px;vertical-align:middle;color:").concat(this.disabled ? '#c9cdd4;cursor: not-allowed' : '#606266;cursor:pointer', ";"),
|
|
450
608
|
"onClick": this.add
|
|
451
|
-
},
|
|
609
|
+
}, {
|
|
610
|
+
"default": function _default() {
|
|
611
|
+
return [vue.createVNode(script$1, null, null)];
|
|
612
|
+
}
|
|
613
|
+
}) : vue.createVNode("div", {
|
|
452
614
|
"key": 2
|
|
453
615
|
}, [keys.map(function (key, index) {
|
|
454
616
|
var _slot;
|
package/dist/index.min.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @form-create/component-elm-group v3.1.
|
|
2
|
+
* @form-create/component-elm-group v3.1.3
|
|
3
3
|
* (c) 2018-2022 xaboy
|
|
4
4
|
* Github https://github.com/xaboy/form-create with group
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*/
|
|
7
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FcGroup={},e.Vue)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){i(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e){return function(e){if(Array.isArray(e))return u(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var c={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===r(e)&&null!==e&&1===e.nodeType&&!c.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0}};["Date","Object","Function","String","Boolean","Array","Number"].forEach((function(e){c[e]=function(t){return c.type(t,e)}}));var a=t.defineComponent({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),o=n.length,r=o-e.length;if(r<0){for(var i=r;i<0;i++)this.addRule(e.length+i);for(var l=0;l<o;l++)this.setValue(n[l],e[l])}else{if(r>0){for(var u=0;u<r;u++)this.removeRule(n[o-u-1]);this.subForm()}e.forEach((function(o,r){t.setValue(n[r],e[r])}))}},deep:!0,flush:"post"}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,i=Object.keys(r);if(i.filter((function(e){return r[e].$f})).length===i.length){var l=i.map((function(r){var i=e===r?t:o({},n.cacheRule[r].$f.form),l=n.field?i[n.field]||null:i;return n.cache(r,l),l}));this.input(l)}},setValue:function(e,t){var n=this.field;n&&(t=i({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,n){var r=this,i=this.formCreateInject.form.copyRules(this.rule||[]),l=this.options?o({},this.options):{submitBtn:!1,resetBtn:!1};this.cacheRule[++this.len]={rule:i,options:l},n&&t.nextTick((function(){return r.$emit("add",i,Object.keys(r.cacheRule).length-1)}))},add$f:function(e,n,o){var r=this;this.cacheRule[n].$f=o,this.subForm(),t.nextTick((function(){r.syncDisabled&&o.disabled(r.disabled),r.$emit("itemMounted",o,Object.keys(r.cacheRule).indexOf(n))}))},subForm:function(){var e=this;this.formCreateInject.subForm(Object.keys(this.cacheRule).map((function(t){return e.cacheRule[t].$f})))},removeRule:function(e,n){var o=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return o.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.subForm(),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return t.createVNode(t.resolveComponent("el-icon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(t.resolveComponent("circle-plus"),null,null)]}})},delIcon:function(e,n){var o=this;return t.createVNode(t.resolveComponent("ElIcon"),{key:"d".concat(n),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return o.del(e,n)}},{default:function(){return[t.createVNode(t.resolveComponent("remove"),null,null)]}})},makeIcon:function(e,t,n){var o=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return o.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,o){this.$emit.apply(this,[e].concat(l(t),[this.cacheRule[o].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,n=Object.keys(this.cacheRule),o=this.button,r=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode("i",{key:1,class:"el-icon-circle-plus-outline",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,u){var c,a=e.cacheRule[l],s=a.rule,f=a.options;return t.createVNode(t.resolveComponent("ElRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("ElCol"),{span:o?20:24},{default:function(){return[t.createVNode(t.resolveComponent("ElFormItem"),null,{default:function(){return[t.createVNode(r,{key:l,"onUpdate:modelValue":function(t){return e.formData(l,t)},modelValue:e.field?i({},e.field,e._value(e.modelValue[u])):e.modelValue[u],"onEmit-event":function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return e.emitEvent(t,o,u,l)},"onUpdate:api":function(t){return e.add$f(u,l,t)},rule:s,option:f,extendOption:!0},null)]}})]}}),o?t.createVNode(t.resolveComponent("ElCol"),{span:2,pull:1,push:1},(a=c=e.makeIcon(n.length,u,l),"function"==typeof a||"[object Object]"===Object.prototype.toString.call(a)&&!t.isVNode(a)?c:{default:function(){return[c]}})):null];var a}})}))])}});e.default=a,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
7
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FcGroup={},e.Vue)}(this,(function(e,t){"use strict";function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function o(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?n(Object(o),!0).forEach((function(t){i(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n<t;n++)o[n]=e[n];return o}var u={type:function(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"},Undef:function(e){return null==e},Element:function(e){return"object"===r(e)&&null!==e&&1===e.nodeType&&!u.Object(e)},trueArray:function(e){return Array.isArray(e)&&e.length>0},Function:function(e){var t=this.getType(e);return"Function"===t||"AsyncFunction"===t},getType:function(e){var t=Object.prototype.toString.call(e);return/^\[object (.*)\]$/.exec(t)[1]},empty:function(e){return null==e||(!(!Array.isArray(e)||!Array.isArray(e)||e.length)||"string"==typeof e&&!e)}};["Date","Object","String","Boolean","Array","Number"].forEach((function(e){u[e]=function(t){return u.type(t,e)}}));var c={name:"IconCirclePlus"},s={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},f=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];c.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",s,f)};var d={name:"IconRemove"},h={class:"icon",viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"},m=[t.createElementVNode("path",{fill:"currentColor",d:"M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"},null,-1),t.createElementVNode("path",{fill:"currentColor",d:"M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"},null,-1)];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,o=!1;for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];if((o=Array.isArray(i))||u.Object(i)){var l=void 0===e[r];if(o)o=!1,l&&p(e,r,[]);else if(i._clone&&void 0!==n){if(!n){p(e,r,i._clone());continue}i=i.getRule(),l&&p(e,r,{})}else l&&p(e,r,{});e[r]=y(e[r],i,n)}else p(e,r,i),u.Undef(i)||(u.Undef(i.__json)||(e[r].__json=i.__json),u.Undef(i.__origin)||(e[r].__origin=i.__origin))}return void 0!==n&&Array.isArray(e)?e.filter((function(e){return!e||!e.__ctrl})):e}function b(e){return y({},{value:e}).value}d.render=function(e,n,o,r,i,l){return t.openBlock(),t.createElementBlock("svg",h,m)};var v=Object.assign||function(e){for(var t,n=1;n<arguments.length;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&p(e,o,t[o]);return e};var g=t.defineComponent({name:"fcGroup",props:{field:String,rule:Array,expand:Number,options:Object,button:{type:Boolean,default:!0},max:{type:Number,default:0},min:{type:Number,default:0},modelValue:{type:Array,default:function(){return[]}},defaultValue:Object,disabled:{type:Boolean,default:!1},syncDisabled:{type:Boolean,default:!0},fontSize:{type:Number,default:28},onBeforeRemove:{type:Function,default:function(){}},onBeforeAdd:{type:Function,default:function(){}},formCreateInject:Object},data:function(){return{len:0,cacheRule:{},cacheValue:{},form:t.markRaw(this.formCreateInject.form.$form())}},emits:["update:modelValue","change","itemMounted","remove"],watch:{disabled:function(e){if(this.syncDisabled){var t=this.cacheRule;Object.keys(t).forEach((function(n){t[n].$f.disabled(e)}))}},expand:function(e){var t=e-this.modelValue.length;t>0&&this.expandRule(t)},modelValue:{handler:function(e){var t=this;e=e||[];var n=Object.keys(this.cacheRule),o=n.length,r=o-e.length;if(r<0){for(var i=r;i<0;i++)this.addRule(e.length+i);for(var l=0;l<o;l++)this.setValue(n[l],e[l])}else{if(r>0){for(var a=0;a<r;a++)this.removeRule(n[o-a-1]);this.subForm()}e.forEach((function(o,r){t.setValue(n[r],e[r])}))}},deep:!0,flush:"post"}},methods:{_value:function(e){return e&&(t=e,n=this.field,{}.hasOwnProperty.call(t,n))?e[this.field]:e;var t,n},cache:function(e,t){this.cacheValue[e]=JSON.stringify(t)},input:function(e){this.$emit("update:modelValue",e),this.$emit("change",e)},formData:function(e,t){var n=this,r=this.cacheRule,i=Object.keys(r);if(i.filter((function(e){return r[e].$f})).length===i.length){var l=i.map((function(r){var i=e===r?t:o({},n.cacheRule[r].$f.form),l=n.field?i[n.field]||null:i;return n.cache(r,l),l}));this.input(l)}},setValue:function(e,t){var n=this.field;n&&(t=i({},n,this._value(t))),this.cacheValue[e]!==JSON.stringify(n?t[n]:t)&&this.cache(e,t)},addRule:function(e,n){var r=this,l=this.formCreateInject.form.copyRules(this.rule||[]),a=this.options?o({},this.options):{submitBtn:!1,resetBtn:!1};if(this.defaultValue){a.formData||(a.formData={});var u=b(this.defaultValue);!function(){v.apply(this,arguments)}(a.formData,this.field?i({},this.field,u):u)}this.cacheRule[++this.len]={rule:l,options:a},n&&t.nextTick((function(){return r.$emit("add",l,Object.keys(r.cacheRule).length-1)}))},add$f:function(e,n,o){var r=this;this.cacheRule[n].$f=o,this.subForm(),this.formData(n,o.formData()),t.nextTick((function(){r.syncDisabled&&o.disabled(r.disabled),r.$emit("itemMounted",o,Object.keys(r.cacheRule).indexOf(n))}))},subForm:function(){var e=this;this.formCreateInject.subForm(Object.keys(this.cacheRule).map((function(t){return e.cacheRule[t].$f})))},removeRule:function(e,n){var o=this,r=Object.keys(this.cacheRule).indexOf(e);delete this.cacheRule[e],delete this.cacheValue[e],n&&t.nextTick((function(){return o.$emit("remove",r)}))},add:function(){this.disabled||!1===this.onBeforeAdd(this.modelValue)||(this.modelValue.push(this.field?null:{}),this.$emit("update:modelValue",this.modelValue))},del:function(e,t){this.disabled||!1===this.onBeforeRemove(this.modelValue,e)||(this.removeRule(t,!0),this.subForm(),this.modelValue.splice(e,1),this.input(this.modelValue))},addIcon:function(e){return t.createVNode(t.resolveComponent("ElIcon"),{key:"a".concat(e),style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}})},delIcon:function(e,n){var o=this;return t.createVNode(t.resolveComponent("ElIcon"),{key:"d".concat(n),class:"el-icon-remove-outline",style:"font-size:".concat(this.fontSize,"px;cursor:").concat(this.disabled?"not-allowed;color:#c9cdd4":"pointer;color:#606266",";"),onClick:function(){return o.del(e,n)}},{default:function(){return[t.createVNode(d,null,null)]}})},makeIcon:function(e,t,n){var o=this;return this.$slots.button?this.$slots.button({total:e,index:t,vm:this,key:n,del:function(){return o.del(t,n)},add:this.add}):0===t?[0!==this.max&&e>=this.max?null:this.addIcon(n),0===this.min||e>this.min?this.delIcon(t,n):null]:t>=this.min?this.delIcon(t,n):void 0},emitEvent:function(e,t,n,o){this.$emit.apply(this,[e].concat(l(t),[this.cacheRule[o].$f,n]))},expandRule:function(e){for(var t=0;t<e;t++)this.modelValue.push(this.field?null:{})}},created:function(){for(var e=(this.expand||0)-this.modelValue.length,t=0;t<this.modelValue.length;t++)this.addRule(t);e>0&&this.expandRule(e)},render:function(){var e=this,n=Object.keys(this.cacheRule),o=this.button,r=this.form;return 0===n.length?this.$slots.default?this.$slots.default({vm:this,add:this.add}):t.createVNode(t.resolveComponent("ElIcon"),{key:1,style:"font-size:".concat(this.fontSize,"px;vertical-align:middle;color:").concat(this.disabled?"#c9cdd4;cursor: not-allowed":"#606266;cursor:pointer",";"),onClick:this.add},{default:function(){return[t.createVNode(c,null,null)]}}):t.createVNode("div",{key:2},[n.map((function(l,a){var u,c=e.cacheRule[l],s=c.rule,f=c.options;return t.createVNode(t.resolveComponent("ElRow"),{align:"middle",type:"flex",key:l,style:"border-bottom:1px dashed #DCDFE6;margin-bottom:10px;"},{default:function(){return[t.createVNode(t.resolveComponent("ElCol"),{span:o?20:24},{default:function(){return[t.createVNode(t.resolveComponent("ElFormItem"),null,{default:function(){return[t.createVNode(r,{key:l,"onUpdate:modelValue":function(t){return e.formData(l,t)},modelValue:e.field?i({},e.field,e._value(e.modelValue[a])):e.modelValue[a],"onEmit-event":function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];return e.emitEvent(t,o,a,l)},"onUpdate:api":function(t){return e.add$f(a,l,t)},rule:s,option:f,extendOption:!0},null)]}})]}}),o?t.createVNode(t.resolveComponent("ElCol"),{span:2,pull:1,push:1},(c=u=e.makeIcon(n.length,a,l),"function"==typeof c||"[object Object]"===Object.prototype.toString.call(c)&&!t.isVNode(c)?u:{default:function(){return[u]}})):null];var c}})}))])}});e.default=g,Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@form-create/component-elm-group",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "@form-create/element-ui 内置组件",
|
|
5
5
|
"main": "./dist/index.min.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"author": "xaboy",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@form-create/utils": "^3.1.
|
|
33
|
+
"@form-create/utils": "^3.1.3"
|
|
34
34
|
},
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/xaboy/form-create/issues"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"esm"
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7188700dc7590edc798b756d6d4d353b9b004512"
|
|
51
51
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<path fill="currentColor" d="M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"></path>
|
|
4
|
+
<path fill="currentColor" d="M480 672V352a32 32 0 1164 0v320a32 32 0 01-64 0z"></path>
|
|
5
|
+
<path fill="currentColor"
|
|
6
|
+
d="M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"></path>
|
|
7
|
+
</svg>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script>
|
|
11
|
+
export default {
|
|
12
|
+
name: 'IconCirclePlus'
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<svg class="icon" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<path fill="currentColor" d="M352 480h320a32 32 0 110 64H352a32 32 0 010-64z"></path>
|
|
4
|
+
<path fill="currentColor"
|
|
5
|
+
d="M512 896a384 384 0 100-768 384 384 0 000 768zm0 64a448 448 0 110-896 448 448 0 010 896z"></path>
|
|
6
|
+
</svg>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
export default {
|
|
11
|
+
name: 'IconRemove'
|
|
12
|
+
}
|
|
13
|
+
</script>
|
package/src/component.jsx
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import {hasProperty} from '@form-create/utils/lib/type';
|
|
2
2
|
import {defineComponent, markRaw, nextTick} from 'vue';
|
|
3
|
+
import IconCirclePlus from './IconCirclePlus.vue';
|
|
4
|
+
import IconRemove from './IconRemove.vue';
|
|
5
|
+
import {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
6
|
+
import extend from '@form-create/utils/lib/extend';
|
|
3
7
|
|
|
4
8
|
const NAME = 'fcGroup';
|
|
5
9
|
|
|
@@ -26,6 +30,7 @@ export default defineComponent({
|
|
|
26
30
|
type: Array,
|
|
27
31
|
default: () => []
|
|
28
32
|
},
|
|
33
|
+
defaultValue: Object,
|
|
29
34
|
disabled: {
|
|
30
35
|
type: Boolean,
|
|
31
36
|
default: false
|
|
@@ -142,6 +147,11 @@ export default defineComponent({
|
|
|
142
147
|
submitBtn: false,
|
|
143
148
|
resetBtn: false,
|
|
144
149
|
};
|
|
150
|
+
if (this.defaultValue) {
|
|
151
|
+
if (!options.formData) options.formData = {};
|
|
152
|
+
const defVal = deepCopy(this.defaultValue);
|
|
153
|
+
extend(options.formData, this.field ? {[this.field]: defVal} : defVal);
|
|
154
|
+
}
|
|
145
155
|
this.cacheRule[++this.len] = {rule, options};
|
|
146
156
|
if (emit) {
|
|
147
157
|
nextTick(() => this.$emit('add', rule, Object.keys(this.cacheRule).length - 1));
|
|
@@ -150,6 +160,7 @@ export default defineComponent({
|
|
|
150
160
|
add$f(i, key, $f) {
|
|
151
161
|
this.cacheRule[key].$f = $f;
|
|
152
162
|
this.subForm();
|
|
163
|
+
this.formData(key, $f.formData());
|
|
153
164
|
nextTick(() => {
|
|
154
165
|
if (this.syncDisabled) {
|
|
155
166
|
$f.disabled(this.disabled);
|
|
@@ -185,17 +196,17 @@ export default defineComponent({
|
|
|
185
196
|
this.input(this.modelValue);
|
|
186
197
|
},
|
|
187
198
|
addIcon(key) {
|
|
188
|
-
return <
|
|
199
|
+
return <ElIcon key={`a${key}`}
|
|
189
200
|
style={`font-size:${this.fontSize}px;cursor:${this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer'};`}
|
|
190
201
|
onClick={this.add}>
|
|
191
|
-
<
|
|
192
|
-
</
|
|
202
|
+
<IconCirclePlus/>
|
|
203
|
+
</ElIcon>
|
|
193
204
|
},
|
|
194
205
|
delIcon(index, key) {
|
|
195
206
|
return <ElIcon key={`d${key}`} class="el-icon-remove-outline"
|
|
196
207
|
style={`font-size:${this.fontSize}px;cursor:${this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266'};`}
|
|
197
208
|
onClick={() => this.del(index, key)}>
|
|
198
|
-
<
|
|
209
|
+
<IconRemove/>
|
|
199
210
|
</ElIcon>
|
|
200
211
|
},
|
|
201
212
|
makeIcon(total, index, key) {
|
|
@@ -242,9 +253,11 @@ export default defineComponent({
|
|
|
242
253
|
(this.$slots.default ? (this.$slots.default({
|
|
243
254
|
vm: this,
|
|
244
255
|
add: this.add
|
|
245
|
-
})) : <
|
|
256
|
+
})) : <ElIcon key={1}
|
|
246
257
|
style={`font-size:${this.fontSize}px;vertical-align:middle;color:${this.disabled ? '#c9cdd4;cursor: not-allowed' : '#606266;cursor:pointer'};`}
|
|
247
|
-
onClick={this.add}
|
|
258
|
+
onClick={this.add}>
|
|
259
|
+
<IconCirclePlus/>
|
|
260
|
+
</ElIcon>) :
|
|
248
261
|
<div key={2}>{keys.map((key, index) => {
|
|
249
262
|
const {rule, options} = this.cacheRule[key];
|
|
250
263
|
return <ElRow align="middle" type="flex" key={key}
|