80 lines
2.8 KiB
JavaScript
80 lines
2.8 KiB
JavaScript
// 方案相关公共函数(currentPlanId 在各页面自行声明)
|
||
|
||
// 查看方案详情
|
||
async function viewPlan(planId) {
|
||
currentPlanId = planId;
|
||
const response = await fetch(`/api/plans/${planId}`);
|
||
const data = await response.json();
|
||
|
||
let html = `
|
||
<div class="mb-3">
|
||
<strong>学员:</strong>${data.student_name}
|
||
<strong>练习时间:</strong>${data.content.practice_time}
|
||
<strong>生成时间:</strong>${data.created_at}
|
||
</div>
|
||
<h6>问题诊断</h6>
|
||
<div class="mb-3">
|
||
`;
|
||
|
||
data.content.problems.forEach(p => {
|
||
html += `<span class="problem-tag severity-${p.severity}">${p.name}(${p.severity})</span> `;
|
||
});
|
||
|
||
html += `</div>`;
|
||
|
||
if (data.content.ai_report) {
|
||
const aiReportHtml = marked.parse(data.content.ai_report);
|
||
html += `
|
||
<h6>AI个性化练习报告</h6>
|
||
<div class="mb-3 p-3 bg-light rounded" style="max-height: 500px; overflow-y: auto;">${aiReportHtml}</div>
|
||
`;
|
||
} else if (data.content.ai_report_error) {
|
||
html += `
|
||
<h6>AI报告</h6>
|
||
<div class="mb-3 p-3 bg-warning rounded">AI生成失败: ${data.content.ai_report_error}</div>
|
||
`;
|
||
}
|
||
|
||
document.getElementById('planDetailContent').innerHTML = html;
|
||
new bootstrap.Modal(document.getElementById('planDetailModal')).show();
|
||
}
|
||
|
||
// 下载PDF
|
||
function downloadPDF() {
|
||
const templateId = document.getElementById('reportTemplateSelect')?.value;
|
||
const url = templateId ? `/api/plans/${currentPlanId}/pdf?template_id=${templateId}` : `/api/plans/${currentPlanId}/pdf`;
|
||
window.open(url, '_blank');
|
||
}
|
||
|
||
// 下载MD
|
||
function downloadMD() {
|
||
const templateId = document.getElementById('reportTemplateSelect')?.value;
|
||
const url = templateId ? `/api/plans/${currentPlanId}/md?template_id=${templateId}` : `/api/plans/${currentPlanId}/md`;
|
||
window.open(url, '_blank');
|
||
}
|
||
|
||
// 别名(兼容旧代码)
|
||
const downloadPlanPDF = downloadPDF;
|
||
const downloadPlanMD = downloadMD;
|
||
|
||
// 预览报告模板
|
||
async function previewReportTemplate() {
|
||
if (!currentPlanId) {
|
||
alert('请先选择一个方案');
|
||
return;
|
||
}
|
||
const templateId = document.getElementById('reportTemplateSelect')?.value;
|
||
const url = templateId ? `/api/plans/${currentPlanId}/md?template_id=${templateId}` : `/api/plans/${currentPlanId}/md`;
|
||
try {
|
||
const resp = await fetch(url);
|
||
if (resp.ok) {
|
||
const md = await resp.text();
|
||
document.getElementById('reportPreviewContent').innerHTML = marked.parse(md);
|
||
new bootstrap.Modal(document.getElementById('reportPreviewModal')).show();
|
||
} else {
|
||
alert('预览失败');
|
||
}
|
||
} catch (e) {
|
||
alert('预览失败: ' + e.message);
|
||
}
|
||
} |