更新:models/routes/services/templates/docs
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h4><i class="bi bi-file-text"></i> 方案详情</h4>
|
||||
<div>
|
||||
<button onclick="history.back()" class="btn btn-outline-secondary">
|
||||
<button onclick="goBack()" class="btn btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left"></i> 返回
|
||||
</button>
|
||||
</div>
|
||||
@@ -40,16 +40,24 @@ async function loadPlan() {
|
||||
<strong>生成时间:</strong>${data.created_at}
|
||||
<strong>模板:</strong>${data.template_name || '无'}
|
||||
<div class="mt-2">
|
||||
<a href="/?student_id=${data.student_id}&from=${encodeURIComponent(window.location.href)}" class="btn btn-sm btn-outline-primary">
|
||||
<a href="/student/${data.student_id}" class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-person"></i> 查看学员
|
||||
</a>
|
||||
<a href="/plan/${currentPlanId}/edit" class="btn btn-sm btn-warning">
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="checkbox" id="typicalToggle" ${data.is_typical ? 'checked' : ''} onchange="toggleTypical(${currentPlanId}, this.checked)">
|
||||
<label class="form-check-label" for="typicalToggle">典型方案</label>
|
||||
</div>
|
||||
<a href="/plan/${currentPlanId}/edit" class="btn btn-sm btn-warning" onclick="markFromEdit()">
|
||||
<i class="bi bi-edit"></i> 编辑
|
||||
</a>
|
||||
<button onclick="downloadPDF()" class="btn btn-sm btn-primary">
|
||||
<div class="form-check form-check-inline">
|
||||
<select id="reportTemplateSelect" class="form-select form-select-sm" style="width: auto;" onchange="updateDownloadLinks()">
|
||||
</select>
|
||||
</div>
|
||||
<button onclick="downloadPDFWithTemplate()" class="btn btn-sm btn-primary">
|
||||
<i class="bi bi-download"></i> 下载PDF
|
||||
</button>
|
||||
<button onclick="downloadMD()" class="btn btn-sm btn-outline-primary">
|
||||
<button onclick="downloadMDWithTemplate()" class="btn btn-sm btn-outline-primary">
|
||||
<i class="bi bi-file-markdown"></i> 下载MD
|
||||
</button>
|
||||
</div>
|
||||
@@ -78,20 +86,8 @@ async function loadPlan() {
|
||||
`;
|
||||
}
|
||||
|
||||
html += `
|
||||
<h6>每日练习计划(共${data.content.total_daily_minutes}分钟)</h6>
|
||||
<table class="table table-sm">
|
||||
<thead><tr><th>环节</th><th>时长</th><th>内容</th><th>目的</th></tr></thead>
|
||||
<tbody>
|
||||
`;
|
||||
|
||||
data.content.daily_schedule.forEach(item => {
|
||||
html += `<tr><td>${item.phase}</td><td>${item.duration}</td><td>${item.content}</td><td>${item.purpose}</td></tr>`;
|
||||
});
|
||||
|
||||
html += '</tbody></table>';
|
||||
|
||||
document.getElementById('planContent').innerHTML = html;
|
||||
loadTemplates();
|
||||
} catch (e) {
|
||||
document.getElementById('planContent').innerHTML = `
|
||||
<div class="card-body text-center text-danger py-5">
|
||||
@@ -102,12 +98,57 @@ async function loadPlan() {
|
||||
}
|
||||
}
|
||||
|
||||
function downloadPDF() {
|
||||
window.open(`/api/plans/${currentPlanId}/pdf`, '_blank');
|
||||
function updateDownloadLinks() {
|
||||
// No longer needed - buttons now use downloadPDFWithTemplate/downloadMDWithTemplate directly
|
||||
}
|
||||
|
||||
function downloadMD() {
|
||||
window.open(`/api/plans/${currentPlanId}/md`, '_blank');
|
||||
function downloadPDFWithTemplate() {
|
||||
const templateId = document.getElementById('reportTemplateSelect')?.value;
|
||||
const suffix = templateId ? `?template_id=${templateId}` : '';
|
||||
window.open(`/api/plans/${currentPlanId}/pdf${suffix}`, '_blank');
|
||||
}
|
||||
|
||||
function downloadMDWithTemplate() {
|
||||
const templateId = document.getElementById('reportTemplateSelect')?.value;
|
||||
const suffix = templateId ? `?template_id=${templateId}` : '';
|
||||
window.open(`/api/plans/${currentPlanId}/md${suffix}`, '_blank');
|
||||
}
|
||||
|
||||
async function loadTemplates() {
|
||||
try {
|
||||
const resp = await fetch('/templates/templates?type=report');
|
||||
if (resp.ok) {
|
||||
const templates = await resp.json();
|
||||
const select = document.getElementById('reportTemplateSelect');
|
||||
select.innerHTML = templates.map(t => `<option value="${t.id}">${t.name}</option>`).join('');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('加载模板失败:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 设为典型
|
||||
async function toggleTypical(planId, isTypical) {
|
||||
try {
|
||||
await fetch(`/api/plans/${planId}/typical`, {method: 'POST'});
|
||||
} catch (e) {
|
||||
alert('设置失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 返回按钮处理:如果是编辑页返回的,跳过编辑页
|
||||
function goBack() {
|
||||
if (sessionStorage.getItem('fromEdit') === 'true') {
|
||||
sessionStorage.removeItem('fromEdit');
|
||||
history.go(-2); // 跳过编辑页
|
||||
} else {
|
||||
history.back();
|
||||
}
|
||||
}
|
||||
|
||||
// 标记来源为编辑页(编辑页点击"返回详情"前设置)
|
||||
function markFromEdit() {
|
||||
sessionStorage.setItem('fromEdit', 'true');
|
||||
}
|
||||
|
||||
window.currentStudentId = null;
|
||||
|
||||
Reference in New Issue
Block a user