@form-create/component-elm-group 2.5.31 → 2.5.32
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 +2 -2
- package/src/component.jsx +70 -36
- package/src/style.css +124 -0
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.32",
|
|
4
4
|
"description": "@form-create/element-ui 内置组件",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "8b4a977f33789d6866a98ecd2559858a4d5a20ec"
|
|
43
43
|
}
|
package/src/component.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {hasProperty} from '@form-create/utils/lib/type';
|
|
2
2
|
import deepExtend, {deepCopy} from '@form-create/utils/lib/deepextend';
|
|
3
3
|
import extend from '@form-create/utils/lib/extend';
|
|
4
|
+
import './style.css';
|
|
4
5
|
|
|
5
6
|
const NAME = 'fcGroup';
|
|
6
7
|
|
|
@@ -32,6 +33,10 @@ export default {
|
|
|
32
33
|
type: Array,
|
|
33
34
|
default: () => []
|
|
34
35
|
},
|
|
36
|
+
sortBtn: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: true
|
|
39
|
+
},
|
|
35
40
|
defaultValue: Object,
|
|
36
41
|
disabled: {
|
|
37
42
|
type: Boolean,
|
|
@@ -41,10 +46,6 @@ export default {
|
|
|
41
46
|
type: Boolean,
|
|
42
47
|
default: true
|
|
43
48
|
},
|
|
44
|
-
fontSize: {
|
|
45
|
-
type: Number,
|
|
46
|
-
default: 28
|
|
47
|
-
},
|
|
48
49
|
onBeforeRemove: {
|
|
49
50
|
type: Function,
|
|
50
51
|
default: () => {
|
|
@@ -55,12 +56,14 @@ export default {
|
|
|
55
56
|
default: () => {
|
|
56
57
|
}
|
|
57
58
|
},
|
|
59
|
+
parse: Function,
|
|
58
60
|
},
|
|
59
61
|
data() {
|
|
60
62
|
return {
|
|
61
63
|
len: 0,
|
|
62
64
|
cacheRule: {},
|
|
63
65
|
cacheValue: {},
|
|
66
|
+
sort: [],
|
|
64
67
|
type: undefined
|
|
65
68
|
}
|
|
66
69
|
},
|
|
@@ -76,6 +79,12 @@ export default {
|
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
81
|
watch: {
|
|
82
|
+
cacheRule: {
|
|
83
|
+
handler(n) {
|
|
84
|
+
this.sort = Object.keys(n);
|
|
85
|
+
},
|
|
86
|
+
immediate: true
|
|
87
|
+
},
|
|
79
88
|
formRule: {
|
|
80
89
|
handler(n, o) {
|
|
81
90
|
Object.keys(this.cacheRule).forEach(v => {
|
|
@@ -113,9 +122,9 @@ export default {
|
|
|
113
122
|
this.expandRule(d);
|
|
114
123
|
}
|
|
115
124
|
},
|
|
116
|
-
value(n) {
|
|
125
|
+
value(n, o) {
|
|
117
126
|
n = n || [];
|
|
118
|
-
let keys =
|
|
127
|
+
let keys = this.sort, total = keys.length, len = total - n.length;
|
|
119
128
|
if (len < 0) {
|
|
120
129
|
for (let i = len; i < 0; i++) {
|
|
121
130
|
this.addRule(n.length + i);
|
|
@@ -132,6 +141,9 @@ export default {
|
|
|
132
141
|
n.forEach((val, i) => {
|
|
133
142
|
this.setValue(keys[i], n[i]);
|
|
134
143
|
});
|
|
144
|
+
if (o.length && !n.length) {
|
|
145
|
+
this.input([]);
|
|
146
|
+
}
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
149
|
},
|
|
@@ -148,7 +160,7 @@ export default {
|
|
|
148
160
|
},
|
|
149
161
|
formData(key, formData) {
|
|
150
162
|
const cacheRule = this.cacheRule;
|
|
151
|
-
const keys =
|
|
163
|
+
const keys = this.sort;
|
|
152
164
|
if (keys.filter(k => cacheRule[k].$f).length !== keys.length) {
|
|
153
165
|
return;
|
|
154
166
|
}
|
|
@@ -182,6 +194,7 @@ export default {
|
|
|
182
194
|
const defVal = deepCopy(this.defaultValue);
|
|
183
195
|
extend(options.formData, this.field ? {[this.field]: defVal} : defVal);
|
|
184
196
|
}
|
|
197
|
+
this.parse && this.parse({rule, options, index: this.sort.length});
|
|
185
198
|
this.$set(this.cacheRule, ++this.len, {rule, options});
|
|
186
199
|
if (emit) {
|
|
187
200
|
this.$nextTick(() => this.$emit('add', rule, Object.keys(this.cacheRule).length - 1));
|
|
@@ -189,7 +202,6 @@ export default {
|
|
|
189
202
|
},
|
|
190
203
|
add$f(i, key, $f) {
|
|
191
204
|
this.cacheRule[key].$f = $f;
|
|
192
|
-
this.formData(key, $f.formData());
|
|
193
205
|
this.$nextTick(() => {
|
|
194
206
|
if (this.syncDisabled) {
|
|
195
207
|
$f.disabled(this.disabled);
|
|
@@ -216,18 +228,30 @@ export default {
|
|
|
216
228
|
return;
|
|
217
229
|
}
|
|
218
230
|
this.removeRule(key, true);
|
|
219
|
-
this.value
|
|
220
|
-
|
|
231
|
+
const value = [...this.value];
|
|
232
|
+
value.splice(index, 1);
|
|
233
|
+
this.input(value);
|
|
221
234
|
},
|
|
222
235
|
addIcon(key) {
|
|
223
|
-
return <
|
|
224
|
-
style={`font-size:${this.fontSize}px;cursor:${this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer'};`}
|
|
225
|
-
on-click={this.add}/>;
|
|
236
|
+
return <div class="_fc-group-btn _fc-group-plus-minus" on-click={this.add}></div>;
|
|
226
237
|
},
|
|
227
238
|
delIcon(index, key) {
|
|
228
|
-
return <
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
return <div class="_fc-group-btn _fc-group-plus-minus _fc-group-minus"
|
|
240
|
+
onClick={() => this.del(index, key)}></div>
|
|
241
|
+
},
|
|
242
|
+
sortUpIcon(index) {
|
|
243
|
+
return <div class="_fc-group-btn _fc-group-arrow _fc-group-up"
|
|
244
|
+
onClick={() => this.changeSort(index, -1)}></div>
|
|
245
|
+
},
|
|
246
|
+
sortDownIcon(index) {
|
|
247
|
+
return <div class="_fc-group-btn _fc-group-arrow _fc-group-down"
|
|
248
|
+
onClick={() => this.changeSort(index, 1)}></div>
|
|
249
|
+
},
|
|
250
|
+
changeSort(index, sort) {
|
|
251
|
+
const a = this.sort[index];
|
|
252
|
+
this.$set(this.sort, index, this.sort[index + sort]);
|
|
253
|
+
this.sort[index + sort] = a;
|
|
254
|
+
this.formData(0);
|
|
231
255
|
},
|
|
232
256
|
makeIcon(total, index, key) {
|
|
233
257
|
if (this.$scopedSlots.button) {
|
|
@@ -240,12 +264,20 @@ export default {
|
|
|
240
264
|
add: this.add
|
|
241
265
|
});
|
|
242
266
|
}
|
|
243
|
-
|
|
244
|
-
|
|
267
|
+
const btn = [];
|
|
268
|
+
if ((!this.max || total < this.max) && total === index + 1) {
|
|
269
|
+
btn.push(this.addIcon(key));
|
|
245
270
|
}
|
|
246
271
|
if (total > this.min) {
|
|
247
|
-
|
|
272
|
+
btn.push(this.delIcon(index, key));
|
|
273
|
+
}
|
|
274
|
+
if (this.sortBtn && index) {
|
|
275
|
+
btn.push(this.sortUpIcon(index));
|
|
276
|
+
}
|
|
277
|
+
if (this.sortBtn && index !== total - 1) {
|
|
278
|
+
btn.push(this.sortDownIcon(index));
|
|
248
279
|
}
|
|
280
|
+
return btn;
|
|
249
281
|
},
|
|
250
282
|
emitEvent(name, args, index, key) {
|
|
251
283
|
this.$emit(name, ...args, this.cacheRule[key].$f, index);
|
|
@@ -267,21 +299,21 @@ export default {
|
|
|
267
299
|
}
|
|
268
300
|
},
|
|
269
301
|
render() {
|
|
270
|
-
const keys =
|
|
302
|
+
const keys = this.sort;
|
|
271
303
|
const button = this.button;
|
|
272
304
|
const Type = this.type;
|
|
273
|
-
|
|
305
|
+
const disabled = this.disabled;
|
|
306
|
+
|
|
307
|
+
const children = keys.length === 0 ?
|
|
274
308
|
(this.$scopedSlots.default ? (this.$scopedSlots.default({
|
|
275
309
|
vm: this,
|
|
276
310
|
add: this.add
|
|
277
|
-
})) : <
|
|
278
|
-
|
|
279
|
-
on-click={this.add}/>) :
|
|
280
|
-
<div key={'con'}>{keys.map((key, index) => {
|
|
311
|
+
})) : <div key={'a_def'} class="_fc-group-plus-minus _fc-group-add"
|
|
312
|
+
on-click={this.add}/>) : keys.map((key, index) => {
|
|
281
313
|
const {rule, options} = this.cacheRule[key];
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
<
|
|
314
|
+
const btn = button && !disabled ? this.makeIcon(keys.length, index, key) : [];
|
|
315
|
+
return <div class="_fc-group-container" key={key}>
|
|
316
|
+
<Type
|
|
285
317
|
key={key}
|
|
286
318
|
on={{
|
|
287
319
|
'update:value': (formData) => this.formData(key, formData),
|
|
@@ -289,15 +321,17 @@ export default {
|
|
|
289
321
|
input: ($f) => this.add$f(index, key, $f)
|
|
290
322
|
}}
|
|
291
323
|
props={{
|
|
324
|
+
inFor: true,
|
|
292
325
|
value: this.field ? {[this.field]: this._value(this.value[index])} : this.value[index],
|
|
293
326
|
rule,
|
|
294
327
|
option: options,
|
|
295
|
-
extendOption: true
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
{
|
|
299
|
-
|
|
300
|
-
</
|
|
301
|
-
})
|
|
302
|
-
|
|
328
|
+
extendOption: true
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
<div class="_fc-group-idx">{index + 1}</div>
|
|
332
|
+
{(btn.length) ? <div class="_fc-group-handle">{btn}</div> : null}
|
|
333
|
+
</div>
|
|
334
|
+
});
|
|
335
|
+
return <div key={'con'} class={'_fc-group ' + (disabled ? '_fc-group-disabled' : '')}>{children}</div>
|
|
336
|
+
},
|
|
303
337
|
}
|
package/src/style.css
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
._fc-group{
|
|
2
|
+
display: flex;
|
|
3
|
+
min-height: 42px;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
._fc-group-disabled ._fc-group-btn, ._fc-group-disabled ._fc-group-add{
|
|
9
|
+
cursor: not-allowed;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
._fc-group-handle {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: row;
|
|
15
|
+
position: absolute;
|
|
16
|
+
bottom: -15px;
|
|
17
|
+
right: 30px;
|
|
18
|
+
border-radius: 15px;
|
|
19
|
+
border: 1px dashed #d9d9d9;
|
|
20
|
+
padding: 3px 8px;
|
|
21
|
+
background-color: #ffffff;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
._fc-group-btn{
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
._fc-group-idx {
|
|
29
|
+
position: absolute;
|
|
30
|
+
bottom: -15px;
|
|
31
|
+
left: 10px;
|
|
32
|
+
width: 30px;
|
|
33
|
+
height: 30px;
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
justify-content: center;
|
|
37
|
+
background: #eee;
|
|
38
|
+
border-radius: 15px;
|
|
39
|
+
font-weight: 700;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
._fc-group-handle ._fc-group-btn + ._fc-group-btn {
|
|
43
|
+
margin-left: 7px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
._fc-group-container{
|
|
47
|
+
position: relative;
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-direction: column;
|
|
50
|
+
border: 1px dashed #d9d9d9;
|
|
51
|
+
padding: 20px;
|
|
52
|
+
margin: 5px;
|
|
53
|
+
border-radius: 5px;
|
|
54
|
+
margin-bottom: 25px;
|
|
55
|
+
padding-bottom: 25px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
._fc-group-arrow {
|
|
59
|
+
position: relative;
|
|
60
|
+
width: 20px;
|
|
61
|
+
height: 20px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
._fc-group-arrow::before {
|
|
65
|
+
content: "";
|
|
66
|
+
position: absolute;
|
|
67
|
+
top: 8px;
|
|
68
|
+
left: 5px;
|
|
69
|
+
width: 9px;
|
|
70
|
+
height: 9px;
|
|
71
|
+
border-left: 2px solid #999;
|
|
72
|
+
border-top: 2px solid #999;
|
|
73
|
+
}
|
|
74
|
+
._fc-group-arrow::before {
|
|
75
|
+
transform: rotate(45deg);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
._fc-group-arrow._fc-group-down {
|
|
79
|
+
transform: rotate(180deg);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
._fc-group-plus-minus {
|
|
83
|
+
width: 20px;
|
|
84
|
+
height: 20px;
|
|
85
|
+
position: relative;
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
._fc-group-plus-minus::before,
|
|
90
|
+
._fc-group-plus-minus::after {
|
|
91
|
+
content: "";
|
|
92
|
+
position: absolute;
|
|
93
|
+
top: 50%;
|
|
94
|
+
left: 50%;
|
|
95
|
+
width: 60%;
|
|
96
|
+
height: 2px;
|
|
97
|
+
background-color: #409eff;
|
|
98
|
+
transform: translate(-50%, -50%);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
._fc-group-plus-minus::before {
|
|
102
|
+
transform: translate(-50%, -50%) rotate(90deg);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
._fc-group-plus-minus._fc-group-minus::before {
|
|
106
|
+
display: none;
|
|
107
|
+
}
|
|
108
|
+
._fc-group-plus-minus._fc-group-minus::after {
|
|
109
|
+
background-color: #f56c6c;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
._fc-group-add{
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
width: 25px;
|
|
116
|
+
height: 25px;
|
|
117
|
+
border: 1px solid rgb(64 158 255 / 50%);
|
|
118
|
+
border-radius: 15px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
._fc-group-add._fc-group-plus-minus::before, ._fc-group-add._fc-group-plus-minus::after {
|
|
122
|
+
width: 50%;
|
|
123
|
+
}
|
|
124
|
+
|