@form-create/component-elm-group 2.5.17 → 2.5.22
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.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/component.jsx +37 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@form-create/component-elm-group",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.22",
|
|
4
4
|
"description": "@form-create/element-ui 内置组件",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"author": "xaboy",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@form-create/utils": "^2.5.
|
|
33
|
+
"@form-create/utils": "^2.5.18"
|
|
34
34
|
},
|
|
35
35
|
"bugs": {
|
|
36
36
|
"url": "https://github.com/xaboy/form-create/issues"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "43cbd7f5342d014a4e6de877304ad613b1433e0b"
|
|
43
43
|
}
|
package/src/component.jsx
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {hasProperty} from '@form-create/utils/lib/type';
|
|
2
|
+
import deepExtend, {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
3
|
+
import extend from '@form-create/utils/lib/extend';
|
|
2
4
|
|
|
3
5
|
const NAME = 'fcGroup';
|
|
4
6
|
|
|
@@ -30,6 +32,7 @@ export default {
|
|
|
30
32
|
type: Array,
|
|
31
33
|
default: () => []
|
|
32
34
|
},
|
|
35
|
+
defaultValue: Object,
|
|
33
36
|
disabled: {
|
|
34
37
|
type: Boolean,
|
|
35
38
|
default: false
|
|
@@ -63,16 +66,39 @@ export default {
|
|
|
63
66
|
},
|
|
64
67
|
computed: {
|
|
65
68
|
formRule() {
|
|
66
|
-
if (this.rule) {
|
|
67
|
-
return Array.isArray(this.rule) ? this.rule : [this.rule];
|
|
68
|
-
}
|
|
69
69
|
if (this.rules) {
|
|
70
70
|
return this.rules;
|
|
71
71
|
}
|
|
72
|
+
if (this.rule) {
|
|
73
|
+
return Array.isArray(this.rule) ? this.rule : [this.rule];
|
|
74
|
+
}
|
|
72
75
|
return [];
|
|
73
76
|
}
|
|
74
77
|
},
|
|
75
78
|
watch: {
|
|
79
|
+
formRule: {
|
|
80
|
+
handler(n, o) {
|
|
81
|
+
Object.keys(this.cacheRule).forEach(v => {
|
|
82
|
+
const item = this.cacheRule[v];
|
|
83
|
+
if (item.$f) {
|
|
84
|
+
const val = item.$f.formData();
|
|
85
|
+
if (n === o) {
|
|
86
|
+
item.$f.deferSyncValue(() => {
|
|
87
|
+
deepExtend(item.rule, n);
|
|
88
|
+
item.$f.setValue(val);
|
|
89
|
+
}, true);
|
|
90
|
+
} else {
|
|
91
|
+
const val = item.$f.formData();
|
|
92
|
+
item.$f.once('reloading', () => {
|
|
93
|
+
item.$f.setValue(val);
|
|
94
|
+
})
|
|
95
|
+
item.rule = deepCopy(n);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
},
|
|
100
|
+
deep: true
|
|
101
|
+
},
|
|
76
102
|
disabled(n) {
|
|
77
103
|
if (this.syncDisabled) {
|
|
78
104
|
const lst = this.cacheRule;
|
|
@@ -102,7 +128,6 @@ export default {
|
|
|
102
128
|
for (let i = 0; i < len; i++) {
|
|
103
129
|
this.removeRule(keys[total - i - 1]);
|
|
104
130
|
}
|
|
105
|
-
this.subForm();
|
|
106
131
|
}
|
|
107
132
|
n.forEach((val, i) => {
|
|
108
133
|
this.setValue(keys[i], n[i]);
|
|
@@ -152,7 +177,11 @@ export default {
|
|
|
152
177
|
submitBtn: false,
|
|
153
178
|
resetBtn: false,
|
|
154
179
|
};
|
|
155
|
-
|
|
180
|
+
if (this.defaultValue) {
|
|
181
|
+
if (!options.formData) options.formData = {};
|
|
182
|
+
const defVal = deepCopy(this.defaultValue);
|
|
183
|
+
extend(options.formData, this.field ? {[this.field]: defVal} : defVal);
|
|
184
|
+
}
|
|
156
185
|
this.$set(this.cacheRule, ++this.len, {rule, options});
|
|
157
186
|
if (emit) {
|
|
158
187
|
this.$nextTick(() => this.$emit('add', rule, Object.keys(this.cacheRule).length - 1));
|
|
@@ -160,7 +189,7 @@ export default {
|
|
|
160
189
|
},
|
|
161
190
|
add$f(i, key, $f) {
|
|
162
191
|
this.cacheRule[key].$f = $f;
|
|
163
|
-
this.
|
|
192
|
+
this.formData(key, $f.formData());
|
|
164
193
|
this.$nextTick(() => {
|
|
165
194
|
if (this.syncDisabled) {
|
|
166
195
|
$f.disabled(this.disabled);
|
|
@@ -168,9 +197,6 @@ export default {
|
|
|
168
197
|
this.$emit('itemMounted', $f, Object.keys(this.cacheRule).indexOf(key));
|
|
169
198
|
});
|
|
170
199
|
},
|
|
171
|
-
subForm() {
|
|
172
|
-
this.formCreateInject.subForm(Object.keys(this.cacheRule).map(k => this.cacheRule[k].$f));
|
|
173
|
-
},
|
|
174
200
|
removeRule(key, emit) {
|
|
175
201
|
const index = Object.keys(this.cacheRule).indexOf(key);
|
|
176
202
|
this.$delete(this.cacheRule, key);
|
|
@@ -190,7 +216,6 @@ export default {
|
|
|
190
216
|
return;
|
|
191
217
|
}
|
|
192
218
|
this.removeRule(key, true);
|
|
193
|
-
this.subForm();
|
|
194
219
|
this.value.splice(index, 1);
|
|
195
220
|
this.input(this.value);
|
|
196
221
|
},
|
|
@@ -257,12 +282,13 @@ export default {
|
|
|
257
282
|
return <ElRow align="middle" type="flex" key={key}
|
|
258
283
|
style="border-bottom:1px dashed #DCDFE6;margin-bottom:10px;">
|
|
259
284
|
<ElCol span={button ? 20 : 24}><ElFormItem><Type
|
|
260
|
-
key={key}
|
|
285
|
+
key={key} inFor={true}
|
|
261
286
|
on={{
|
|
262
287
|
'update:value': (formData) => this.formData(key, formData),
|
|
263
288
|
'emit-event': (name, ...args) => this.emitEvent(name, args, index, key),
|
|
264
289
|
input: ($f) => this.add$f(index, key, $f)
|
|
265
290
|
}}
|
|
291
|
+
value={this.field ? {[this.field]: this._value(this.value[index])} : this.value[index]}
|
|
266
292
|
rule={rule}
|
|
267
293
|
option={options} extendOption={true}/></ElFormItem></ElCol>
|
|
268
294
|
{button ? <ElCol span={2} pull={1} push={1}>{this.makeIcon(keys.length, index, key)}</ElCol> : null}
|