From b1a153298fd277fdc8dfbfd1daac54887e55a602 Mon Sep 17 00:00:00 2001 From: wangziqi Date: Tue, 10 Feb 2026 16:06:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=89=8D=E7=AB=AF=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E8=A7=A3=E5=86=B3=E4=B8=8A=E4=BC=A0=E8=B7=A8?= =?UTF-8?q?=E5=9F=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 配置 Vite 开发服务器代理 /api 和 /uploads 到后端 - API baseURL 改为相对路径 '/api' - 修改上传 action 为相对路径 '/api/upload/image' - 移除后端 FileUploadController 的 @CrossOrigin 注解 - 恢复 WebMvcConfig 的拦截器配置 --- .../maternalmall/config/WebMvcConfig.class | Bin 3438 -> 3478 bytes .../controller/FileUploadController.class | Bin 4183 -> 4426 bytes frontend/src/api/http.js | 2 +- frontend/src/views/admin/AdminBanners.vue | 2 +- frontend/src/views/admin/AdminProducts.vue | 2 +- .../src/views/merchant/MerchantProducts.vue | 2 +- frontend/vite.config.js | 14 +++++++++++++- 7 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/target/classes/com/maternalmall/config/WebMvcConfig.class b/backend/target/classes/com/maternalmall/config/WebMvcConfig.class index 02a72c768c0794f23dd9af7b91e097186d0dbf8a..aeba192c0f021a19a5e7ff9bce5a054d1a6fbf61 100644 GIT binary patch delta 767 zcmZ9JT~8B16o%i~?g!3Jnz+RB(a1-o1=`YrTE!1k6cj}eMMY4=)m^1p?b>2YObqci zOyZ^Y#w#M>f}{o$uS`t*6W;n0jAu$y7cXY_edoM$p4qd%JKx9o_dnZT0E}U6gMZX| zTX2XWns=13xCp{Mz?s{I%7xS5?tt0>{IpDc|+{3YAXaq=i!gr!gkKvV!a~VzQ>cGtUZ~!?>I< zQsxDL2~5hsn6xip%ED!VE0o?bitH+p3!hia50U5-j#U&bJXPsu(&pdTbNQ3U^?)HM z1KuWQdDOH}Vd!dDOOD#k@H8|yupwv=nu3C1hO|xZSz6bsn1fEjz;z1TkZL2N;PI!AZ;)*Aae(csuAf5HB|?4@|WGSuGi4I7;zHw zTj*ZcpluC`6QdB&Mx=HeLtE!XMF91ax++bRgw2MCIYf?7pUDZZ;6e7|+y(4lK^x@60*(`@VDThxXrlt)G9_zX8KkSFF#Wofchm zn;dZH;h-$WAw{m{Xd}|9JBLW^PK>Dji@k%`G{7Oc0r<(UsYH|DqQoL4$t*$7sqm7ve^QZdF8}}l diff --git a/backend/target/classes/com/maternalmall/controller/FileUploadController.class b/backend/target/classes/com/maternalmall/controller/FileUploadController.class index 2edc01eb2bde12cff8776168377ebfb36bb4d144..32a1cee95676f5acc0823ace585fc631b323252d 100644 GIT binary patch delta 425 zcmXYtNiRcT6o%iUrCiq-5`snyiB<%OrcF!<6$d8U6r?EMaLdf7bZ{m#krF22v&be)j?N!(PV;v@>0>p$m3+(Tp*)U>a>$ z;L9>PunGs(;lu`9$!K8}mG^K(FIV)V0&X-yV!@+t7A>i6n6Smawhh8c2&7>LyS&>o w@;(m!=V1uh3XX7`K{A7r3{EpR!#OvUv30>Mw+8PGKH`}#0&idNh7VN!0+zpJ_5c6? delta 261 zcmW-cyGjFL7(~yPh?jNOTu@M=L02Ug3{e!da4n)B76vS|5sQEUA;l)ywY9LbviQ-$ zH}GzZ*Ql|v$_w}cK8N^|W|%nx1Jkm9Mvc~AqX{^C)r>-~9nQI~@A=h2d86p>yL(=! zlUsv3?z^a&Z1bS<=6Cc_2#9p^ECeO1&8wQQQu40yR=VR;h^tL2uFkEBM3mY0>%{0` zmKyG#UB_dcZa% diff --git a/frontend/src/api/http.js b/frontend/src/api/http.js index 732f576..4b42ee8 100644 --- a/frontend/src/api/http.js +++ b/frontend/src/api/http.js @@ -1,7 +1,7 @@ import axios from 'axios' const http = axios.create({ - baseURL: 'http://localhost:8080', + baseURL: '/api', timeout: 10000 }) diff --git a/frontend/src/views/admin/AdminBanners.vue b/frontend/src/views/admin/AdminBanners.vue index 4e79020..0b0c182 100644 --- a/frontend/src/views/admin/AdminBanners.vue +++ b/frontend/src/views/admin/AdminBanners.vue @@ -90,7 +90,7 @@ const banners = ref([]) const bannerModalVisible = ref(false) const bannerForm = reactive({ id: null, imageUrl: '', linkUrl: '', sortNo: 1, enabled: true }) -const uploadAction = 'http://localhost:8080/api/upload/image' +const uploadAction = '/api/upload/image' const uploadHeaders = computed(() => ({ 'X-Token': localStorage.getItem('token') || '' })) diff --git a/frontend/src/views/admin/AdminProducts.vue b/frontend/src/views/admin/AdminProducts.vue index f04d7bb..b54f67d 100644 --- a/frontend/src/views/admin/AdminProducts.vue +++ b/frontend/src/views/admin/AdminProducts.vue @@ -126,7 +126,7 @@ const merchantOptions = ref([]) const productModalVisible = ref(false) const productForm = reactive({ id: null, name: '', category: '', description: '', price: 0, stock: 0, imageUrl: '', merchantId: null, approved: false }) -const uploadAction = 'http://localhost:8080/api/upload/image' +const uploadAction = '/api/upload/image' const uploadHeaders = computed(() => ({ 'X-Token': localStorage.getItem('token') || '' })) diff --git a/frontend/src/views/merchant/MerchantProducts.vue b/frontend/src/views/merchant/MerchantProducts.vue index 51be18b..fb1a05b 100644 --- a/frontend/src/views/merchant/MerchantProducts.vue +++ b/frontend/src/views/merchant/MerchantProducts.vue @@ -110,7 +110,7 @@ const products = ref([]) const productModalVisible = ref(false) const productForm = reactive({ id: null, name: '', category: '', description: '', price: 0, stock: 0, imageUrl: '', approved: false }) -const uploadAction = 'http://localhost:8080/api/upload/image' +const uploadAction = '/api/upload/image' const uploadHeaders = computed(() => ({ 'X-Token': localStorage.getItem('token') || '' })) diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 8084277..d048596 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -4,6 +4,18 @@ import vue from '@vitejs/plugin-vue' export default defineConfig({ plugins: [vue()], server: { - port: 5173 + port: 5173, + proxy: { + '/api': { + target: 'http://localhost:8080', + changeOrigin: true, + secure: false + }, + '/uploads': { + target: 'http://localhost:8080', + changeOrigin: true, + secure: false + } + } } })