From 8db618a80795aa78171edc75ed78b00e54dc58e0 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Thu, 9 Jul 2026 15:04:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=89=E8=A3=85=E5=90=91=E5=AF=BC?= =?UTF-8?q?=E9=A1=B5=E6=94=AF=E6=8C=81=E6=BB=9A=E5=8A=A8=E5=B9=B6=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20MySQL/Redis=20=E8=BF=9E=E6=8E=A5=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Install 页作为独立满屏路由自身承载纵向滚动,修复内容超出视口无法滚动; MySQL/Redis 卡片新增测试连接按钮,后端新增 /api/install/test-connection(仅安装模式可用, 不建库不落盘;MySQL 库不存在也视为可连接因安装时会自动建库)。 --- apps/admin/src/locales/en-US.json | 3 + apps/admin/src/locales/zh-CN.json | 3 + apps/admin/src/views/Install.vue | 86 +++++++++++++++++++++- apps/api/src/install/dto/install.dto.ts | 32 ++++++++ apps/api/src/install/install.controller.ts | 9 ++- apps/api/src/install/install.service.ts | 54 +++++++++++++- 6 files changed, 182 insertions(+), 5 deletions(-) diff --git a/apps/admin/src/locales/en-US.json b/apps/admin/src/locales/en-US.json index 74a9f34..01cec2b 100644 --- a/apps/admin/src/locales/en-US.json +++ b/apps/admin/src/locales/en-US.json @@ -212,6 +212,9 @@ "failed": "Installation failed", "done": "Initialized. The service is restarting, please wait…", "loadFailed": "Failed to read installation status", + "testConnection": "Test", + "testOk": "Connected", + "testFailed": "Connection failed", "defaultAppName": "Artwork Traceability Platform", "defaultAdminName": "Administrator" }, diff --git a/apps/admin/src/locales/zh-CN.json b/apps/admin/src/locales/zh-CN.json index 7b5f4e0..b91bea6 100644 --- a/apps/admin/src/locales/zh-CN.json +++ b/apps/admin/src/locales/zh-CN.json @@ -212,6 +212,9 @@ "failed": "安装失败", "done": "初始化完成,服务正在重启,请稍候…", "loadFailed": "读取安装状态失败", + "testConnection": "测试连接", + "testOk": "连接成功", + "testFailed": "连接失败", "defaultAppName": "艺术品溯源平台", "defaultAdminName": "管理员" }, diff --git a/apps/admin/src/views/Install.vue b/apps/admin/src/views/Install.vue index 166da66..1637f03 100644 --- a/apps/admin/src/views/Install.vue +++ b/apps/admin/src/views/Install.vue @@ -34,7 +34,10 @@
-

MySQL

+
+

MySQL

+ {{ tt('testConnection') }} +
@@ -42,14 +45,19 @@ +

{{ mysqlTest.msg }}

{{ tt('mysqlAdminHint') }}

-

Redis

+
+

Redis

+ {{ tt('testConnection') }} +
+

{{ redisTest.msg }}

@@ -159,11 +167,56 @@ const submitting = ref(false); const installed = ref(false); const error = ref(''); const success = ref(''); +const testingMysql = ref(false); +const testingRedis = ref(false); +const mysqlTest = ref<{ ok: boolean; msg: string } | null>(null); +const redisTest = ref<{ ok: boolean; msg: string } | null>(null); function goAdmin(): void { location.href = '/admin'; } +async function testConnection(payload: Record): Promise<{ ok: boolean; msg: string }> { + try { + const res = await fetch('/api/install/test-connection', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(payload), + }); + const body = await res.json(); + if (!res.ok || body.code !== 0) throw new Error(body.message || tt('testFailed')); + return { ok: true, msg: body.data?.message || tt('testOk') }; + } catch (e) { + return { ok: false, msg: (e as Error).message || tt('testFailed') }; + } +} + +async function testMysql(): Promise { + testingMysql.value = true; + mysqlTest.value = null; + mysqlTest.value = await testConnection({ + target: 'mysql', + host: form.mysql.host, + port: form.mysql.port, + database: form.mysql.database, + username: form.mysql.username, + password: form.mysql.password, + }); + testingMysql.value = false; +} + +async function testRedis(): Promise { + testingRedis.value = true; + redisTest.value = null; + redisTest.value = await testConnection({ + target: 'redis', + host: form.redis.host, + port: form.redis.port, + password: form.redis.password, + }); + testingRedis.value = false; +} + onMounted(async () => { try { const res = await fetch('/api/install/status'); @@ -224,7 +277,9 @@ async function submit(): Promise {