feat: 安装向导页支持滚动并新增 MySQL/Redis 连接测试

Install 页作为独立满屏路由自身承载纵向滚动,修复内容超出视口无法滚动;
MySQL/Redis 卡片新增测试连接按钮,后端新增 /api/install/test-connection(仅安装模式可用,
不建库不落盘;MySQL 库不存在也视为可连接因安装时会自动建库)。
This commit is contained in:
Nixevol
2026-07-09 15:04:45 +08:00
parent 0780fc2d0f
commit 8db618a807
6 changed files with 182 additions and 5 deletions
+83 -3
View File
@@ -34,7 +34,10 @@
</section>
<section class="box">
<h2>MySQL</h2>
<div class="box-head">
<h2>MySQL</h2>
<n-button size="tiny" :loading="testingMysql" @click="testMysql">{{ tt('testConnection') }}</n-button>
</div>
<label><span>{{ tt('host') }}</span><n-input v-model:value="form.mysql.host" /></label>
<label><span>{{ tt('port') }}</span><n-input-number v-model:value="form.mysql.port" :min="1" :show-button="false" class="full" /></label>
<label><span>{{ tt('database') }}</span><n-input v-model:value="form.mysql.database" /></label>
@@ -42,14 +45,19 @@
<label><span>{{ tt('password') }}</span><n-input v-model:value="form.mysql.password" type="password" show-password-on="click" /></label>
<label><span>{{ tt('adminUser') }}</span><n-input v-model:value="form.mysql.adminUsername" /></label>
<label><span>{{ tt('adminPass') }}</span><n-input v-model:value="form.mysql.adminPassword" type="password" show-password-on="click" /></label>
<p v-if="mysqlTest" class="test-result" :class="mysqlTest.ok ? 'ok' : 'fail'">{{ mysqlTest.msg }}</p>
<p class="hint">{{ tt('mysqlAdminHint') }}</p>
</section>
<section class="box">
<h2>Redis</h2>
<div class="box-head">
<h2>Redis</h2>
<n-button size="tiny" :loading="testingRedis" @click="testRedis">{{ tt('testConnection') }}</n-button>
</div>
<label><span>{{ tt('host') }}</span><n-input v-model:value="form.redis.host" /></label>
<label><span>{{ tt('port') }}</span><n-input-number v-model:value="form.redis.port" :min="1" :show-button="false" class="full" /></label>
<label><span>{{ tt('password') }}</span><n-input v-model:value="form.redis.password" type="password" show-password-on="click" /></label>
<p v-if="redisTest" class="test-result" :class="redisTest.ok ? 'ok' : 'fail'">{{ redisTest.msg }}</p>
</section>
<section class="box">
@@ -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<string, unknown>): 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<void> {
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<void> {
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<void> {
<style scoped>
.install-page {
min-height: 100vh;
/* 全局 #app 为 overflow-y:hidden,安装页是独立满屏路由,需自身承载纵向滚动 */
height: 100vh;
overflow-y: auto;
padding: 24px;
display: flex;
justify-content: center;
@@ -273,6 +328,31 @@ async function submit(): Promise<void> {
padding-bottom: 8px;
border-bottom: 1px solid var(--border, #e9edf4);
}
.box-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid var(--border, #e9edf4);
}
.box-head h2 {
margin: 0;
padding: 0;
border: 0;
}
.test-result {
margin: 2px 0 0;
font-size: 12px;
line-height: 1.5;
word-break: break-all;
}
.test-result.ok {
color: #18a058;
}
.test-result.fail {
color: #d03050;
}
.box label {
display: grid;
grid-template-columns: 132px 1fr;