From f3ccf25ede16c9b302ff2a0af025ea19ba5b2eb6 Mon Sep 17 00:00:00 2001 From: hz4th_coder Date: Thu, 4 Jun 2026 23:26:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E7=AB=A0=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E8=A1=A8=E5=8D=95=E6=97=A0=E6=B3=95=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除嵌套的附件上传form(HTML不允许表单嵌套) - 改用div和JavaScript FormData处理附件上传 --- app/templates/admin/article_form.html | 73 ++++++++++++++------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/app/templates/admin/article_form.html b/app/templates/admin/article_form.html index 53e0bd9..c2f729b 100644 --- a/app/templates/admin/article_form.html +++ b/app/templates/admin/article_form.html @@ -387,6 +387,39 @@ editor.addEventListener('input', updatePreview); // 初始化预览 updatePreview(); + +// 附件上传函数 +{% if article %} +function uploadAttachment() { + const formData = new FormData(); + formData.append('article_id', document.getElementById('attachment-article-id').value); + formData.append('file', document.getElementById('attachment-upload-file').files[0]); + formData.append('description', document.getElementById('attachment-desc').value); + + fetch('{{ url_for("admin.upload_attachment") }}', { + method: 'POST', + body: formData + }) + .then(res => res.json()) + .then(data => { + if (data.success) { + location.reload(); + } + }); +} + +function deleteAttachment(id) { + if (confirm('确定删除此附件?')) { + fetch(`/admin/attachment/${id}/delete`, {method: 'POST'}) + .then(res => res.json()) + .then(data => { + if (data.success) { + location.reload(); + } + }); + } +} +{% endif %} {% endblock %} @@ -515,43 +548,13 @@ updatePreview(); {% endfor %} -
- - - +
+ + + - +
- - {% endif %}