Enhance Step4Report component with individual selection reason parsing and display

- Introduced a new function to parse individual selection reasons from interview text, accommodating multiple formats for better accuracy.
- Updated the interview object to include a selection reason property, ensuring each interview displays the corresponding rationale.
- Enhanced the InterviewDisplay component to render selection reasons with improved styling for better visibility and user experience.
This commit is contained in:
666ghj 2025-12-16 16:09:30 +08:00
parent 1659665a0b
commit c811f454ab

View file

@ -661,6 +661,72 @@ const parseInterview = (text) => {
result.selectionReason = reasonMatch[1].trim()
}
//
const parseIndividualReasons = (reasonText) => {
const reasons = {}
if (!reasonText) return reasons
const lines = reasonText.split(/\n+/)
let currentName = null
let currentReason = []
for (const line of lines) {
let headerMatch = null
let name = null
let reasonStart = null
// 1: . **index=X**
// : 1. **_345index=1**...
headerMatch = line.match(/^\d+\.\s*\*\*([^*(]+)(?:[(]index\s*=?\s*\d+[)])?\*\*[:]\s*(.*)/)
if (headerMatch) {
name = headerMatch[1].trim()
reasonStart = headerMatch[2]
}
// 2: - index X
// : - _601index 0...
if (!headerMatch) {
headerMatch = line.match(/^-\s*选择([^(]+)(?:[(]index\s*=?\s*\d+[)])?[:]\s*(.*)/)
if (headerMatch) {
name = headerMatch[1].trim()
reasonStart = headerMatch[2]
}
}
// 3: - **index X**
// : - **_601index 0**...
if (!headerMatch) {
headerMatch = line.match(/^-\s*\*\*([^*(]+)(?:[(]index\s*=?\s*\d+[)])?\*\*[:]\s*(.*)/)
if (headerMatch) {
name = headerMatch[1].trim()
reasonStart = headerMatch[2]
}
}
if (name) {
//
if (currentName && currentReason.length > 0) {
reasons[currentName] = currentReason.join(' ').trim()
}
//
currentName = name
currentReason = reasonStart ? [reasonStart.trim()] : []
} else if (currentName && line.trim() && !line.match(/^未选|^综上|^最终选择/)) {
//
currentReason.push(line.trim())
}
}
//
if (currentName && currentReason.length > 0) {
reasons[currentName] = currentReason.join(' ').trim()
}
return reasons
}
const individualReasons = parseIndividualReasons(result.selectionReason)
// 访
const interviewBlocks = text.split(/#### 采访 #\d+:/).slice(1)
@ -671,6 +737,7 @@ const parseInterview = (text) => {
name: '',
role: '',
bio: '',
selectionReason: '',
questions: [],
twitterAnswer: '',
redditAnswer: '',
@ -686,6 +753,8 @@ const parseInterview = (text) => {
if (nameRoleMatch) {
interview.name = nameRoleMatch[1].trim()
interview.role = nameRoleMatch[2].trim()
//
interview.selectionReason = individualReasons[interview.name] || ''
}
//
@ -1079,6 +1148,12 @@ const InterviewDisplay = {
])
]),
// Selection Reason -
props.result.interviews[activeIndex.value]?.selectionReason && h('div', { class: 'selection-reason' }, [
h('div', { class: 'reason-label' }, '选择理由'),
h('div', { class: 'reason-content' }, props.result.interviews[activeIndex.value].selectionReason)
]),
// Q&A Conversation Thread -
h('div', { class: 'qa-thread' },
(props.result.interviews[activeIndex.value]?.questions?.length > 0
@ -3368,6 +3443,30 @@ watch(() => props.reportId, (newId) => {
overflow: hidden;
}
/* Selection Reason - 选择理由 */
:deep(.interview-display .selection-reason) {
background: #F8FAFC;
border: 1px solid #E2E8F0;
border-radius: 8px;
padding: 12px 14px;
margin-bottom: 16px;
}
:deep(.interview-display .reason-label) {
font-size: 11px;
font-weight: 600;
color: #64748B;
text-transform: uppercase;
letter-spacing: 0.03em;
margin-bottom: 6px;
}
:deep(.interview-display .reason-content) {
font-size: 12px;
color: #475569;
line-height: 1.6;
}
/* Q&A Thread - Clean list */
:deep(.interview-display .qa-thread) {
display: flex;