From b5c13d5f24a1feaf471945b26eadb37419b59696 Mon Sep 17 00:00:00 2001 From: wx <2636507191@qq.com> Date: Mon, 4 May 2026 14:19:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(blog):=20=E5=90=8E=E5=8F=B0=E5=8D=9A?= =?UTF-8?q?=E5=AE=A2=E5=9B=BE=E7=89=87=E6=94=AF=E6=8C=81=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=20+=20=E5=B0=81=E9=9D=A2=E5=9B=BE=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E9=94=99=E8=AF=AF=E4=BF=A1=E6=81=AF=E6=9A=B4=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 正文编辑器: - 新增"图片"按钮: 点击弹文件选择 -> 调 /api/admin/upload -> 自动插入 - 保留"图片URL"按钮兼容外链/已有路径(原来唯一的 prompt 路径) - 上传中按钮 disabled, 失败用 naive-ui message 提示 封面图 ImageUpload: - 改用 useAdmin().adminFetch 替代裸 \$fetch + useState 取 token 的双轨写法 - 错误信息从单一字符串"上传失败"改为 e.data?.message || e.message || HTTP statusCode, 让线上"上传失败"自暴露真实根因 Co-Authored-By: Claude Opus 4.7 (1M context) --- components/admin/ImageUpload.vue | 6 ++--- components/admin/RichTextEditor.vue | 41 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/components/admin/ImageUpload.vue b/components/admin/ImageUpload.vue index 33902f2..1a51546 100644 --- a/components/admin/ImageUpload.vue +++ b/components/admin/ImageUpload.vue @@ -90,11 +90,9 @@ async function uploadFile(file) { const formData = new FormData() formData.append('file', file) - const token = useState('admin_token') - const result = await $fetch('/api/admin/upload', { + const result = await adminFetch('/api/admin/upload', { method: 'POST', body: formData, - headers: { Authorization: `Bearer ${token.value}` }, }) if (result.files?.length) { @@ -102,7 +100,7 @@ async function uploadFile(file) { imgError.value = false } } catch (e) { - uploadError.value = e.data?.message || '上传失败' + uploadError.value = e?.data?.message || e?.message || `上传失败 (HTTP ${e?.statusCode ?? '?'})` } finally { uploading.value = false } diff --git a/components/admin/RichTextEditor.vue b/components/admin/RichTextEditor.vue index 6ec23e5..a237a57 100644 --- a/components/admin/RichTextEditor.vue +++ b/components/admin/RichTextEditor.vue @@ -14,7 +14,8 @@ - + + @@ -22,6 +23,8 @@ + +