同步:完善质量分析工作台并更新主题字体
同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
This commit is contained in:
+70
-7
@@ -1,10 +1,10 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { sanitizeAnalysisDisplayText } from './analysisDisplayText';
|
||||
import { analysisEvidenceParts } from './analysisEvidenceRefs';
|
||||
|
||||
function inlineMarkdown(value: string, keyPrefix = 'inline', evidenceLabels?: Record<string, string>, evidencePrefix = ''): ReactNode[] {
|
||||
const references = (part: string, key: string): ReactNode => !evidenceLabels ? part : part.split(/(\[?Q[A-F0-9]{8}\]?)/g).map((token, index) => {
|
||||
const ref = token.replace(/^\[|\]$/g, '');
|
||||
return evidenceLabels[ref] ? <a className="analysis-evidence-ref" key={`${key}-${index}`} href={`#${evidencePrefix}${ref}`} title={ref}>{evidenceLabels[ref]}</a> : token;
|
||||
const references = (part: string, key: string): ReactNode => !evidenceLabels ? part : analysisEvidenceParts(part).map(({ text, ref }, index) => {
|
||||
return ref && Object.hasOwn(evidenceLabels, ref) ? <a className="analysis-evidence-ref" key={`${key}-${index}`} href={`#${evidencePrefix}${ref}`} title={ref}>{evidenceLabels[ref]}</a> : text;
|
||||
});
|
||||
return value.split(/(\*\*.+?\*\*|`[^`]+`)/g).map((part, index) => {
|
||||
if (part.startsWith('**') && part.endsWith('**') && part.length >= 4) {
|
||||
@@ -36,12 +36,64 @@ function isBlockStart(lines: string[], index: number): boolean {
|
||||
|| isTableStart(lines, index);
|
||||
}
|
||||
|
||||
/** Break prose at its own punctuation; never split a number, code or parenthesis. */
|
||||
function readingSentences(value: string, boundaries = '。!?;'): string[] {
|
||||
const parts: string[] = [];
|
||||
let start = 0, depth = 0, code = false, bold = false;
|
||||
for (let index = 0; index < value.length; index += 1) {
|
||||
const char = value[index];
|
||||
if (char === '`') code = !code;
|
||||
if (code) continue;
|
||||
if (value.slice(index, index + 2) === '**') { bold = !bold; index += 1; continue; }
|
||||
if (bold) continue;
|
||||
if ('(([【'.includes(char)) depth += 1;
|
||||
if ('))]】'.includes(char)) depth = Math.max(0, depth - 1);
|
||||
const nextFinding = boundaries.includes(';') && char === ',' && value.slice(index + 1).trimStart().startsWith('**') && index - start >= 35;
|
||||
if (!depth && (boundaries.includes(char) || nextFinding)) { parts.push(value.slice(start, index + 1).trim()); start = index + 1; }
|
||||
}
|
||||
if (value.slice(start).trim()) parts.push(value.slice(start).trim());
|
||||
return parts.filter(Boolean);
|
||||
}
|
||||
|
||||
/** Renders the small Markdown subset used by analysis answers with React text nodes only. */
|
||||
export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix }: { content: string; className?: string; evidenceLabels?: Record<string, string>; evidencePrefix?: string }) {
|
||||
export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix, layout }: { content: string; className?: string; evidenceLabels?: Record<string, string>; evidencePrefix?: string; layout?: 'conclusions' | 'sections' }) {
|
||||
const inline = (value: string, key: string) => inlineMarkdown(value, key, evidenceLabels, evidencePrefix);
|
||||
const lines = sanitizeAnalysisDisplayText(content).replaceAll('\r\n', '\n').replaceAll('\r', '\n').split('\n');
|
||||
const blocks: ReactNode[] = [];
|
||||
let index = 0;
|
||||
let leadPending = layout === 'conclusions';
|
||||
let tableNote = '';
|
||||
const note = (value: string) => <p className="analysis-conclusion-context" key={`context-${blocks.length}`}>{inline(value, `context-${blocks.length}`)}</p>;
|
||||
const renderReadingParagraph = (value: string) => {
|
||||
let body = value;
|
||||
let followsLead = false;
|
||||
// Some saved, checked answers use a bold paragraph as a section heading.
|
||||
// Promote only explicit heading syntax, never infer a business conclusion.
|
||||
const title = body.match(/^\*\*([^*\n]{1,45})\*\*\s*(?:([((][\s\S]*[))])\s*[::]?\s*$|[::]\s*([\s\S]*)$|$)/);
|
||||
if (title && /[\p{L}]/u.test(title[1])) {
|
||||
blocks.push(<h3 key={`heading-${blocks.length}`}>{inline(title[1], `heading-${blocks.length}`)}</h3>);
|
||||
if (title[2]) {
|
||||
let next = index;
|
||||
while (next < lines.length && !lines[next].trim()) next += 1;
|
||||
if (isTableStart(lines, next)) tableNote = title[2];
|
||||
else blocks.push(note(title[2]));
|
||||
}
|
||||
body = title[3] || '';
|
||||
}
|
||||
if (!body.trim()) return;
|
||||
if (leadPending) {
|
||||
const sentences = readingSentences(body, '。!?');
|
||||
blocks.push(<p className="analysis-conclusion-lead" key={`lead-${blocks.length}`}>{inline(sentences[0], `lead-${blocks.length}`)}</p>);
|
||||
body = sentences.slice(1).join('');
|
||||
leadPending = false;
|
||||
followsLead = true;
|
||||
}
|
||||
if (!body.trim()) return;
|
||||
const sentences = readingSentences(body);
|
||||
if (sentences.length > 1 && (followsLead || body.length > 85)) {
|
||||
blocks.push(<ul className="analysis-conclusion-points" key={`points-${blocks.length}`}>{sentences.map((item, itemIndex) => <li key={itemIndex}>{inline(item, `point-${blocks.length}-${itemIndex}`)}</li>)}</ul>);
|
||||
} else blocks.push(<p key={`paragraph-${blocks.length}`}>{inline(body, `paragraph-${blocks.length}`)}</p>);
|
||||
};
|
||||
|
||||
while (index < lines.length) {
|
||||
const line = lines[index];
|
||||
@@ -49,6 +101,7 @@ export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix
|
||||
|
||||
const fence = line.match(/^\s*```([^`]*)$/);
|
||||
if (fence) {
|
||||
leadPending = false;
|
||||
const code: string[] = [];
|
||||
index += 1;
|
||||
while (index < lines.length && !/^\s*```\s*$/.test(lines[index])) code.push(lines[index++]);
|
||||
@@ -73,19 +126,23 @@ export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix
|
||||
}
|
||||
|
||||
if (isTableStart(lines, index)) {
|
||||
leadPending = false;
|
||||
const headers = tableCells(lines[index]);
|
||||
const hasIndex = headers[0]?.replace(/[*`]/g, '').trim() === '序号';
|
||||
index += 2;
|
||||
const body: string[][] = [];
|
||||
while (index < lines.length && lines[index].trim() && lines[index].includes('|')) body.push(tableCells(lines[index++]));
|
||||
blocks.push(<div className="ai-markdown-table-wrap" key={`table-${blocks.length}`}><table>
|
||||
<thead><tr><th className="ai-markdown-index">序号</th>{headers.map((cell, cellIndex) => <th key={cellIndex}>{inline(cell, `th-${cellIndex}`)}</th>)}</tr></thead>
|
||||
<tbody>{body.map((row, rowIndex) => <tr key={rowIndex}><td className="ai-markdown-index">{rowIndex + 1}</td>{headers.map((_, cellIndex) => <td key={cellIndex}>{inline(row[cellIndex] || '', `td-${rowIndex}-${cellIndex}`)}</td>)}</tr>)}</tbody>
|
||||
<thead><tr>{!hasIndex && <th className="ai-markdown-index">序号</th>}{headers.map((cell, cellIndex) => <th key={cellIndex} className={hasIndex && cellIndex === 0 ? 'ai-markdown-index' : undefined}>{inline(cell, `th-${cellIndex}`)}</th>)}</tr></thead>
|
||||
<tbody>{body.map((row, rowIndex) => <tr key={rowIndex}>{!hasIndex && <td className="ai-markdown-index">{rowIndex + 1}</td>}{headers.map((_, cellIndex) => <td key={cellIndex} className={hasIndex && cellIndex === 0 ? 'ai-markdown-index' : undefined}>{inline(row[cellIndex] || '', `td-${rowIndex}-${cellIndex}`)}</td>)}</tr>)}</tbody>
|
||||
</table></div>);
|
||||
if (tableNote) { blocks.push(note(tableNote)); tableNote = ''; }
|
||||
continue;
|
||||
}
|
||||
|
||||
const listItem = line.match(/^\s*(?:([-*+])\s+|(\d+)[.)]\s+)(.*)$/);
|
||||
if (listItem) {
|
||||
leadPending = false;
|
||||
const ordered = Boolean(listItem[2]);
|
||||
const list: string[] = [];
|
||||
const firstNumber = ordered ? Number(listItem[2]) : undefined;
|
||||
@@ -104,11 +161,17 @@ export function AiMarkdown({ content, className, evidenceLabels, evidencePrefix
|
||||
const paragraph: string[] = [];
|
||||
while (index < lines.length && lines[index].trim() && !isBlockStart(lines, index)) paragraph.push(lines[index++]);
|
||||
if (!paragraph.length) { index += 1; continue; }
|
||||
if (layout) {
|
||||
// The presentation only changes line grouping. Tables, order and all
|
||||
// checked words/values remain intact, including limits and uncertainty.
|
||||
renderReadingParagraph(paragraph.join('\n'));
|
||||
continue;
|
||||
}
|
||||
blocks.push(<p key={`paragraph-${blocks.length}`}>{paragraph.flatMap((part, partIndex) => [
|
||||
...(partIndex ? [<br key={`break-${partIndex}`} />] : []),
|
||||
...inline(part, `paragraph-${blocks.length}-${partIndex}`),
|
||||
])}</p>);
|
||||
}
|
||||
|
||||
return <div className={className ? `ai-markdown ${className}` : 'ai-markdown'}>{blocks}</div>;
|
||||
return <div className={['ai-markdown', className, layout && 'analysis-conclusion-layout'].filter(Boolean).join(' ')}>{blocks}</div>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user