@form-create/component-elm-group 2.5.31 → 2.5.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@form-create/component-elm-group",
3
- "version": "2.5.31",
3
+ "version": "2.5.33",
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": "a963ffacbba371b5589112e605846dc993944dc0"
42
+ "gitHead": "12917cac42299a1b546cb76ab6a901bcaa872801"
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 = Object.keys(this.cacheRule), total = keys.length, len = total - n.length;
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);
@@ -148,7 +157,7 @@ export default {
148
157
  },
149
158
  formData(key, formData) {
150
159
  const cacheRule = this.cacheRule;
151
- const keys = Object.keys(cacheRule);
160
+ const keys = this.sort;
152
161
  if (keys.filter(k => cacheRule[k].$f).length !== keys.length) {
153
162
  return;
154
163
  }
@@ -169,7 +178,7 @@ export default {
169
178
  return;
170
179
  }
171
180
  this.cache(key, value);
172
- $f.coverValue(value || {});
181
+ $f && $f.coverValue(value || {});
173
182
  },
174
183
  addRule(i, emit) {
175
184
  const rule = this.formCreateInject.form.copyRules(this.formRule);
@@ -182,6 +191,7 @@ export default {
182
191
  const defVal = deepCopy(this.defaultValue);
183
192
  extend(options.formData, this.field ? {[this.field]: defVal} : defVal);
184
193
  }
194
+ this.parse && this.parse({rule, options, index: this.sort.length});
185
195
  this.$set(this.cacheRule, ++this.len, {rule, options});
186
196
  if (emit) {
187
197
  this.$nextTick(() => this.$emit('add', rule, Object.keys(this.cacheRule).length - 1));
@@ -189,7 +199,6 @@ export default {
189
199
  },
190
200
  add$f(i, key, $f) {
191
201
  this.cacheRule[key].$f = $f;
192
- this.formData(key, $f.formData());
193
202
  this.$nextTick(() => {
194
203
  if (this.syncDisabled) {
195
204
  $f.disabled(this.disabled);
@@ -216,18 +225,30 @@ export default {
216
225
  return;
217
226
  }
218
227
  this.removeRule(key, true);
219
- this.value.splice(index, 1);
220
- this.input(this.value);
228
+ const value = [...this.value];
229
+ value.splice(index, 1);
230
+ this.input(value);
221
231
  },
222
232
  addIcon(key) {
223
- return <i key={`a${key}`} class="el-icon-circle-plus-outline"
224
- style={`font-size:${this.fontSize}px;cursor:${this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer'};`}
225
- on-click={this.add}/>;
233
+ return <div class="_fc-group-btn _fc-group-plus-minus" on-click={this.add}></div>;
226
234
  },
227
235
  delIcon(index, key) {
228
- return <i key={`d${key}`} class="el-icon-remove-outline"
229
- style={`font-size:${this.fontSize}px;cursor:${this.disabled ? 'not-allowed;color:#c9cdd4' : 'pointer;color:#606266'};`}
230
- on-click={() => this.del(index, key)}/>;
236
+ return <div class="_fc-group-btn _fc-group-plus-minus _fc-group-minus"
237
+ onClick={() => this.del(index, key)}></div>
238
+ },
239
+ sortUpIcon(index) {
240
+ return <div class="_fc-group-btn _fc-group-arrow _fc-group-up"
241
+ onClick={() => this.changeSort(index, -1)}></div>
242
+ },
243
+ sortDownIcon(index) {
244
+ return <div class="_fc-group-btn _fc-group-arrow _fc-group-down"
245
+ onClick={() => this.changeSort(index, 1)}></div>
246
+ },
247
+ changeSort(index, sort) {
248
+ const a = this.sort[index];
249
+ this.$set(this.sort, index, this.sort[index + sort]);
250
+ this.sort[index + sort] = a;
251
+ this.formData(0);
231
252
  },
232
253
  makeIcon(total, index, key) {
233
254
  if (this.$scopedSlots.button) {
@@ -240,12 +261,20 @@ export default {
240
261
  add: this.add
241
262
  });
242
263
  }
243
- if (index === 0) {
244
- return [(this.max !== 0 && total >= this.max) ? null : this.addIcon(key), (this.min === 0 || total > this.min) ? this.delIcon(index, key) : null];
264
+ const btn = [];
265
+ if ((!this.max || total < this.max) && total === index + 1) {
266
+ btn.push(this.addIcon(key));
245
267
  }
246
268
  if (total > this.min) {
247
- return this.delIcon(index, key);
269
+ btn.push(this.delIcon(index, key));
270
+ }
271
+ if (this.sortBtn && index) {
272
+ btn.push(this.sortUpIcon(index));
273
+ }
274
+ if (this.sortBtn && index !== total - 1) {
275
+ btn.push(this.sortDownIcon(index));
248
276
  }
277
+ return btn;
249
278
  },
250
279
  emitEvent(name, args, index, key) {
251
280
  this.$emit(name, ...args, this.cacheRule[key].$f, index);
@@ -267,21 +296,21 @@ export default {
267
296
  }
268
297
  },
269
298
  render() {
270
- const keys = Object.keys(this.cacheRule);
299
+ const keys = this.sort;
271
300
  const button = this.button;
272
301
  const Type = this.type;
273
- return keys.length === 0 ?
302
+ const disabled = this.disabled;
303
+
304
+ const children = keys.length === 0 ?
274
305
  (this.$scopedSlots.default ? (this.$scopedSlots.default({
275
306
  vm: this,
276
307
  add: this.add
277
- })) : <i key={'a_def'} class="el-icon-circle-plus-outline"
278
- style={`font-size:${this.fontSize}px;vertical-align:middle;color:${this.disabled ? '#c9cdd4;cursor: not-allowed' : '#606266;cursor:pointer'};`}
279
- on-click={this.add}/>) :
280
- <div key={'con'}>{keys.map((key, index) => {
308
+ })) : <div key={'a_def'} class="_fc-group-plus-minus _fc-group-add"
309
+ on-click={this.add}/>) : keys.map((key, index) => {
281
310
  const {rule, options} = this.cacheRule[key];
282
- return <ElRow align="middle" type="flex" key={key}
283
- style="border-bottom:1px dashed #DCDFE6;margin-bottom:10px;">
284
- <ElCol span={button ? 20 : 24}><Type
311
+ const btn = button && !disabled ? this.makeIcon(keys.length, index, key) : [];
312
+ return <div class="_fc-group-container" key={key}>
313
+ <Type
285
314
  key={key}
286
315
  on={{
287
316
  'update:value': (formData) => this.formData(key, formData),
@@ -289,15 +318,17 @@ export default {
289
318
  input: ($f) => this.add$f(index, key, $f)
290
319
  }}
291
320
  props={{
321
+ inFor: true,
292
322
  value: this.field ? {[this.field]: this._value(this.value[index])} : this.value[index],
293
323
  rule,
294
324
  option: options,
295
- extendOption: true,
296
- inFor: true
297
- }}/></ElCol>
298
- {button ? <ElCol
299
- props={{span: 2, pull: 1, push: 1}}>{this.makeIcon(keys.length, index, key)}</ElCol> : null}
300
- </ElRow>
301
- })}</div>
302
- }
325
+ extendOption: true
326
+ }}
327
+ />
328
+ <div class="_fc-group-idx">{index + 1}</div>
329
+ {(btn.length) ? <div class="_fc-group-handle">{btn}</div> : null}
330
+ </div>
331
+ });
332
+ return <div key={'con'} class={'_fc-group ' + (disabled ? '_fc-group-disabled' : '')}>{children}</div>
333
+ },
303
334
  }
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
+