lw-cdp-ui 1.2.1 → 1.2.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.
@@ -7,7 +7,7 @@
7
7
  ghost-class="draggable-ghost"
8
8
  :class="{ showBorder: hideBorder, cur: curIndex == (formItems.name || formItems?.options?.items[0]?.name) }">
9
9
  <template #item="{element: item, index}">
10
- <el-col :span="item.span || 24"
10
+ <el-col :span="['list'].includes(item.component) ? 24 : item.span || 24"
11
11
  :class="{ borderItem: hideBorder, cur: hideBorder && curIndex == (item.name || item?.options?.items[0]?.name) }"
12
12
  v-if="!hideHandle(item)">
13
13
  <!-- 组合/列表 -->
@@ -24,30 +24,34 @@
24
24
  </template>
25
25
  <!-- 列表 显示时 -->
26
26
  <template v-else-if="['list'].includes(item.component)">
27
- <el-form-item :label="item.label"
28
- @click.capture="changeClick(item)">
29
- <div class="list-item"
30
- :class="{ borderItem: hideBorder }"
31
- v-for="(x, xIndex) in item.value">
32
- <JsonItem v-if="form[item.name]"
33
- :formItems="x"
34
- :form="form[item.name][xIndex]"
35
- :hideBorder="hideBorder"
36
- @curClick="changeClick"></JsonItem>
27
+ <el-form-item @click.capture="changeClick(item)">
28
+ <template #label>
29
+ {{ item.label }}
30
+ <el-button v-if="!hideBorder"
31
+ type="primary"
32
+ class="add-btn"
33
+ plain
34
+ size="small"
35
+ icon="el-icon-plus"
36
+ @click="addListItem(item.value)">{{ $t('btn.add') }}</el-button>
37
+ </template>
38
+ <el-col :span="item.span || 24"
39
+ v-for="(x, xIndex) in item.value">
40
+ <div class="list-item"
41
+ :class="{borderItem: hideBorder}">
42
+ <JsonItem v-if="form[item.name]"
43
+ :formItems="x"
44
+ :form="form[item.name][xIndex]"
45
+ :hideBorder="hideBorder"
46
+ @curClick="changeClick"></JsonItem>
47
+ <el-icon class="remove-btn"
48
+ size="14"
49
+ v-if="!hideBorder && item.value.length > 1"
50
+ @click="deleteListItem(item.value, xIndex)"><el-icon-delete /></el-icon>
51
+ </div>
37
52
 
38
- <el-icon class="remove-btn"
39
- size="14"
40
- v-if="!hideBorder && item.value.length > 1"
41
- @click="deleteListItem(item.value, xIndex)"><el-icon-delete /></el-icon>
42
- </div>
53
+ </el-col>
43
54
 
44
- <el-button v-if="!hideBorder"
45
- type="primary"
46
- class="add-btn"
47
- plain
48
- size="small"
49
- icon="el-icon-plus"
50
- @click="addListItem(item.value)">{{ $t('btn.add') }}</el-button>
51
55
  </el-form-item>
52
56
 
53
57
  </template>
@@ -235,9 +239,25 @@ export default {
235
239
  padding: 10px;
236
240
  width: 100%;
237
241
  }
238
-
242
+ :deep(.el-form-item) {
243
+ position: relative;
244
+ }
239
245
  .add-btn {
240
- width: 100%;
241
- margin-top: 5px;
246
+ top: 0px;
247
+ right: 0;
248
+ z-index: 9;
249
+ position: absolute;
250
+ }
251
+ :deep(.el-form-item--label-right),:deep(.el-form-item--label-left) {
252
+ .el-form-item__label {
253
+ position: relative;
254
+ .add-btn {
255
+ top: 30px;
256
+ right: 10px;
257
+ // left: 0;
258
+ // z-index: 9;
259
+ // position: absolute;
260
+ }
261
+ }
242
262
  }
243
263
  </style>
@@ -110,6 +110,38 @@
110
110
 
111
111
  </template>
112
112
 
113
+ <template v-if="['tags'].includes(item.component)">
114
+ <el-form-item label="按钮名称">
115
+ <el-input v-model="item.options.addText"
116
+ placeholder="请输入"
117
+ clearable />
118
+ </el-form-item>
119
+ <el-form-item label="默认标签">
120
+ <div class="tags-list">
121
+ <el-tag v-for="tag in item.value"
122
+ :key="tag"
123
+ closable
124
+ :disable-transitions="false"
125
+ @close="tagClose(tag, item.value)">
126
+ {{ tag }}
127
+ </el-tag>
128
+ <el-input v-if="tagVisible[item.name]"
129
+ v-model="tagValue"
130
+ class="w-20"
131
+ size="small"
132
+ @keyup.enter="tagInputConfirm(item, item.value)"
133
+ @blur="tagInputConfirm(item, item.value)" />
134
+ <el-button v-else
135
+ class="button-new-tag"
136
+ size="small"
137
+ @click="tagVisible[item.name] = true">
138
+ + 添加
139
+ </el-button>
140
+ </div>
141
+ </el-form-item>
142
+
143
+ </template>
144
+
113
145
  <el-form-item v-if="item.component === 'switch'"
114
146
  label="开关文字">
115
147
  <div class="form-item">
@@ -301,6 +333,12 @@
301
333
  <script>
302
334
  export default {
303
335
  name: 'StatsConfig',
336
+ data() {
337
+ return {
338
+ tagVisible: {},
339
+ tagValue: ''
340
+ }
341
+ },
304
342
  props: {
305
343
  item: {
306
344
  type: Object,
@@ -314,6 +352,21 @@ export default {
314
352
  type: Boolean,
315
353
  default: false
316
354
  }
355
+ },
356
+ methods: {
357
+ // 删除tag
358
+ tagClose(tag, item) {
359
+ item.splice(item.indexOf(tag), 1)
360
+ },
361
+ // 增加tag
362
+ tagInputConfirm(item, val) {
363
+ if (this.tagValue) {
364
+ val = val || []
365
+ val.push(this.tagValue)
366
+ }
367
+ this.tagVisible[item.name] = false
368
+ this.tagValue = ''
369
+ }
317
370
  }
318
371
  };
319
372
  </script>
@@ -342,5 +395,17 @@ export default {
342
395
  gap: 5px;
343
396
  margin-bottom: 10px;
344
397
  }
398
+
399
+ :deep(.el-tag) {
400
+ & + .button-new-tag {
401
+ margin-left: 10px;
402
+ }
403
+ & + .w-20 {
404
+ margin-left: 10px;
405
+ }
406
+ }
407
+ .w-20 {
408
+ width: 100px;
409
+ }
345
410
  }
346
411
  </style>
@@ -146,12 +146,12 @@ export default {
146
146
  },
147
147
  deep: true
148
148
  },
149
- form: {
150
- handler(val) {
151
- this.$emit("update:modelValue", val)
152
- },
153
- deep: true
154
- },
149
+ // form: {
150
+ // handler(val) {
151
+ // this.$emit("update:modelValue", val)
152
+ // },
153
+ // deep: true
154
+ // },
155
155
  localConfig: {
156
156
  handler(val) {
157
157
  this.render(val)
@@ -239,10 +239,32 @@ export default {
239
239
  return result;
240
240
  }
241
241
 
242
- this.form = parse(config.formItems, this.modelValue);
243
- this.$emit("update:modelValue", this.form);
242
+ let form = parse(config.formItems, this.modelValue);
243
+ this.form = {
244
+ ...this.modelValue,
245
+ ...form
246
+ }
247
+
248
+ this.$emit("update:modelValue", this.parseNestedObject(this.form));
244
249
  this.localConfig = this.config;
245
250
  },
251
+ parseNestedObject(obj) {
252
+ const result = {};
253
+ for (const [key, value] of Object.entries(obj)) {
254
+ const keys = key.split('.');
255
+ let current = result;
256
+
257
+ keys.forEach((k, index) => {
258
+ if (!current[k]) {
259
+ current[k] = index === keys.length - 1 ? value : {};
260
+ }
261
+ current = current[k];
262
+ });
263
+
264
+ delete obj[key]
265
+ }
266
+ return result;
267
+ },
246
268
 
247
269
  //数据验证
248
270
  validate(valid, obj) {
@@ -65,8 +65,11 @@ export default [
65
65
  {
66
66
  label: '标签',
67
67
  name: 'tags',
68
- value: '',
68
+ value: [],
69
69
  span: 24,
70
+ options: {
71
+ addText: '添加',
72
+ },
70
73
  component: 'tags'
71
74
  }
72
75
  ]
@@ -203,7 +203,7 @@
203
203
  class="button-new-tag"
204
204
  size="small"
205
205
  @click="tagVisible[item.name] = true">
206
- + 添加
206
+ + {{item?.options?.addText || '添加'}}
207
207
  </el-button>
208
208
  </div>
209
209
  </template>
@@ -268,10 +268,10 @@ export default {
268
268
  handler(val) {
269
269
  if (val.component === 'checkbox' || val.component === 'upload') {
270
270
  val.options?.items?.forEach((option) => {
271
- this.unflattenObject(this.form, option.name, option[option.name])
271
+ this.unflattenObject(this.form, option.name, option.value)
272
272
  });
273
273
  } else {
274
- this.unflattenObject(this.form, this.item.name, val[this.item.name])
274
+ this.unflattenObject(this.form, this.item.name, val.value)
275
275
  }
276
276
  },
277
277
  deep: true
@@ -281,6 +281,7 @@ export default {
281
281
  flattenObject(obj, key, defaultValue = '') {
282
282
  if (!key || !obj) { return false }
283
283
  const keys = key.split('.'); // 将路径拆分成数组
284
+
284
285
  let current = obj;
285
286
  // 遍历路径并逐层查找
286
287
  for (let i = 0; i < keys.length; i++) {
@@ -291,7 +292,7 @@ export default {
291
292
  // 否则,继续向下查找
292
293
  current = current[keys[i]];
293
294
  }
294
-
295
+
295
296
  return current;
296
297
  },
297
298
  unflattenObject(obj, path, value) {
@@ -310,6 +311,8 @@ export default {
310
311
  current = current[key]; // 进入下一层
311
312
  }
312
313
  });
314
+
315
+
313
316
  },
314
317
  // 删除tag
315
318
  tagClose(tag, item) {
@@ -375,13 +378,9 @@ export default {
375
378
  min-width: 130px;
376
379
  padding-left: 20px;
377
380
  }
378
- .button-new-tag {
379
- margin-left: 10px;
380
- }
381
381
 
382
382
  .w-20 {
383
383
  width: 100px;
384
- margin-left: 10px;
385
384
  }
386
385
 
387
386
  .title-name {
@@ -440,4 +439,13 @@ export default {
440
439
  }
441
440
  }
442
441
  }
442
+
443
+ :deep(.el-tag) {
444
+ & + .button-new-tag {
445
+ margin-left: 10px;
446
+ }
447
+ & + .w-20 {
448
+ margin-left: 10px;
449
+ }
450
+ }
443
451
  </style>
@@ -135,20 +135,12 @@ export default {
135
135
  })
136
136
  }
137
137
  },
138
- immediate: true,
139
- deep: true
140
- },
141
- form: {
142
- handler(val) {
143
- this.$emit("update:modelValue", val)
144
- },
145
138
  deep: true
146
139
  },
147
140
  localConfig: {
148
141
  handler(val) {
149
142
  this.render(val)
150
143
  this.$emit("update:config", val)
151
-
152
144
  },
153
145
  deep: true
154
146
  },
@@ -206,6 +198,7 @@ export default {
206
198
  result[item.name] = existingValue ?? (item.value !== undefined ? Number(item.value) : item.options?.min || 0);
207
199
  } else {
208
200
  result[item.name] = existingValue ?? item.value;
201
+
209
202
  }
210
203
  }
211
204
  });
@@ -213,10 +206,35 @@ export default {
213
206
  return result;
214
207
  }
215
208
 
216
- this.form = parse(config.formItems, this.modelValue);
217
- this.$emit("update:modelValue", this.form);
209
+ let form = parse(config.formItems, this.modelValue);
210
+
211
+ this.form = {
212
+ ...this.modelValue,
213
+ ...form
214
+ }
215
+
216
+ this.$emit("update:modelValue", this.parseNestedObject(this.form));
218
217
  this.localConfig = this.config;
219
218
  },
219
+
220
+ parseNestedObject(obj) {
221
+ const result = {};
222
+ for (const [key, value] of Object.entries(obj)) {
223
+ const keys = key.split('.');
224
+ let current = result;
225
+
226
+ keys.forEach((k, index) => {
227
+ if (!current[k]) {
228
+ current[k] = index === keys.length - 1 ? value : {};
229
+ }
230
+ current = current[k];
231
+ });
232
+
233
+ delete obj[key]
234
+ }
235
+ return result;
236
+ },
237
+
220
238
  //处理动态隐藏
221
239
  hideHandle(item) {
222
240
  if (typeof item?.hideHandle === 'string') {