subform-child-validation-value.js
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/** subform 单元格校验取值(App 双 key / carBrand 优先 meta) */
import { resolveCarBrandValueForValidation } from './car-brand-value.js'
import {
getFieldTypeStrategy,
resolveSubformChildValidationValue
} from './field-types/registry.js'
import {
hasPlanImportDateMarker
} from './plan-import-date-value.js'
function hasMeaningfulRowValue(value) {
return value !== undefined && value !== null && value !== ''
}
export function resolveSubformChildValue(child, row, rowField) {
if (child?.type === 'carBrandSelect') {
return resolveCarBrandValueForValidation(rowField, child.key, row?.[child.key])
}
if (getFieldTypeStrategy(child?.type)?.resolveValidationValue) {
return resolveSubformChildValidationValue(child, rowField, row?.[child.key])
}
const isDateField = child?.type === 'date' || child?.type === 'datetime'
if (isDateField) {
if (rowField && hasPlanImportDateMarker(rowField.value)) {
return rowField.value
}
const rowMapVal = row?.[child.key]
if (hasPlanImportDateMarker(rowMapVal)) {
return rowMapVal
}
const metaVal = rowField?.[child.key]
if (hasPlanImportDateMarker(metaVal)) {
return metaVal
}
}
if (rowField && hasMeaningfulRowValue(rowField.value)) {
return rowField.value
}
return row?.[child.key]
}