@longhongguo/form-create-ant-design-vue 3.2.45 → 3.2.47

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": "@longhongguo/form-create-ant-design-vue",
3
- "version": "3.2.45",
3
+ "version": "3.2.47",
4
4
  "description": "AntDesignVue版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。",
5
5
  "main": "./dist/form-create.min.js",
6
6
  "module": "./dist/form-create.esm.js",
@@ -9,7 +9,12 @@
9
9
  :style="style"
10
10
  :tabindex="disabled ? -1 : 0"
11
11
  >
12
- <div class="fc-cus-select-selector">
12
+ <div
13
+ class="fc-cus-select-selector"
14
+ :class="{
15
+ 'fc-cus-select-selector-borderless': !bordered
16
+ }"
17
+ >
13
18
  <span
14
19
  v-if="displayValue"
15
20
  class="fc-cus-select-selection-item"
@@ -72,7 +77,12 @@
72
77
  :style="style"
73
78
  :tabindex="disabled ? -1 : 0"
74
79
  >
75
- <div class="fc-cus-select-selector">
80
+ <div
81
+ class="fc-cus-select-selector"
82
+ :class="{
83
+ 'fc-cus-select-selector-borderless': !bordered
84
+ }"
85
+ >
76
86
  <div class="fc-cus-select-selection-overflow">
77
87
  <!-- 显示的 tags -->
78
88
  <div
@@ -176,10 +186,12 @@ import { defineComponent } from 'vue'
176
186
  export default defineComponent({
177
187
  name: 'CusSelect',
178
188
  props: {
179
- // 当前值:单个时为字符串/数字,多个时为数组(支持 v-model)
189
+ // 当前值:统一使用对象数组格式(支持 v-model)
190
+ // 单选时:[{value: '1001', label: '门店1'}] 或 []
191
+ // 多选时:[{value: '1001', label: '门店1'}, {value: '1002', label: '门店2'}] 或 []
180
192
  modelValue: {
181
- type: [String, Number, Array],
182
- default: null
193
+ type: Array,
194
+ default: () => []
183
195
  },
184
196
  // 选项列表
185
197
  options: {
@@ -225,50 +237,137 @@ export default defineComponent({
225
237
  allowClear: {
226
238
  type: Boolean,
227
239
  default: false
240
+ },
241
+ // 是否有边框
242
+ bordered: {
243
+ type: Boolean,
244
+ default: true
228
245
  }
229
246
  },
230
247
  emits: ['update:modelValue', 'change'],
231
248
  computed: {
232
- // 统一处理值(支持 v-model
249
+ // 统一处理值(支持 v-model),确保始终是对象数组格式
233
250
  currentValue: {
234
251
  get() {
235
- return this.modelValue
252
+ // 确保返回对象数组格式
253
+ if (!Array.isArray(this.modelValue)) {
254
+ // 如果是 null、undefined 或空字符串,返回空数组
255
+ if (
256
+ this.modelValue === null ||
257
+ this.modelValue === undefined ||
258
+ this.modelValue === ''
259
+ ) {
260
+ return []
261
+ }
262
+ // 如果是单个对象,转换为数组
263
+ if (typeof this.modelValue === 'object') {
264
+ return [this.modelValue]
265
+ }
266
+ // 如果是单个值,转换为对象数组格式
267
+ return [
268
+ { value: this.modelValue, label: this.getLabel(this.modelValue) }
269
+ ]
270
+ }
271
+ // 确保数组中的每个元素都是对象格式
272
+ return this.modelValue.map((item) => {
273
+ if (
274
+ typeof item === 'object' &&
275
+ item !== null &&
276
+ (item.value !== undefined || item[this.valueKey] !== undefined)
277
+ ) {
278
+ // 已经是对象格式
279
+ return item
280
+ }
281
+ // 如果是单个值,转换为对象格式
282
+ return {
283
+ [this.valueKey]: item,
284
+ [this.labelKey]: this.getLabel(item)
285
+ }
286
+ })
236
287
  },
237
288
  set(val) {
289
+ // 确保设置的值是对象数组格式
290
+ let arrayValue = []
291
+ if (val !== null && val !== undefined) {
292
+ if (Array.isArray(val)) {
293
+ // 确保数组中的每个元素都是对象格式
294
+ arrayValue = val.map((item) => {
295
+ if (
296
+ typeof item === 'object' &&
297
+ item !== null &&
298
+ (item.value !== undefined || item[this.valueKey] !== undefined)
299
+ ) {
300
+ return item
301
+ }
302
+ // 单个值转换为对象格式
303
+ return {
304
+ [this.valueKey]: item,
305
+ [this.labelKey]: this.getLabel(item)
306
+ }
307
+ })
308
+ } else if (typeof val === 'object' && val !== null) {
309
+ // 单个对象转换为数组
310
+ arrayValue = [val]
311
+ } else {
312
+ // 单个值转换为对象数组格式
313
+ arrayValue = [
314
+ { [this.valueKey]: val, [this.labelKey]: this.getLabel(val) }
315
+ ]
316
+ }
317
+ }
238
318
  // 触发 update:modelValue 事件以支持 v-model
239
- this.$emit('update:modelValue', val)
240
- this.$emit('change', val)
319
+ this.$emit('update:modelValue', arrayValue)
320
+ this.$emit('change', arrayValue)
241
321
  }
242
322
  },
243
- // 是否有值
323
+ // 是否有值(统一判断数组长度)
244
324
  hasValue() {
245
325
  const val = this.currentValue
246
- if (this.multiple) {
247
- return Array.isArray(val) && val.length > 0
248
- } else {
249
- return val !== null && val !== undefined && val !== ''
250
- }
326
+ return Array.isArray(val) && val.length > 0
251
327
  },
252
- // 单个模式:显示的值
328
+ // 单个模式:显示的值对象(从数组中取第一个)
253
329
  displayValue() {
254
330
  if (!this.hasValue) return null
255
- return this.currentValue
331
+ return this.currentValue[0]
256
332
  },
257
333
  // 单个模式:显示的标签
258
334
  displayLabel() {
259
335
  if (!this.displayValue) return ''
260
- return this.getLabel(this.displayValue)
336
+ const item = this.displayValue
337
+ // 如果是对象格式,直接取 label
338
+ if (typeof item === 'object' && item !== null) {
339
+ return (
340
+ item[this.labelKey] ||
341
+ item.label ||
342
+ String(item[this.valueKey] || item.value || '')
343
+ )
344
+ }
345
+ // 如果不是对象,使用 getLabel 方法查找
346
+ return this.getLabel(item)
261
347
  },
262
- // 多个模式:所有选中的项(包含 label 的对象数组)
348
+ // 多个模式:所有选中的项(直接使用对象数组)
263
349
  allSelectedItems() {
264
350
  const val = this.currentValue
265
- if (!this.multiple || !Array.isArray(val) || val.length === 0) {
351
+ if (!Array.isArray(val) || val.length === 0) {
266
352
  return []
267
353
  }
268
- return val.map((v) => ({
269
- value: v,
270
- label: this.getLabel(v)
271
- }))
354
+ // 直接返回对象数组,确保格式统一
355
+ return val.map((item) => {
356
+ if (typeof item === 'object' && item !== null) {
357
+ return {
358
+ value: item[this.valueKey] || item.value,
359
+ label:
360
+ item[this.labelKey] ||
361
+ item.label ||
362
+ String(item[this.valueKey] || item.value || '')
363
+ }
364
+ }
365
+ // 如果不是对象,转换为对象格式
366
+ return {
367
+ value: item,
368
+ label: this.getLabel(item)
369
+ }
370
+ })
272
371
  },
273
372
  // 多个模式:显示的项(根据 maxTagCount 限制)
274
373
  displayItems() {
@@ -311,13 +410,20 @@ export default defineComponent({
311
410
  // 如果找不到对应的 option,直接显示 value
312
411
  return String(val)
313
412
  },
314
- // 删除单个项(多选模式)
413
+ // 删除单个项
315
414
  removeItem(itemValue, event) {
316
415
  if (this.disabled) return
317
416
  event.stopPropagation()
318
417
  const val = this.currentValue
319
- if (this.multiple && Array.isArray(val)) {
320
- const newValue = val.filter((v) => v !== itemValue)
418
+ if (Array.isArray(val)) {
419
+ // 根据 value 来过滤,支持对象数组格式
420
+ const newValue = val.filter((item) => {
421
+ if (typeof item === 'object' && item !== null) {
422
+ const currentItemValue = item[this.valueKey] || item.value
423
+ return currentItemValue !== itemValue
424
+ }
425
+ return item !== itemValue
426
+ })
321
427
  this.currentValue = newValue
322
428
  }
323
429
  },
@@ -325,11 +431,8 @@ export default defineComponent({
325
431
  clearValue(event) {
326
432
  if (this.disabled) return
327
433
  event.stopPropagation()
328
- if (this.multiple) {
329
- this.currentValue = []
330
- } else {
331
- this.currentValue = null
332
- }
434
+ // 统一设置为空数组
435
+ this.currentValue = []
333
436
  }
334
437
  }
335
438
  })