From 4b3f2fb51ac4045a5b776796c082c3017a111ae1 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Sun, 2 Feb 2025 23:39:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E9=80=82=E9=85=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/file/index.ts | 16 ++++++++++++++++ src/components/WangEditor/index.vue | 2 +- src/views/demo/signature.vue | 2 +- src/views/profile/index.vue | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/api/file/index.ts b/src/api/file/index.ts index c2076a19..0b109772 100644 --- a/src/api/file/index.ts +++ b/src/api/file/index.ts @@ -17,6 +17,22 @@ const FileAPI = { }); }, + /** + * 上传文件 + */ + uploadFile(file: File) { + const formData = new FormData(); + formData.append("file", file); + return request({ + url: "/api/v1/files", + method: "post", + data: formData, + headers: { + "Content-Type": "multipart/form-data", + }, + }); + }, + /** * 删除文件 * diff --git a/src/components/WangEditor/index.vue b/src/components/WangEditor/index.vue index 4ea98f38..883e23c5 100644 --- a/src/components/WangEditor/index.vue +++ b/src/components/WangEditor/index.vue @@ -67,7 +67,7 @@ const editorConfig = ref>({ uploadImage: { customUpload(file: File, insertFn: InsertFnType) { // 上传图片 - FileAPI.upload(file).then((res) => { + FileAPI.uploadFile(file).then((res) => { // 插入图片 insertFn(res.url, res.name, res.url); }); diff --git a/src/views/demo/signature.vue b/src/views/demo/signature.vue index c755921b..dd00ad92 100644 --- a/src/views/demo/signature.vue +++ b/src/views/demo/signature.vue @@ -68,7 +68,7 @@ const handleToFile = async () => { const file = dataURLtoFile(canvas.value.toDataURL(), "签名.png"); if (!file) return; - const data = await FileAPI.upload(file); + const data = await FileAPI.uploadFile(file); handleClearSign(); imgUrl.value = data.url; }; diff --git a/src/views/profile/index.vue b/src/views/profile/index.vue index e36f06b3..999d9f50 100644 --- a/src/views/profile/index.vue +++ b/src/views/profile/index.vue @@ -458,7 +458,7 @@ const handleFileChange = async (event: Event) => { if (file) { // 调用文件上传API try { - const data = await FileAPI.upload(file); + const data = await FileAPI.uploadFile(file); // 更新用户头像 userProfile.value.avatar = data.url; // 更新用户信息