function stripInlineMarkdownMarkers(value = '') { return String(value || '') .replace(/\*\*/g, '') .replace(/`/g, '') .trim() } function resolveLegacyAttachmentAssociationField(text = '', label = '') { const escapedLabel = String(label || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&') const match = String(text || '').match(new RegExp(`${escapedLabel}[::]\\s*([^\\n]+)`, 'u')) return stripInlineMarkdownMarkers(match?.[1] || '') } function renderLegacyAttachmentAssociationField(label = '', value = '', options = {}, context = {}) { const text = String(value || '').trim() if (!text) { return '' } return [ `
`, `${context.escapeHtml(label)}`, `${context.escapeHtml(text)}`, '
' ].join('') } function isNoisyLegacyAssociationText(value = '') { const text = String(value || '').replace(/\s+/g, '').trim() if (!text) { return true } if (!/[\u4e00-\u9fa5A-Za-z]/.test(text)) { return true } if (/^[::;;,,.\-\d]+$/.test(text)) { return true } if (/^[::;;]/.test(text) && /\d{6,}/.test(text)) { return true } return false } function normalizeLegacyAssociationDescription(value = '') { const text = stripInlineMarkdownMarkers(value).replace(/\s+/g, ' ').trim() return isNoisyLegacyAssociationText(text) ? '' : text } export function renderLegacyAttachmentAssociationHtml(content = '', options = {}) { const context = { escapeHtml: options.escapeHtml || ((item) => String(item || '')) } const text = String(content || '') if (!/我已先识别票据,并匹配到最可能的报销单/.test(text)) { return '' } const attachment = resolveLegacyAttachmentAssociationField(text, '本次附件') const summary = resolveLegacyAttachmentAssociationField(text, '识别摘要') const claimNo = resolveLegacyAttachmentAssociationField(text, '推荐关联') const reason = normalizeLegacyAssociationDescription(resolveLegacyAttachmentAssociationField(text, '单据事项')) const basis = resolveLegacyAttachmentAssociationField(text, '匹配依据') return [ '
', '

我已先识别票据,并找到一张可能关联的报销单。请确认是否自动归集:

', '
', '
', '
', '可能关联单据', '待确认', '
', '
', '
', renderLegacyAttachmentAssociationField('推荐单据', claimNo, {}, context), renderLegacyAttachmentAssociationField('本次附件', attachment, {}, context), renderLegacyAttachmentAssociationField('识别摘要', summary, { wide: true, muted: true }, context), renderLegacyAttachmentAssociationField('关联事项', reason, { wide: true }, context), renderLegacyAttachmentAssociationField('匹配依据', basis, { wide: true, muted: true }, context), '
', '
如果这就是要归集的单据,可直接使用下方快捷按钮;不确定时也可以先查看单据。
', '
', '
', '
', '
' ].join('') }