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 {