Commit bcf36208 by 李伟康

fix(form): 解决多选字段显示标签解析问题

- 添加 splitMultipleSelectDisplayLabel 函数处理双 key 字段的显示标签解析
- 实现 zipMultipleSelectIdsWithDisplayLabel 函数将 ID 数组与显示名称关联
- 修复 resolveMultipleSelectEngineValueFromAppField 中对象类型值的处理逻辑
- 移除多余的数组元素名称赋值操作,避免字段值被错误覆盖
- 优化多选字段的存储类型处理机制
1 parent 42b6286e
...@@ -435,6 +435,26 @@ function extractMultipleSelectIdsAndLabels(raw, field = {}) { ...@@ -435,6 +435,26 @@ function extractMultipleSelectIdsAndLabels(raw, field = {}) {
return { ids, displayLabel: names.filter(part => part != null && part !== '').join('/') } return { ids, displayLabel: names.filter(part => part != null && part !== '').join('/') }
} }
/** App jsonContent 双 key:field[key] 为 id 数组时,用 value 的 / 展示串还原 { id, name } */
function splitMultipleSelectDisplayLabel(value) {
if (typeof value !== 'string' || value === '') {
return []
}
const trimmed = value.trim()
if (trimmed.startsWith('[')) {
return []
}
return trimmed.split('/').map(part => part.trim()).filter(part => part !== '')
}
function zipMultipleSelectIdsWithDisplayLabel(ids = [], displayLabel = '') {
const names = splitMultipleSelectDisplayLabel(displayLabel)
return ids.map((id, index) => ({
id: String(id),
name: names[index] != null && names[index] !== '' ? names[index] : String(id)
}))
}
function resolveMultipleSelectEngineValueFromAppField(field = {}) { function resolveMultipleSelectEngineValueFromAppField(field = {}) {
const key = field.key const key = field.key
const meta = key != null ? field[key] : undefined const meta = key != null ? field[key] : undefined
...@@ -443,6 +463,13 @@ function resolveMultipleSelectEngineValueFromAppField(field = {}) { ...@@ -443,6 +463,13 @@ function resolveMultipleSelectEngineValueFromAppField(field = {}) {
if (!meta.length) { if (!meta.length) {
return [] return []
} }
if (meta.some(item => typeof item === 'object')) {
return coerceMultipleSelectValue(meta)
}
const displayNames = splitMultipleSelectDisplayLabel(field.value)
if (displayNames.length) {
return zipMultipleSelectIdsWithDisplayLabel(meta, field.value)
}
return meta.map(id => String(id)) return meta.map(id => String(id))
} }
...@@ -627,10 +654,6 @@ function resolveStorageFieldValue(field = {}, fieldValue) { ...@@ -627,10 +654,6 @@ function resolveStorageFieldValue(field = {}, fieldValue) {
if (value === undefined || value == null || (Array.isArray(value) && !value.length)) { if (value === undefined || value == null || (Array.isArray(value) && !value.length)) {
return { value: undefined, storageType: 'JSON' } return { value: undefined, storageType: 'JSON' }
} }
const names = field.value.split('/')
value.forEach((item,index) => {
item.name = names[index]
})
return { value, storageType: 'JSON' } return { value, storageType: 'JSON' }
} }
if (field.type === 'carBrandSelect') { if (field.type === 'carBrandSelect') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!