二维表头

This commit is contained in:
zhangheng
2026-02-08 18:17:29 +08:00
parent cd2b745336
commit 7a7df06d66
6 changed files with 510 additions and 26 deletions

View File

@@ -330,6 +330,21 @@ const tableFormVerify = (type) => {
filedData.splice(item.sortNum || 999, 0, item)
})
// 先进行hasChildren一致性检查
filedData.forEach(currentItem => {
if (currentItem.hasChildren === 'Y') {
// 检查是否存在子字段parentFieldCode等于当前字段的fieldCode
const hasChildFields = filedData.some(childItem =>
childItem.parentFieldCode === currentItem.fieldCode
)
// 如果没有子字段则将hasChildren设为'N'
if (!hasChildFields) {
currentItem.hasChildren = 'N'
}
}
})
for (const i in filedData) {
const index = Number(i)
const item = filedData[index]
@@ -337,12 +352,31 @@ const tableFormVerify = (type) => {
let messageText = ''
let tabKey = 'mysql'
if (!item.fieldCode || !item.fieldName) {
// 子字段不能再包含子字段
if (item.isSubField && item.hasChildren === 'Y') {
debugger
messageText = `<div style="line-height:24px">
<div>${!item.fieldCode ? '字段编码' : '字段名称'}必须填写</div>
<div>子字段不能包含子字段</div>
<div>序号:${index + 1}</div>
</div>`
}
// 当不包含子字段时,字段编码和字段名称必须填写
else if (item.hasChildren !== 'Y') {
if (!item.fieldCode || !item.fieldName) {
messageText = `<div style="line-height:24px">
<div>${!item.fieldCode ? '字段编码' : '字段名称'}必须填写</div>
<div>序号:${index + 1}</div>
</div>`
}
} else {
// 包含子字段时,字段名称必须填写
if (!item.fieldName) {
messageText = `<div style="line-height:24px">
<div>字段名称必须填写</div>
<div>序号:${index + 1}</div>
</div>`
}
}
if (fieldCodeArr.includes(item.fieldCode)) {
messageText = `<div style="line-height:24px">
<div>
@@ -353,15 +387,18 @@ const tableFormVerify = (type) => {
</div>`
}
fieldCodeArr.push(item.fieldCode)
if (!/(^[a-zA-Z]{2}(_?[a-zA-Z0-9])*_?$)/.test(item.fieldCode)) {
messageText = `<div style="line-height:24px">
<div>
<span>字段编码不符合规范</span>
<span style="color:red">${item.fieldCode}</span>
</div>
<div>命名规则:只能由字母、数字、下划线组成;必须以字母开头;不能以单个字母加下滑线开头</div>
<div>序号:${index + 1}</div>
</div>`
// 当不包含子字段时才验证字段编码格式
if (item.hasChildren !== 'Y' && item.fieldCode) {
if (!/(^[a-zA-Z]{2}(_?[a-zA-Z0-9])*_?$)/.test(item.fieldCode)) {
messageText = `<div style="line-height:24px">
<div>
<span>字段编码不符合规范</span>
<span style="color:red">${item.fieldCode}</span>
</div>
<div>命名规则:只能由字母、数字、下划线组成;必须以字母开头;不能以单个字母加下滑线开头</div>
<div>序号:${index + 1}</div>
</div>`
}
}
if (messageText) {
@@ -379,6 +416,20 @@ const tableFormVerify = (type) => {
})
if (key == 'fieldList') {
itemObj.labelI18n = formattingLengStr(itemObj.labelI18n, itemObj.fieldName)
// 为子字段添加父字段编码信息
if (item.isSubField && item.parentFieldId) {
// 查找父字段的编码
const parentField = filedData.find(field => field._X_ROW_KEY === item.parentFieldId)
if (parentField && parentField.fieldCode) {
itemObj.parentFieldCode = parentField.fieldCode
}
}
// 为父字段添加是否包含子字段的标识
if (item.hasChildren === 'Y') {
itemObj.hasChildren = 'Y'
} else {
itemObj.hasChildren = 'N'
}
}
if (type == 'edit' && item[`${key}_id`]) itemObj['id'] = item[`${key}_id`]
infoData[key].push(itemObj)