From ef41235b077e53ee2d5bdc8b4b3b658eda0f92ed Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 3 May 2026 17:44:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=89=E8=A3=85=E9=A1=B5=E9=9D=A2API?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit api.ts的BASE_URL=/api/v1,安装页面调用api.get('/api/install/status') 导致实际请求路径为/api/v1/api/install/status(404)。 改为fetch直接请求避免baseURL前缀叠加。 --- frontend/src/pages/install/index.vue | 33 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/frontend/src/pages/install/index.vue b/frontend/src/pages/install/index.vue index efb7055..7e78933 100644 --- a/frontend/src/pages/install/index.vue +++ b/frontend/src/pages/install/index.vue @@ -4,8 +4,6 @@ import { computed, onMounted, ref } from 'vue' import { useRouter } from 'vue-router' import { toast } from 'vue-sonner' -import api from '@/services/api' - const router = useRouter() const loading = ref(false) @@ -41,9 +39,10 @@ const dbTypes = [ async function checkInstallStatus() { checkingStatus.value = true try { - const data = await api.get('/api/install/status') - installStatus.value = data - if (data?.installed) { + const res = await fetch('/api/install/status') + const data = await res.json() + installStatus.value = data?.data + if (data?.data?.installed) { router.push('/auth/login') } } @@ -68,8 +67,16 @@ async function testDatabase() { payload.username = form.value.db_username payload.password = form.value.db_password } - const data = await api.post('/api/install/test-db', payload) - toast.success(data?.message || '数据库连接成功') + const res = await fetch('/api/install/test-db', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload), + }) + const result = await res.json() + if (!res.ok || result.code !== 200) { + throw new Error(result.message || '数据库连接失败') + } + toast.success(result.data?.message || '数据库连接成功') } catch (error: any) { toast.error(error.message || '数据库连接失败') @@ -130,8 +137,16 @@ async function handleInstall() { payload.redis_db = form.value.redis_db } - const data = await api.post('/api/install/setup', payload) - toast.success(data?.message || '安装成功') + const res = await fetch('/api/install/setup', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload), + }) + const result = await res.json() + if (!res.ok || result.code !== 200) { + throw new Error(result.message || '安装失败') + } + toast.success(result.data?.message || '安装成功') step.value = 4 } catch (error: any) {