From fd3e2a450f142b379f404460a3566602502233a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AD=9F?= <3111696955@qq.com> Date: Thu, 14 Aug 2025 16:55:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(biji):=20=E4=BF=AE=E5=A4=8D=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=E5=92=8C=E9=A2=84=E8=A7=88=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -优化图片预览接口返回信息,提高错误处理的可读性- 在图片上传时添加基础 URL,确保正确的图片路径 - 更新 Vite 配置,修复开发环境的代理设置 --- .../controller/ImageController.java | 6 ++++-- .../src/components/home/NoteEditor.vue | 7 ++++--- biji-qianduan/vite.config.js | 5 ++--- mydatabase.db | Bin 73728 -> 73728 bytes 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/ImageController.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/ImageController.java index 85604ab..eb75b91 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/ImageController.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/ImageController.java @@ -64,12 +64,14 @@ public class ImageController { public void preview(@PathVariable String url, HttpServletResponse resp) throws IOException { if (StrUtil.isBlank(url)) { resp.setStatus(404); - R.fail("文件不存在"); + resp.getWriter().write("{\"code\":404,\"msg\":\"文件不存在\",\"data\":null}"); + return; } File file = new File(rootPath + File.separator + url); if (!file.exists()) { resp.setStatus(404); - R.fail("文件不存在"); + resp.getWriter().write("{\"code\":404,\"msg\":\"文件不存在\",\"data\":null}"); + return; } String contentTypeFromFileExtension = getContentTypeFromFileExtension(url); // 设置正确的 MIME diff --git a/biji-qianduan/src/components/home/NoteEditor.vue b/biji-qianduan/src/components/home/NoteEditor.vue index c87f372..8241b55 100644 --- a/biji-qianduan/src/components/home/NoteEditor.vue +++ b/biji-qianduan/src/components/home/NoteEditor.vue @@ -66,9 +66,10 @@ const initVditor = () => { if (!file) return; uploadImage(file).then(res => { - const url = res.url; - // 使用 file.name 替代 files.name 保证一致性 - vditor.value.insertValue(`![${file.name}](${url})`); + const url = res.url; + // 使用 file.name 替代 files.name 保证一致性 + const baseUrl = import.meta.env.VITE_API_BASE_URL || ''; + vditor.value.insertValue(`![${file.name}](${baseUrl}${url})`); }).catch(() => { ElMessage.error('图片上传失败'); }); diff --git a/biji-qianduan/vite.config.js b/biji-qianduan/vite.config.js index de98cd0..22dbd66 100644 --- a/biji-qianduan/vite.config.js +++ b/biji-qianduan/vite.config.js @@ -6,9 +6,8 @@ import path from 'path' export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') return { - // base: env.VITE_BASE_URL, + base: env.VITE_BASE_URL, plugins: [vue()], - base: './', resolve: { alias: { '@': path.resolve(__dirname, './src') @@ -17,7 +16,7 @@ export default defineConfig(({ mode }) => { server: { proxy: { '/api': { - target: 'http://localhost:8084', + target: 'http://127.0.0.1:8084', changeOrigin: true, rewrite: path => path.replace(/^\/api/, '') } diff --git a/mydatabase.db b/mydatabase.db index fd7c2f6bb460092cab3e484791ac5bdbe1d38a04..c783be23487560fc0bf94800e4b350ae9c782de0 100644 GIT binary patch delta 790 zcmZoTz|wGlWr8%L=|mZ4M$?T6OZb_^SY#)&3#hZP8ndimk=<-4@RFIikwaqgK~Z59 zBeN7^BeSGb-DE@4G+h&;M04H5lvFca%Oq1%b8~Y86C?AK$seU9Y=}{)SCE%pwmdU8 zF+Eiu$Yh+c{G_dTBZoNHrbII{Gh;JjOIEofhSCg>9$pr1ir5d*27EFh+_`C5)u zF%!SWWuM|{}tXHJlFXZHmfB3=bpHrmqmv;mT|Ixn8xO7IabA+g&sWS zo4CM~&xD1Afi0G0uZpP*lK=x)KJNVr1&;R&yjIN9nci=96u8bLvvtYg6(3qAFz_-o r$~LWsa~S1S8#AZR6Jqq49>ved57IroMVL{5dHLKu+ouaNX7T_4O5{K@