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 %}