From 285979ff70ba5f64ea09599da19a6e7c03800599 Mon Sep 17 00:00:00 2001 From: hmo Date: Thu, 23 Apr 2026 06:40:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=AE=80=E5=8C=96=E5=90=84?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=A8=A1=E6=9D=BF=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81=EF=BC=9B=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?plan=5Fcommon.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/js/plan_common.js | 93 ++++++++++++++++++++++++++ app/templates/api_settings.html | 63 ++---------------- app/templates/classes.html | 55 ++------------- app/templates/settings.html | 114 +++++++++++++++----------------- app/templates/templates.html | 52 +-------------- app/templates/users.html | 45 +------------ 6 files changed, 163 insertions(+), 259 deletions(-) create mode 100644 app/static/js/plan_common.js diff --git a/app/static/js/plan_common.js b/app/static/js/plan_common.js new file mode 100644 index 0000000..1ff58be --- /dev/null +++ b/app/static/js/plan_common.js @@ -0,0 +1,93 @@ +// 方案相关公共函数(currentPlanId 在各页面自行声明) + +// 查看方案详情 +async function viewPlan(planId) { + currentPlanId = planId; + const response = await fetch(`/api/plans/${planId}`); + const data = await response.json(); + + let html = ` +
+ 学员:${data.student_name}    + 练习时间:${data.content.practice_time}    + 生成时间:${data.created_at} +
+
问题诊断
+
+ `; + + data.content.problems.forEach(p => { + html += `${p.name}(${p.severity}) `; + }); + + html += `
`; + + if (data.content.ai_report) { + const aiReportHtml = marked.parse(data.content.ai_report); + html += ` +
AI个性化练习报告
+
${aiReportHtml}
+ `; + } else if (data.content.ai_report_error) { + html += ` +
AI报告
+
AI生成失败: ${data.content.ai_report_error}
+ `; + } + + html += ` +
每日练习计划(共${data.content.total_daily_minutes}分钟)
+ + + + `; + + data.content.daily_schedule.forEach(item => { + html += ``; + }); + + html += '
环节时长内容目的
${item.phase}${item.duration}${item.content}${item.purpose}
'; + + 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); + } +} \ No newline at end of file diff --git a/app/templates/api_settings.html b/app/templates/api_settings.html index 31803dd..cb354a2 100644 --- a/app/templates/api_settings.html +++ b/app/templates/api_settings.html @@ -2,34 +2,6 @@ {% block title %}API设置 - 钢琴练习方案系统{% endblock %} -{% block sidebar_nav %} - - 学员管理 - - - 问题配置 - - - API设置 - - - - 班级管理 - - -
- - 修改密码 - - - 退出登录 - -{% endblock %} - {% block content %}
@@ -141,34 +113,13 @@ {% block extra_js %} - -