fix: 解决病例回填不显示问题
This commit is contained in:
@@ -482,8 +482,9 @@ function fillDetailForm(row: CaseListItem, fullData: unknown) {
|
||||
resetReviewDetailForm()
|
||||
|
||||
const record = getDetailRecord(fullData)
|
||||
const traditional = getRecord(getFirst(record, ['traditional']))
|
||||
const teaching = getRecord(getFirst(record, ['teaching']))
|
||||
const contentSources = [record, fullData]
|
||||
const traditional = findRecord(['traditional', 'traditional_case', 'traditionalCase'], contentSources) ?? {}
|
||||
const teaching = findRecord(['teaching', 'teaching_case', 'teachingCase'], contentSources) ?? {}
|
||||
const scoringRules = getScoringRules(fullData, record)
|
||||
const examItems = getExamItems(fullData, record)
|
||||
|
||||
@@ -724,6 +725,48 @@ function findArray(keys: string[], sources: unknown[]) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findRecord(keys: string[], sources: unknown[]) {
|
||||
for (const source of sources) {
|
||||
const found = findRecordInSource(source, keys)
|
||||
if (found) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findRecordInSource(value: unknown, keys: string[], depth = 0): Record<string, unknown> | undefined {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value) || depth > 5) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const record = value as Record<string, unknown>
|
||||
for (const key of keys) {
|
||||
const nested = record[key]
|
||||
if (nested && typeof nested === 'object' && !Array.isArray(nested)) {
|
||||
return nested as Record<string, unknown>
|
||||
}
|
||||
}
|
||||
|
||||
const preferredKeys = ['data', 'case', 'case_detail', 'caseDetail', 'case_info', 'caseInfo', 'detail', 'full', 'result', 'record', 'item']
|
||||
for (const key of preferredKeys) {
|
||||
const found = findRecordInSource(record[key], keys, depth + 1)
|
||||
if (found) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
for (const child of Object.values(record)) {
|
||||
const found = findRecordInSource(child, keys, depth + 1)
|
||||
if (found) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findArrayInSource(value: unknown, keys: string[], depth = 0): unknown[] | undefined {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value) || depth > 5) {
|
||||
return undefined
|
||||
|
||||
+60
-4
@@ -1514,8 +1514,9 @@ function fillCaseFormFromImportedPdf(result: ImportCasePdfResult) {
|
||||
|
||||
const record = getImportRecord(result.data)
|
||||
const caseType = normalizeImportCaseType(getImportString(record, ['case_type', 'caseType']), result.caseType)
|
||||
const traditional = getImportRecord(getImportFirst(record, ['traditional']))
|
||||
const teaching = getImportRecord(getImportFirst(record, ['teaching']))
|
||||
const contentSources = [record, result.data, result.raw]
|
||||
const traditional = findImportRecord(['traditional', 'traditional_case', 'traditionalCase'], contentSources) ?? {}
|
||||
const teaching = findImportRecord(['teaching', 'teaching_case', 'teachingCase'], contentSources) ?? {}
|
||||
const scoringRules = getImportScoringRules(result.raw, result.data, record)
|
||||
const examItems = getImportExamItems(result.raw, result.data, record)
|
||||
|
||||
@@ -1565,8 +1566,9 @@ function fillDetailForm(row: CaseListItem, fullData: unknown) {
|
||||
resetDraftForm(detailForm)
|
||||
|
||||
const record = getDetailRecord(fullData)
|
||||
const traditional = getImportRecord(getImportFirst(record, ['traditional']))
|
||||
const teaching = getImportRecord(getImportFirst(record, ['teaching']))
|
||||
const contentSources = [record, fullData]
|
||||
const traditional = findImportRecord(['traditional', 'traditional_case', 'traditionalCase'], contentSources) ?? {}
|
||||
const teaching = findImportRecord(['teaching', 'teaching_case', 'teachingCase'], contentSources) ?? {}
|
||||
const scoringRules = getImportScoringRules(fullData, record)
|
||||
const examItems = getImportExamItems(fullData, record)
|
||||
|
||||
@@ -1740,6 +1742,60 @@ function findImportArray(keys: string[], sources: unknown[]) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findImportRecord(keys: string[], sources: unknown[]) {
|
||||
for (const source of sources) {
|
||||
const found = findImportRecordInSource(source, keys)
|
||||
if (found) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findImportRecordInSource(value: unknown, keys: string[], depth = 0): Record<string, unknown> | undefined {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value) || depth > 5) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const record = value as Record<string, unknown>
|
||||
for (const key of keys) {
|
||||
const nested = record[key]
|
||||
if (nested && typeof nested === 'object' && !Array.isArray(nested)) {
|
||||
return nested as Record<string, unknown>
|
||||
}
|
||||
}
|
||||
|
||||
const preferredKeys = [
|
||||
'data',
|
||||
'case',
|
||||
'case_detail',
|
||||
'caseDetail',
|
||||
'case_info',
|
||||
'caseInfo',
|
||||
'detail',
|
||||
'full',
|
||||
'result',
|
||||
'record',
|
||||
'item'
|
||||
]
|
||||
for (const key of preferredKeys) {
|
||||
const found = findImportRecordInSource(record[key], keys, depth + 1)
|
||||
if (found) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
for (const child of Object.values(record)) {
|
||||
const found = findImportRecordInSource(child, keys, depth + 1)
|
||||
if (found) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function findImportArrayInSource(value: unknown, keys: string[], depth = 0): unknown[] | undefined {
|
||||
if (!value || typeof value !== 'object' || depth > 5) {
|
||||
return undefined
|
||||
|
||||
Reference in New Issue
Block a user