From 5366270ad635d2685659cf86f80cc1c2c5c768d3 Mon Sep 17 00:00:00 2001 From: wren <“porlong@qq.com”> Date: Wed, 6 May 2026 11:15:52 +0800 Subject: [PATCH] fix: improve review field location fallback --- .../rightColumn/ReviewPointDetailCard.tsx | 73 ++++++++++++++++--- 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/app/components/reviews/rightColumn/ReviewPointDetailCard.tsx b/app/components/reviews/rightColumn/ReviewPointDetailCard.tsx index 135e117..cab0926 100644 --- a/app/components/reviews/rightColumn/ReviewPointDetailCard.tsx +++ b/app/components/reviews/rightColumn/ReviewPointDetailCard.tsx @@ -450,27 +450,60 @@ function RenderGenericRule({ : Array.isArray((config as any).fields) ? (config as any).fields.map((field: unknown) => String(field)) : []; - const reason = [config.reason, detail.reason, reviewPoint.failMessage, reviewPoint.passMessage] - .find((item) => typeof item === 'string' && item.trim()) as string | undefined; const passed = typeof rule.res === 'boolean' ? rule.res : reviewPoint.result === true; + const reasonCandidates = passed + ? [config.reason, detail.reason, reviewPoint.passMessage] + : [config.reason, detail.reason, reviewPoint.failMessage, reviewPoint.suggestion]; + const reason = reasonCandidates.find((item) => typeof item === 'string' && item.trim()) as string | undefined; const checkType = typeof config.check_type === 'string' ? config.check_type : ''; const primitiveType = typeof config.primitive_type === 'string' ? config.primitive_type : ''; const badgeText = checkType || primitiveType || '规则检查'; - const jumpToField = (fieldName: string) => { + const getFieldLocatorState = (fieldName: string) => { const fieldData = reviewPoint.content?.[fieldName]; const page = fieldData?.page || reviewPoint.contentPage?.[fieldName]; const normalizedPage = page ? Number(page) : undefined; - if (normalizedPage && Number.isFinite(normalizedPage)) { + const hasPage = !!(normalizedPage && Number.isFinite(normalizedPage)); + const rawValue = fieldData?.value; + const normalizedValue = + typeof rawValue === 'string' + ? rawValue.trim() + : rawValue == null + ? '' + : String(rawValue); + + return { + fieldData, + normalizedPage: hasPage ? normalizedPage : undefined, + normalizedValue, + canLocate: hasPage || normalizedValue.length > 0, + }; + }; + + const jumpToField = (fieldName: string) => { + const { fieldData, normalizedPage, normalizedValue } = getFieldLocatorState(fieldName); + if (normalizedPage) { onReviewPointSelect( reviewPoint.id, normalizedPage, fieldData?.char_positions, - typeof fieldData?.value === 'string' ? fieldData.value : undefined, + normalizedValue || undefined, ); return; } - toastService.info(`${fieldName} 当前没有可定位页码`); + + if (normalizedValue) { + onReviewPointSelect( + reviewPoint.id, + undefined, + fieldData?.char_positions, + normalizedValue, + ); + toastService.info(`${fieldName} 当前没有页码,已改为按文本定位`); + return; + } + + toastService.info(`${fieldName} 当前既没有页码,也没有可定位文本`); }; return ( @@ -492,7 +525,7 @@ function RenderGenericRule({ {fieldNames.length > 0 && (