lw-cdp-ui 1.2.6 → 1.2.8

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.
@@ -18,7 +18,14 @@
18
18
  :form="form[item.name]"
19
19
  class="object-item"
20
20
  :hideBorder="hideBorder"
21
- @curClick="changeClick"></JsonItem>
21
+ @curClick="changeClick">
22
+ <template v-for="item in custom"
23
+ v-slot:[item.component]="{ itemCur, formCur }">
24
+ <slot :name="item.component"
25
+ :itemCur="itemCur"
26
+ :formCur="formCur"></slot>
27
+ </template>
28
+ </JsonItem>
22
29
  </el-form-item>
23
30
 
24
31
  </template>
@@ -43,7 +50,14 @@
43
50
  :formItems="x"
44
51
  :form="form[item.name][xIndex]"
45
52
  :hideBorder="hideBorder"
46
- @curClick="changeClick"></JsonItem>
53
+ @curClick="changeClick">
54
+ <template v-for="item in custom"
55
+ v-slot:[item.component]="{ itemCur, formCur }">
56
+ <slot :name="item.component"
57
+ :itemCur="itemCur"
58
+ :formCur="formCur"></slot>
59
+ </template>
60
+ </JsonItem>
47
61
  <el-icon class="remove-btn"
48
62
  size="14"
49
63
  v-if="!hideBorder && item.value.length > 1"
@@ -105,7 +119,9 @@ export default {
105
119
  default: () => { }
106
120
  },
107
121
  // 是否是显示边界
108
- hideBorder: { type: Boolean, default: true }
122
+ hideBorder: { type: Boolean, default: true },
123
+ // 自定义组件
124
+ custom: { type: Array, default: () => [] },
109
125
  },
110
126
  computed: {
111
127
  curIndex() {
@@ -310,17 +310,37 @@
310
310
  <el-form-item label="提交校验">
311
311
  <el-select v-model="item.rules"
312
312
  multiple
313
+ value-key="label"
313
314
  clearable
314
315
  placeholder="请选择">
315
316
  <el-option v-for="item in rules"
317
+ :key="item.label"
316
318
  :label="item.label"
317
- :value="item.value" />
319
+ :value="item" />
318
320
  </el-select>
319
321
  </el-form-item>
320
- <el-form-item label="隐藏校验">
321
- <el-input v-model="item.hideHandle"
322
- placeholder="请输入"
323
- clearable />
322
+ <el-form-item label="隐藏校验(满足条件时将隐藏该项)">
323
+ <div class="input-body">
324
+ <el-cascader v-model="hideForm.label"
325
+ :show-all-levels="false"
326
+ :props="{ emitPath: false }"
327
+ style="flex:1.2;"
328
+ :options="strList" />
329
+ <el-select v-model="hideForm.filter"
330
+ clearable
331
+ style="flex:1;"
332
+ placeholder="条件">
333
+ <el-option v-for="item in filter"
334
+ :key="item.label"
335
+ :label="item.label"
336
+ :value="item.value" />
337
+ </el-select>
338
+ <el-input v-model="hideForm.value"
339
+ style="flex:1;"
340
+ placeholder="值"
341
+ clearable />
342
+ </div>
343
+
324
344
  </el-form-item>
325
345
 
326
346
  </div>
@@ -356,15 +376,22 @@ export default {
356
376
  data() {
357
377
  return {
358
378
  tagVisible: {},
379
+ hideForm: {},
359
380
  tagValue: '',
381
+ filter: [
382
+ { label: '等于', value: '==' },
383
+ { label: '大于', value: '>' },
384
+ { label: '大于等于', value: '>=' },
385
+ { label: '小于', value: '<' },
386
+ { label: '小于等于', value: '<=' },
387
+ { label: '不等于', value: '!=' }
388
+ ],
360
389
  rules: [
361
390
  {
362
- label: '必填',
363
- value: { required: true, message: '请输入', trigger: 'blur' }
391
+ label: '必填', required: true, message: '请输入', trigger: 'blur'
364
392
  },
365
393
  {
366
- label: '必选',
367
- value: { required: true, message: '请选择', trigger: 'change' }
394
+ label: '必选', required: true, message: '请选择', trigger: 'change'
368
395
  },
369
396
  ]
370
397
  }
@@ -374,13 +401,53 @@ export default {
374
401
  type: Object,
375
402
  default: () => ({})
376
403
  },
377
- form: {
404
+ config: {
378
405
  type: Object,
379
406
  default: () => ({})
380
- },
381
- isBorder: {
382
- type: Boolean,
383
- default: false
407
+ }
408
+ },
409
+ watch: {
410
+ hideForm: {
411
+ handler(val) {
412
+ if (!val?.label || !val.filter || !val.value) {
413
+ this.item.hideHandle = ''
414
+ return
415
+ }
416
+ this.item.hideHandle = `$.${val.label} ${val.filter} ${val.value}`
417
+ },
418
+ deep: true
419
+ }
420
+ },
421
+ computed: {
422
+ // 字段
423
+ strList() {
424
+ function parse(data) {
425
+ const parseItem = (item) => {
426
+ let node = {
427
+ label: item.label,
428
+ value: item.name || item.label
429
+ };
430
+
431
+ if (item.component === 'object' || item.component === 'list') {
432
+ // 如果是组合或者列表,递归处理子节点
433
+ node.children = (item.value || []).map((subItem) => {
434
+ if (Array.isArray(subItem)) {
435
+ return subItem.map(parseItem); // 处理二维数组的情况
436
+ }
437
+ return parseItem(subItem);
438
+ }).flat();
439
+ } else if (item.component === 'checkbox' || item.component === 'upload') {
440
+ // 如果是复选框或者上传组件,从 options.items 中提取子节点
441
+ node.value = item.options?.items[0].name
442
+ }
443
+
444
+ return node;
445
+ };
446
+
447
+ return data.formItems.map(parseItem);
448
+ }
449
+ let list = parse(this.config)
450
+ return list
384
451
  }
385
452
  },
386
453
  methods: {
@@ -437,5 +504,10 @@ export default {
437
504
  .w-20 {
438
505
  width: 100px;
439
506
  }
507
+
508
+ .input-body {
509
+ display: flex;
510
+ align-items: center;
511
+ }
440
512
  }
441
513
  </style>
@@ -32,21 +32,22 @@
32
32
  <el-form ref="form"
33
33
  @click.capture="back(config)"
34
34
  :model="form"
35
- :label-width="localConfig.labelWidth"
36
- :label-position="$i18n.locale == 'en-us' ? 'top' : localConfig.labelPosition"
35
+ :label-width="config.labelWidth"
36
+ :label-position="$i18n.locale == 'en-us' ? 'top' : config.labelPosition"
37
37
  v-loading="loading"
38
38
  :disabled="isView"
39
39
  element-loading-text="Loading...">
40
40
  <el-row>
41
- <JsonItem :formItems="localConfig.formItems"
41
+ <JsonItem :formItems="config.formItems"
42
42
  :hideBorder="hideBorder"
43
43
  :form="form"
44
+ :custom="custom"
44
45
  @curClick="selectItem">
45
46
  <template v-for="item in custom"
46
- v-slot:[item.component]>
47
+ v-slot:[item.component]="{ itemCur, formCur }">
47
48
  <slot :name="item.component"
48
- :itemCur="item"
49
- :formCur="form"></slot>
49
+ :itemCur="itemCur"
50
+ :formCur="formCur"></slot>
50
51
  </template>
51
52
  </JsonItem>
52
53
  </el-row>
@@ -58,7 +59,8 @@
58
59
  <el-aside v-if="hideTool"
59
60
  width="300px"
60
61
  class="aside-right">
61
- <StatsConfig :item="curItem" />
62
+ <StatsConfig :item="curItem"
63
+ :config="config" />
62
64
  </el-aside>
63
65
  </el-container>
64
66
  </template>
@@ -125,7 +127,6 @@ export default {
125
127
  data() {
126
128
  return {
127
129
  form: {},
128
- localConfig: {},
129
130
  curItem: {},
130
131
  scrollObserverEnabled: true,
131
132
  renderLoading: false,
@@ -145,17 +146,9 @@ export default {
145
146
  config: {
146
147
  handler(val) {
147
148
  this.render()
148
- this.localConfig = JSON.parse(JSON.stringify(val))
149
- },
150
- immediate: true,
151
- deep: true
152
- },
153
- localConfig: {
154
- handler(val) {
155
- this.render(val)
156
149
  this.$emit("update:config", val)
157
-
158
150
  },
151
+ immediate: true,
159
152
  deep: true
160
153
  },
161
154
  },
@@ -31,7 +31,7 @@
31
31
 
32
32
  <!-- input -->
33
33
  <template v-if="item.component == 'input'">
34
- <el-input v-model="item.value"
34
+ <el-input v-model="objItem.value"
35
35
  :placeholder="item?.options?.placeholder"
36
36
  clearable
37
37
  :type="item?.options?.type"
@@ -47,7 +47,7 @@
47
47
  </template>
48
48
  <!-- upload -->
49
49
  <template v-else-if="item.component == 'upload'">
50
- <template v-for="(_item, _index) in item?.options.items"
50
+ <template v-for="(_item, _index) in objItem?.options.items"
51
51
  :key="_index">
52
52
  <lw-upload v-model="_item.value"
53
53
  :height="item.height"
@@ -69,12 +69,12 @@
69
69
  <template v-else-if="item.component == 'checkbox'">
70
70
  <el-checkbox v-model="_item.value"
71
71
  :label="_item.label"
72
- v-for="(_item, _index) in item?.options.items"
72
+ v-for="(_item, _index) in objItem?.options.items"
73
73
  :key="_index"></el-checkbox>
74
74
  </template>
75
75
  <!-- checkboxGroup -->
76
76
  <template v-else-if="item.component == 'checkboxGroup'">
77
- <el-checkbox-group v-model="item.value">
77
+ <el-checkbox-group v-model="objItem.value">
78
78
  <el-checkbox v-for="_item in item?.options.items"
79
79
  :key="_item.value"
80
80
  :value="_item.value">{{ _item.label }}</el-checkbox>
@@ -83,14 +83,14 @@
83
83
 
84
84
  <!-- switch -->
85
85
  <template v-else-if="item.component == 'switch'">
86
- <el-switch v-model="item.value"
86
+ <el-switch v-model="objItem.value"
87
87
  inline-prompt
88
88
  :active-text="item?.options?.activeText"
89
89
  :inactive-text="item?.options?.inactiveText" />
90
90
  </template>
91
91
  <!-- select -->
92
92
  <template v-else-if="item.component == 'select'">
93
- <el-select v-model="item.value"
93
+ <el-select v-model="objItem.value"
94
94
  :multiple="item?.options?.multiple"
95
95
  :allow-create="item?.options?.allowCreate"
96
96
  default-first-option
@@ -110,7 +110,7 @@
110
110
  </template>
111
111
  <!-- treeSelect -->
112
112
  <template v-else-if="item.component == 'treeSelect'">
113
- <el-tree-select v-model="item.value"
113
+ <el-tree-select v-model="objItem.value"
114
114
  :props="item?.options?.props"
115
115
  :node-Key="item?.options?.nodeKey"
116
116
  :multiple="item?.options?.multiple"
@@ -120,7 +120,7 @@
120
120
  </template>
121
121
  <!-- cascader -->
122
122
  <template v-else-if="item.component == 'cascader'">
123
- <el-cascader v-model="item.value"
123
+ <el-cascader v-model="objItem.value"
124
124
  style="width: 100%;"
125
125
  :props="item?.options?.props"
126
126
  :separator="item?.options?.separator"
@@ -130,7 +130,7 @@
130
130
  </template>
131
131
  <!-- date -->
132
132
  <template v-else-if="item.component == 'date'">
133
- <el-date-picker v-model="item.value"
133
+ <el-date-picker v-model="objItem.value"
134
134
  style="width: 100%;"
135
135
  :type="item?.options?.type"
136
136
  :start-placeholder="item?.options?.startPlaceholder"
@@ -145,7 +145,7 @@
145
145
  </template>
146
146
  <!-- number -->
147
147
  <template v-else-if="item.component == 'number'">
148
- <el-input-number v-model="item.value"
148
+ <el-input-number v-model="objItem.value"
149
149
  :disabled="item?.options?.disabled"
150
150
  :min="item?.options?.min"
151
151
  :max="item?.options?.max"
@@ -161,7 +161,7 @@
161
161
  </template>
162
162
  <!-- radio -->
163
163
  <template v-else-if="item.component == 'radio'">
164
- <el-radio-group v-model="item.value"
164
+ <el-radio-group v-model="objItem.value"
165
165
  :disabled="item?.options.disabled">
166
166
  <el-radio v-for="_item in item?.options.items"
167
167
  :key="_item.value"
@@ -170,35 +170,35 @@
170
170
  </template>
171
171
  <!-- color -->
172
172
  <template v-else-if="item.component == 'color'">
173
- <el-color-picker v-model="item.value" />
173
+ <el-color-picker v-model="objItem.value" />
174
174
  </template>
175
175
  <!-- rate -->
176
176
  <template v-else-if="item.component == 'rate'">
177
177
  <el-rate style="margin-top: 6px;"
178
- v-model="item.value"></el-rate>
178
+ v-model="objItem.value"></el-rate>
179
179
  </template>
180
180
  <!-- slider -->
181
181
  <template v-else-if="item.component == 'slider'">
182
- <el-slider v-model="item.value"
182
+ <el-slider v-model="objItem.value"
183
183
  :marks="item?.options.marks"></el-slider>
184
184
  </template>
185
185
 
186
186
  <!-- tags -->
187
187
  <template v-else-if="item.component == 'tags'">
188
188
  <div class="tags-list">
189
- <el-tag v-for="tag in item.value"
189
+ <el-tag v-for="tag in objItem.value"
190
190
  :key="tag"
191
191
  closable
192
192
  :disable-transitions="false"
193
- @close="tagClose(tag, item.value)">
193
+ @close="tagClose(tag, objItem.value)">
194
194
  {{ tag }}
195
195
  </el-tag>
196
196
  <el-input v-if="tagVisible[item.name]"
197
197
  v-model="tagValue"
198
198
  class="w-20"
199
199
  size="small"
200
- @keyup.enter="tagInputConfirm(item, item.value)"
201
- @blur="tagInputConfirm(item, item.value)" />
200
+ @keyup.enter="tagInputConfirm(item, objItem.value)"
201
+ @blur="tagInputConfirm(item, objItem.value)" />
202
202
  <el-button v-else
203
203
  class="button-new-tag"
204
204
  size="small"
@@ -230,6 +230,7 @@ export default {
230
230
  return {
231
231
  tagVisible: {},
232
232
  dataForm: {},
233
+ objItem: {},
233
234
  tagValue: ''
234
235
  }
235
236
  },
@@ -254,32 +255,38 @@ export default {
254
255
  form: {
255
256
  handler(val) {
256
257
  if (this.item.component === 'checkbox' || this.item.component === 'upload') {
257
- this.item.options?.items?.forEach((option) => {
258
+ this.objItem.options?.items?.forEach((option) => {
258
259
  option.value = this.flattenObject(this.form, option.name, option.value)
259
260
  });
260
261
  } else {
261
- this.item.value = this.flattenObject(this.form, this.item.name, this.item.value)
262
+ this.objItem.value= this.flattenObject(this.form, this.item.name, this.objItem.value)
262
263
  }
263
264
  },
264
265
  immediate: true,
265
266
  deep: true
266
267
  },
267
268
  item: {
269
+ handler(val) {
270
+ this.objItem = val
271
+ },
272
+ immediate: true,
273
+ deep: true
274
+ },
275
+ objItem: {
268
276
  handler(val) {
269
277
  if (val.component === 'checkbox' || val.component === 'upload') {
270
278
  val.options?.items?.forEach((option) => {
271
279
  this.unflattenObject(this.form, option.name, option.value)
272
280
  });
273
281
  } else {
274
- this.unflattenObject(this.form, this.item.name, val.value)
282
+ this.unflattenObject(this.form, val.name, val.value)
275
283
  }
276
284
  },
277
285
  deep: true
278
- }
286
+ },
279
287
  },
280
288
  methods: {
281
289
  flattenObject(obj, key, defaultValue = '') {
282
- console.log(obj, key)
283
290
  if (!key || !obj) { return false }
284
291
  const keys = key.split('.'); // 将路径拆分成数组
285
292
 
@@ -293,28 +300,25 @@ export default {
293
300
  // 否则,继续向下查找
294
301
  current = current[keys[i]];
295
302
  }
296
-
297
303
  return current;
298
304
  },
299
305
  unflattenObject(obj, path, value) {
300
306
  if (!path || !obj) { return false }
301
307
  const keys = path.split('.'); // 按点分隔路径
302
- let current = obj; // 指向传入的对象(如 this.form)
303
308
 
304
309
  keys.forEach((key, index) => {
305
310
  if (index === keys.length - 1) {
306
311
  // 最后一级,直接赋值
307
- current[key] = value;
312
+ obj[key] = value || obj[path];
308
313
  } else {
309
314
  // 如果不存在该层级,创建空对象
310
- if (!current[key] || typeof current[key] !== 'object') {
311
- current[key] = {};
315
+ if (!obj[key] || typeof obj[key] !== 'object') {
316
+ obj[key] = {};
312
317
  }
313
- current = current[key]; // 进入下一层
318
+ obj = obj[key]; // 进入下一层
314
319
  }
315
320
  });
316
321
 
317
-
318
322
  },
319
323
  // 删除tag
320
324
  tagClose(tag, item) {
@@ -3,7 +3,7 @@
3
3
  :offset="100"
4
4
  style="width: 100%; height: 45px;">
5
5
  <ul class="affix-body">
6
- <template v-for="(item, index) in localConfig.formItems"
6
+ <template v-for="(item, index) in config.formItems"
7
7
  :key="index">
8
8
  <a v-if="item.component === 'divider'"
9
9
  class="anchor-link"
@@ -21,14 +21,14 @@
21
21
  <el-form v-else
22
22
  ref="form"
23
23
  :model="form"
24
- :label-width="localConfig.labelWidth"
25
- :label-position="$i18n.locale == 'en-us' ? 'top' : localConfig.labelPosition"
24
+ :label-width="config.labelWidth"
25
+ :label-position="$i18n.locale == 'en-us' ? 'top' : config.labelPosition"
26
26
  v-loading="loading"
27
27
  :disabled="isView"
28
28
  element-loading-text="Loading...">
29
29
  <el-row :gutter="15">
30
30
 
31
- <template v-for="(item, index) in localConfig.formItems">
31
+ <template v-for="(item, index) in config.formItems">
32
32
  <el-col :span="item.span || 24"
33
33
  v-if="!hideHandle(item)">
34
34
  <FormItem :item="item"
@@ -110,7 +110,6 @@ export default {
110
110
  data() {
111
111
  return {
112
112
  form: {},
113
- localConfig: {},
114
113
  affixIndex: 0,
115
114
  isChange: true,
116
115
  scrollObserverEnabled: true,
@@ -128,24 +127,17 @@ export default {
128
127
  },
129
128
  config: {
130
129
  handler(val) {
131
- this.render()
130
+ this.render(val)
132
131
  if (this.showMenu) {
133
132
  this.$nextTick(() => {
134
133
  this.handleScroll()
135
134
  })
136
135
  }
137
- this.localConfig = JSON.parse(JSON.stringify(val))
138
- },
139
- immediate: true,
140
- deep: true
141
- },
142
- localConfig: {
143
- handler(val) {
144
- this.render(val)
145
136
  this.$emit("update:config", val)
146
137
  },
138
+ immediate: true,
147
139
  deep: true
148
- },
140
+ }
149
141
  },
150
142
  computed: {
151
143
  hasConfig() {