fix: 结构化渲染审查总结,替换原始JSON显示
- 后端发送结构化数据(score/overall/findings/recommendations)而非格式化文本 - 增加灵活JSON解析,兼容LLM返回recommendations为数组的情况 - 前端渲染带样式的审查总结:评分徽章(颜色分级)、分区展示 - 两个页面统一处理:repo页面的内联审查和review页面的完整审查
This commit is contained in:
@@ -126,6 +126,34 @@
|
||||
let fileReviews = {};
|
||||
let currentAnalysisId = null;
|
||||
|
||||
// ── Utilities ────────────────────────────────────────────────
|
||||
function escapeHtml(text) {
|
||||
if (!text) return '';
|
||||
return String(text)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function renderSummaryHtml(data) {
|
||||
let html = '<div class="space-y-3">';
|
||||
const score = data.score || 0;
|
||||
const scoreColor = score >= 7 ? 'bg-green-100 text-green-800' : score >= 4 ? 'bg-yellow-100 text-yellow-800' : 'bg-red-100 text-red-800';
|
||||
html += `<div class="flex items-center gap-2"><span class="text-sm font-medium text-gray-600">整体评分</span><span class="px-2 py-0.5 rounded-full text-xs font-semibold ${scoreColor}">${score}/10</span></div>`;
|
||||
if (data.overall) {
|
||||
html += `<div><span class="text-sm font-medium text-gray-600">总体评价</span><p class="mt-1 text-sm text-gray-800">${escapeHtml(data.overall)}</p></div>`;
|
||||
}
|
||||
if (data.findings) {
|
||||
html += `<div><span class="text-sm font-medium text-gray-600">主要发现</span><p class="mt-1 text-sm text-gray-800">${escapeHtml(data.findings)}</p></div>`;
|
||||
}
|
||||
if (data.recommendations) {
|
||||
html += `<div><span class="text-sm font-medium text-gray-600">改进建议</span><p class="mt-1 text-sm text-gray-800">${escapeHtml(data.recommendations)}</p></div>`;
|
||||
}
|
||||
html += '</div>';
|
||||
return html;
|
||||
}
|
||||
|
||||
// Load refs on page load
|
||||
async function loadRefs() {
|
||||
try {
|
||||
@@ -310,7 +338,12 @@
|
||||
}
|
||||
},
|
||||
summary(data) {
|
||||
document.getElementById('summary-content').innerHTML = renderMarkdown(data.content || '');
|
||||
const el = document.getElementById('summary-content');
|
||||
if (data.score !== undefined) {
|
||||
el.innerHTML = renderSummaryHtml(data);
|
||||
} else {
|
||||
el.innerHTML = renderMarkdown(data.content || '');
|
||||
}
|
||||
document.getElementById('progress-bar').style.width = '90%';
|
||||
document.getElementById('progress-text').textContent = '生成总结...';
|
||||
},
|
||||
@@ -497,13 +530,7 @@
|
||||
|
||||
// Render summary
|
||||
const summary = result.summary || {};
|
||||
let summaryText = '';
|
||||
if (summary.score) summaryText += `整体评分: ${summary.score}/10\n\n`;
|
||||
if (summary.overall) summaryText += summary.overall;
|
||||
if (summary.findings) summaryText += '\n\n**主要发现:**\n' + summary.findings;
|
||||
if (summary.recommendations) summaryText += '\n\n**改进建议:**\n' + summary.recommendations;
|
||||
|
||||
document.getElementById('summary-content').innerHTML = renderMarkdown(summaryText);
|
||||
document.getElementById('summary-content').innerHTML = renderSummaryHtml(summary);
|
||||
|
||||
// Clear and rebuild card view
|
||||
document.getElementById('file-reviews').innerHTML = '';
|
||||
|
||||
Reference in New Issue
Block a user