lw-cdp-ui 1.5.54 → 1.5.56

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.
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <draggable
3
3
  :list="formItems"
4
- item-key="name"
4
+ item-key="key"
5
5
  group="people"
6
6
  :animation="350"
7
7
  :disabled="hideBorder"
@@ -9,14 +9,14 @@
9
9
  ghost-class="draggable-ghost"
10
10
  :class="{
11
11
  showBorder: !hideBorder,
12
- cur: curIndex == `${this.uuid}${formItems.name || formItems?.options?.items[0]?.name}`
12
+ cur: curIndex == `${uuid}${formItems.name || formItems?.options?.items[0]?.name}`
13
13
  }">
14
14
  <template #item="{ element: item, index }">
15
15
  <el-col
16
16
  :span="['list'].includes(item.component) ? 24 : item.span || 24"
17
17
  :class="{
18
18
  borderItem: !hideBorder,
19
- cur: !hideBorder && curIndex == `${this.uuid}${item.name || item?.options?.items[0]?.name}`
19
+ cur: !hideBorder && curIndex == `${uuid}${item.name || item?.options?.items[0]?.name}`
20
20
  }"
21
21
  v-if="!hideHandle(item)"
22
22
  @click.stop="changeClick(item)">
@@ -27,10 +27,10 @@
27
27
  :formItems="item.value"
28
28
  :form="form[item.name]"
29
29
  class="object-item"
30
- :custom="custom"
30
+ :customComponent="customComponent"
31
31
  :hideBorder="hideBorder"
32
32
  @curClick="emitClick">
33
- <template v-for="c in custom" v-slot:[c.component]="{ itemCur, formCur }">
33
+ <template v-for="c in customComponent" v-slot:[c.component]="{ itemCur, formCur }">
34
34
  <slot :name="c.component" :itemCur="itemCur" :formCur="formCur"></slot>
35
35
  </template>
36
36
  </JsonItem>
@@ -41,39 +41,28 @@
41
41
  <el-form-item>
42
42
  <template #label>
43
43
  {{ item.label }}
44
- <el-button
45
- v-if="hideBorder"
46
- type="primary"
47
- class="add-btn"
48
- plain
49
- size="small"
50
- icon="el-icon-plus"
51
- @click="addListItem(item.value)"
52
- >{{ $t('btn.add') }}</el-button
53
- >
44
+ <el-button v-if="hideBorder" type="primary" class="add-btn" plain size="small" icon="el-icon-plus" @click="addListItem(item.value)"></el-button>
54
45
  </template>
55
- <el-col :span="item.span || 24" v-for="(x, xIndex) in item.value" :key="xIndex">
56
- <div class="list-item" :class="{ borderItem: !hideBorder }">
57
- <JsonItem
58
- v-if="form[item.name]"
59
- :formItems="x"
60
- :custom="custom"
61
- :form="form[item.name][xIndex]"
62
- :hideBorder="hideBorder"
63
- @curClick="emitClick">
64
- <template v-for="c in custom" v-slot:[c.component]="{ itemCur, formCur }">
65
- <slot :name="c.component" :itemCur="itemCur" :formCur="formCur"></slot>
66
- </template>
67
- </JsonItem>
68
- <el-icon
69
- class="remove-btn"
70
- size="14"
71
- v-if="hideBorder && item.value.length > 1"
72
- @click="deleteListItem(item.value, xIndex)"
73
- ><el-icon-delete
74
- /></el-icon>
75
- </div>
76
- </el-col>
46
+ <div class="list-span-bg">
47
+ <el-col :span="!hideBorder ? 24 : item.span || 24" v-for="(x, xIndex) in item.value" :key="xIndex">
48
+ <div v-if="(!hideBorder && xIndex == 0) || hideBorder" class="list-item" :class="{ borderItem: !hideBorder }">
49
+ <JsonItem
50
+ v-if="form[item.name]"
51
+ :formItems="x"
52
+ :customComponent="customComponent"
53
+ :form="form[item.name][xIndex]"
54
+ :hideBorder="hideBorder"
55
+ @curClick="emitClick">
56
+ <template v-for="c in customComponent" v-slot:[c.component]="{ itemCur, formCur }">
57
+ <slot :name="c.component" :itemCur="itemCur" :formCur="formCur"></slot>
58
+ </template>
59
+ </JsonItem>
60
+ <el-icon class="remove-btn" size="14" v-if="hideBorder && item.value.length > 1" @click="deleteListItem(item.value, xIndex)">
61
+ <el-icon-delete />
62
+ </el-icon>
63
+ </div>
64
+ </el-col>
65
+ </div>
77
66
  </el-form-item>
78
67
  </template>
79
68
  <FormItem v-else :item="item" :form="form">
@@ -102,91 +91,92 @@
102
91
  <slot :name="item.component" :itemCur="item" :formCur="form"></slot>
103
92
  </template>
104
93
  </FormItem>
94
+
105
95
  <!-- 工具 -->
106
- <div
107
- v-if="!hideBorder && curIndex == `${this.uuid}${item.name || item?.options?.items[0]?.name}`"
108
- class="tool-list">
109
- <el-icon class="btn" size="14" @click="copyItem(item, index)" title="复制"><el-icon-copy-document /></el-icon>
110
- <el-icon class="btn" size="14" @click="deleteItem(index)" title="删除"><el-icon-delete /></el-icon>
96
+ <div v-if="!hideBorder && curIndex == `${uuid}${item.name || item?.options?.items[0]?.name}`" class="tool-list">
97
+ <el-icon class="btn" size="12" @click="copyItem(item, index)" title="复制"><el-icon-copy-document /></el-icon>
98
+ <el-icon class="btn" size="12" @click="deleteItem(index)" title="删除"><el-icon-delete /></el-icon>
111
99
  </div>
112
100
  </el-col>
113
101
  </template>
114
102
  </draggable>
115
103
  </template>
116
104
 
117
- <script>
118
- import FormItem from '../lwFormMini/FormItem'
105
+ <script setup>
106
+ import { computed, getCurrentInstance } from 'vue'
119
107
  import draggable from 'vuedraggable'
120
- export default {
121
- name: 'JsonItem',
122
- data() {
123
- return {
124
- uuid: this.$tool.getUUID('', 12)
125
- }
126
- },
127
- components: {
128
- FormItem,
129
- draggable
130
- },
131
- props: {
132
- formItems: {
133
- type: Object,
134
- default: []
135
- },
136
- form: {
137
- type: Object,
138
- default: () => {}
139
- },
140
- // 是否是显示边界
141
- hideBorder: { type: Boolean, default: false },
142
- // 自定义组件
143
- custom: { type: Array, default: () => [] }
108
+ import { useStore } from 'vuex'
109
+ import FormItem from '../lwFormMini/FormItem'
110
+ const {
111
+ proxy: { $api, $tool, t, $expression }
112
+ } = getCurrentInstance()
113
+ defineOptions({ name: 'JsonItem' })
114
+ const store = useStore()
115
+
116
+ const props = defineProps({
117
+ formItems: {
118
+ type: Object,
119
+ default: () => []
144
120
  },
145
- computed: {
146
- curIndex() {
147
- return this.$store.state?.curIndex || ''
148
- }
121
+ form: {
122
+ type: Object,
123
+ default: () => ({})
149
124
  },
150
- emits: ['curClick'],
151
- methods: {
152
- //处理动态隐藏
153
- hideHandle(item) {
154
- if (typeof item?.hideHandle === 'string') {
155
- const func = new Function('form', `return ${item?.hideHandle.replace(/\$/g, 'form')}`)
156
- return func(this.form)
157
- } else if (typeof item?.hideHandle === 'boolean') {
158
- return item.hideHandle
159
- }
160
- return false
161
- },
162
- changeClick(item) {
163
- this.$store.state.curIndex = `${this.uuid}${item.name || item?.options.items[0]?.name}`
164
- this.emitClick(item)
165
- },
166
- emitClick(item) {
167
- this.$emit('curClick', item)
168
- },
169
- // 列表删除
170
- deleteListItem(list, index) {
171
- list.splice(index, 1)
172
- },
173
- // 列表新增
174
- addListItem(list) {
175
- let item = list[0]
176
- let x = JSON.parse(JSON.stringify(item))
177
- list.push(x)
178
- },
179
- // 删除
180
- deleteItem(index) {
181
- this.formItems.splice(index, 1)
182
- },
183
- // 复制
184
- copyItem(item, index) {
185
- let x = JSON.parse(JSON.stringify(item))
186
- x.name = `${item.component}-${this.$tool.getUUID('', 2)}`
187
- this.formItems.splice(index + 1, 0, x)
188
- }
125
+ // 是否是显示边界
126
+ hideBorder: { type: Boolean, default: false },
127
+ // 自定义组件
128
+ customComponent: { type: Array, default: () => [] }
129
+ })
130
+
131
+ const emit = defineEmits(['curClick'])
132
+
133
+ const uuid = $tool?.getUUID('', 12) || Date.now().toString(36)
134
+
135
+ // 计算属性
136
+ const curIndex = computed(() => store?.state?.curIndex || '')
137
+
138
+ // 处理动态隐藏
139
+ function hideHandle(item) {
140
+ if (typeof item?.hideHandle === 'string') {
141
+ const func = new Function('form', `return ${item?.hideHandle.replace(/\$/g, 'form')}`)
142
+ return func(props.form)
143
+ } else if (typeof item?.hideHandle === 'boolean') {
144
+ return item.hideHandle
189
145
  }
146
+ return false
147
+ }
148
+
149
+ function changeClick(item) {
150
+ store.state.curIndex = `${uuid}${item.name || item?.options.items[0]?.name}`
151
+ emitClick(item)
152
+ }
153
+
154
+ function emitClick(item) {
155
+ emit('curClick', item)
156
+ }
157
+
158
+ // 列表删除
159
+ function deleteListItem(list, index) {
160
+ list.splice(index, 1)
161
+ }
162
+
163
+ // 列表新增
164
+ function addListItem(list) {
165
+ const item = list[0]
166
+ const x = JSON.parse(JSON.stringify(item))
167
+ list.push(x)
168
+ }
169
+
170
+ // 删除
171
+ function deleteItem(index) {
172
+ props.formItems.splice(index, 1)
173
+ }
174
+
175
+ // 复制
176
+ function copyItem(item, index) {
177
+ const x = JSON.parse(JSON.stringify(item))
178
+ x.name = `${item.component}-${$tool?.getUUID('', 2) || Date.now()}`
179
+ props.formItems.splice(index + 1, 0, x)
190
180
  }
191
181
  </script>
192
182
 
@@ -197,48 +187,64 @@ export default {
197
187
  display: flex;
198
188
  flex-wrap: wrap;
199
189
  // gap: 10px;
200
- padding-bottom: 10px;
190
+ // padding-bottom: 10px;
191
+
201
192
  > div {
202
193
  .title-name {
203
194
  margin-top: 0;
204
195
  }
196
+
205
197
  &:first-child {
206
198
  .title-name {
207
199
  border-top: 0;
208
200
  }
209
201
  }
210
202
  }
203
+
211
204
  &.showBorder {
212
205
  border: 1px dashed var(--el-border-color-light);
213
206
  background-color: var(--color-white);
207
+ .object-item,
208
+ .list-span-bg {
209
+ background-color: var(--el-border-color-extra-light);
210
+ }
211
+ .list-item {
212
+ padding: 0 !important;
213
+ }
214
214
  }
215
215
  }
216
- // :deep(.el-form-item__content){
217
- // margin-left: -5px;
218
- // margin-right: -5px;
219
- // }
216
+
220
217
  .object-item {
221
- // margin: 0 5px;
222
- padding: 15px 10px;
223
218
  background-color: #fff;
224
- // box-shadow: 0 0 3px rgba($color: #000000, $alpha: 0.1);
219
+
220
+ padding: 10px;
225
221
  }
226
222
 
227
223
  :deep(.el-col) {
228
224
  border: 1px dashed transparent;
229
225
  }
230
226
 
227
+ .list-span-bg {
228
+ background-color: var(--el-border-color-extra-light);
229
+ width: 100%;
230
+ padding: 10px 5px 0;
231
+ display: flex;
232
+ flex-wrap: wrap;
233
+ }
234
+
231
235
  .list-item {
232
236
  width: 100%;
233
- padding: 15px 10px;
237
+ padding: 15px 10px 0;
234
238
  background-color: #fff;
235
- // box-shadow: 0 0 3px rgba($color: #000000, $alpha: 0.1);
239
+
240
+ border: 0 !important;
236
241
  margin-bottom: 10px;
237
242
  position: relative;
243
+
238
244
  .remove-btn {
239
245
  position: absolute;
240
- top: 10px;
241
- right: 10px;
246
+ top: 5px;
247
+ right: 5px;
242
248
  color: var(--el-color-primary);
243
249
  cursor: pointer;
244
250
  }
@@ -250,17 +256,21 @@ export default {
250
256
  padding: 10px;
251
257
  cursor: move;
252
258
  position: relative;
259
+ background-color: #fff;
260
+
253
261
  &:hover {
254
262
  border: 1px dashed var(--el-border-color);
255
- background-color: rgba($color: #000000, $alpha: 0.01);
263
+ background-color: var(--color-white-1);
256
264
  }
257
265
 
258
266
  .tool-list {
259
267
  display: none;
260
268
  }
261
269
  }
270
+
262
271
  :deep(.cur) {
263
272
  border: 1px dashed var(--el-color-primary) !important;
273
+
264
274
  .tool-list {
265
275
  position: absolute;
266
276
  bottom: 0;
@@ -273,6 +283,7 @@ export default {
273
283
  display: flex;
274
284
  gap: 10px;
275
285
  padding: 2px 10px;
286
+
276
287
  .btn {
277
288
  cursor: pointer;
278
289
  width: 20px;
@@ -287,22 +298,27 @@ export default {
287
298
  padding: 10px;
288
299
  width: 100%;
289
300
  }
301
+
290
302
  :deep(.el-form-item) {
291
303
  position: relative;
304
+
292
305
  .el-form-item {
293
306
  margin-bottom: 18px;
294
307
  }
295
308
  }
309
+
296
310
  .add-btn {
297
311
  top: 0px;
298
312
  right: 0;
299
313
  z-index: 9;
300
314
  position: absolute;
301
315
  }
316
+
302
317
  :deep(.el-form-item--label-right),
303
318
  :deep(.el-form-item--label-left) {
304
319
  .el-form-item__label {
305
320
  position: relative;
321
+
306
322
  .add-btn {
307
323
  top: 30px;
308
324
  right: 10px;
@@ -312,4 +328,9 @@ export default {
312
328
  }
313
329
  }
314
330
  }
331
+
332
+ .component-title-name {
333
+ position: absolute;
334
+ z-index: 9;
335
+ }
315
336
  </style>