feat: 安装向导改为三步分段引导并说明对外访问地址填写方式

基础配置/数据库/存储三步走:当前步有未填或不合法项时禁用下一步并逐条列出问题;
数据库步点下一步自动测试 MySQL/Redis,全部通过才放行;
存储步按钮变为「安装」,安装前自动先做存储读写测试;去掉右上角开始安装按钮;
对外访问地址补充说明(域名 / 服务器IP:端口 / 本地默认),配置变更后自动作废旧测试结果。
This commit is contained in:
Nixevol
2026-07-09 15:33:12 +08:00
parent 3109beabee
commit 8ef7f08ded
3 changed files with 215 additions and 79 deletions
+177 -79
View File
@@ -9,9 +9,6 @@
<div class="head-actions">
<lang-switch />
<theme-switch />
<n-button v-if="!installed" type="primary" size="large" :loading="submitting" @click="submit">
{{ submitting ? tt('installing') : tt('start') }}
</n-button>
</div>
</div>
@@ -28,73 +25,98 @@
</n-result>
<template v-else>
<div class="grid">
<section class="box">
<h2>{{ tt('base') }}</h2>
<label><span>{{ tt('appName') }}<i class="req">*</i></span><n-input v-model:value="form.appName" /></label>
<label><span>{{ tt('baseUrl') }}<i class="req">*</i></span><n-input v-model:value="form.baseUrl" placeholder="https://example.com" /></label>
<div class="urls">
<div><span>{{ tt('urlAdmin') }}</span>{{ baseTrim }}/admin</div>
<div><span>{{ tt('urlClient') }}</span>{{ baseTrim }}/trace</div>
</div>
<n-steps :current="step + 1" size="small" class="steps">
<n-step :title="tt('stepBase')" />
<n-step :title="tt('stepDb')" />
<n-step :title="tt('stepStorage')" />
</n-steps>
<div class="sub">{{ tt('admin') }}</div>
<label><span>{{ tt('adminAccount') }}<i class="req">*</i></span><n-input v-model:value="form.admin.username" /></label>
<label><span>{{ tt('adminPwd') }}<i class="req">*</i></span><n-input v-model:value="form.admin.password" type="password" show-password-on="click" /></label>
<label><span>{{ tt('realName') }}</span><n-input v-model:value="form.admin.realName" /></label>
</section>
<!-- 第 1 步:基础配置(含管理员) -->
<section v-show="step === 0" class="box">
<h2>{{ tt('base') }}</h2>
<label><span>{{ tt('appName') }}<i class="req">*</i></span><n-input v-model:value="form.appName" /></label>
<label><span>{{ tt('baseUrl') }}<i class="req">*</i></span><n-input v-model:value="form.baseUrl" placeholder="https://art.example.com" /></label>
<p class="hint">{{ tt('baseUrlHint') }}</p>
<div class="urls">
<div><span>{{ tt('urlAdmin') }}</span>{{ baseTrim }}/admin</div>
<div><span>{{ tt('urlClient') }}</span>{{ baseTrim }}/trace</div>
</div>
<section class="box">
<h2>{{ tt('dbCard') }}</h2>
<div class="sub">{{ tt('admin') }}</div>
<label><span>{{ tt('adminAccount') }}<i class="req">*</i></span><n-input v-model:value="form.admin.username" /></label>
<label><span>{{ tt('adminPwd') }}<i class="req">*</i></span><n-input v-model:value="form.admin.password" type="password" show-password-on="click" /></label>
<label><span>{{ tt('realName') }}</span><n-input v-model:value="form.admin.realName" /></label>
</section>
<div class="sub-row">
<div class="sub">MySQL</div>
<n-button size="tiny" :loading="testingMysql" @click="testMysql">{{ tt('testConnection') }}</n-button>
</div>
<label><span>{{ tt('host') }}<i class="req">*</i></span><n-input v-model:value="form.mysql.host" /></label>
<label><span>{{ tt('port') }}<i class="req">*</i></span><n-input-number v-model:value="form.mysql.port" :min="1" :show-button="false" class="full" /></label>
<label><span>{{ tt('database') }}<i class="req">*</i></span><n-input v-model:value="form.mysql.database" /></label>
<label><span>{{ tt('username') }}<i class="req">*</i></span><n-input v-model:value="form.mysql.username" /></label>
<label><span>{{ tt('password') }}</span><n-input v-model:value="form.mysql.password" type="password" show-password-on="click" /></label>
<p v-if="mysqlTest" class="test-result" :class="mysqlTest.ok ? 'ok' : 'fail'">{{ mysqlTest.msg }}</p>
<!-- 第 2 步:数据库(MySQL + Redis) -->
<section v-show="step === 1" class="box">
<h2>{{ tt('dbCard') }}</h2>
<div class="sub-row">
<div class="sub">Redis</div>
<n-button size="tiny" :loading="testingRedis" @click="testRedis">{{ tt('testConnection') }}</n-button>
</div>
<label><span>{{ tt('host') }}<i class="req">*</i></span><n-input v-model:value="form.redis.host" /></label>
<label><span>{{ tt('port') }}<i class="req">*</i></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>
<div class="sub-row">
<div class="sub">MySQL</div>
<n-button size="tiny" :loading="testingMysql" @click="testMysql">{{ tt('testConnection') }}</n-button>
</div>
<label><span>{{ tt('host') }}<i class="req">*</i></span><n-input v-model:value="form.mysql.host" /></label>
<label><span>{{ tt('port') }}<i class="req">*</i></span><n-input-number v-model:value="form.mysql.port" :min="1" :show-button="false" class="full" /></label>
<label><span>{{ tt('database') }}<i class="req">*</i></span><n-input v-model:value="form.mysql.database" /></label>
<label><span>{{ tt('username') }}<i class="req">*</i></span><n-input v-model:value="form.mysql.username" /></label>
<label><span>{{ tt('password') }}</span><n-input v-model:value="form.mysql.password" type="password" show-password-on="click" /></label>
<p v-if="mysqlTest" class="test-result" :class="mysqlTest.ok ? 'ok' : 'fail'">{{ mysqlTest.msg }}</p>
<section class="box">
<div class="box-head">
<h2>{{ tt('storage') }}</h2>
<n-button size="tiny" :loading="testingStorage" @click="testStorage">{{ tt('testConnection') }}</n-button>
</div>
<label>
<span>{{ tt('driver') }}<i class="req">*</i></span>
<n-select v-model:value="form.storage.driver" :options="driverOptions" class="full" />
</label>
<template v-if="form.storage.driver === 'local'">
<label><span>{{ tt('localDir') }}<i class="req">*</i></span><n-input v-model:value="form.storage.localDir" /></label>
</template>
<template v-else>
<label><span>Endpoint<i class="req">*</i></span><n-input v-model:value="form.storage.ossEndpoint" /></label>
<label><span>Region</span><n-input v-model:value="form.storage.ossRegion" /></label>
<label><span>Bucket<i class="req">*</i></span><n-input v-model:value="form.storage.ossBucket" /></label>
<label><span>AccessKey ID<i class="req">*</i></span><n-input v-model:value="form.storage.ossAccessKeyId" /></label>
<label><span>AccessKey Secret<i class="req">*</i></span><n-input v-model:value="form.storage.ossAccessKeySecret" type="password" show-password-on="click" /></label>
</template>
<label><span>CDN</span><n-input v-model:value="form.storage.cdnBaseUrl" placeholder="https://cdn.example.com" /></label>
<p class="hint">{{ tt('cdnHint') }}</p>
<p v-if="storageTest" class="test-result" :class="storageTest.ok ? 'ok' : 'fail'">{{ storageTest.msg }}</p>
</section>
</div>
<div class="sub-row">
<div class="sub">Redis</div>
<n-button size="tiny" :loading="testingRedis" @click="testRedis">{{ tt('testConnection') }}</n-button>
</div>
<label><span>{{ tt('host') }}<i class="req">*</i></span><n-input v-model:value="form.redis.host" /></label>
<label><span>{{ tt('port') }}<i class="req">*</i></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>
<!-- 第 3 步:存储 -->
<section v-show="step === 2" class="box">
<div class="box-head">
<h2>{{ tt('storage') }}</h2>
<n-button size="tiny" :loading="testingStorage" @click="testStorage">{{ tt('testConnection') }}</n-button>
</div>
<label>
<span>{{ tt('driver') }}<i class="req">*</i></span>
<n-select v-model:value="form.storage.driver" :options="driverOptions" class="full" />
</label>
<template v-if="form.storage.driver === 'local'">
<label><span>{{ tt('localDir') }}<i class="req">*</i></span><n-input v-model:value="form.storage.localDir" /></label>
</template>
<template v-else>
<label><span>Endpoint<i class="req">*</i></span><n-input v-model:value="form.storage.ossEndpoint" /></label>
<label><span>Region</span><n-input v-model:value="form.storage.ossRegion" /></label>
<label><span>Bucket<i class="req">*</i></span><n-input v-model:value="form.storage.ossBucket" /></label>
<label><span>AccessKey ID<i class="req">*</i></span><n-input v-model:value="form.storage.ossAccessKeyId" /></label>
<label><span>AccessKey Secret<i class="req">*</i></span><n-input v-model:value="form.storage.ossAccessKeySecret" type="password" show-password-on="click" /></label>
</template>
<label><span>CDN</span><n-input v-model:value="form.storage.cdnBaseUrl" placeholder="https://cdn.example.com" /></label>
<p class="hint">{{ tt('cdnHint') }}</p>
<p v-if="storageTest" class="test-result" :class="storageTest.ok ? 'ok' : 'fail'">{{ storageTest.msg }}</p>
</section>
<ul v-if="stepErrors.length" class="problems">
<li v-for="(p, i) in stepErrors" :key="i">{{ p }}</li>
</ul>
<n-alert v-if="error" type="error" class="mt" :title="error" />
<n-alert v-if="success" type="success" class="mt" :title="success" />
<div class="wizard-foot">
<n-button v-if="step > 0" :disabled="advancing || submitting" @click="step -= 1">{{ tt('prev') }}</n-button>
<div class="spacer" />
<n-button
type="primary"
:disabled="stepErrors.length > 0"
:loading="advancing || submitting"
@click="onNext"
>
{{ step === 2 ? (submitting ? tt('installing') : tt('install')) : tt('next') }}
</n-button>
</div>
</template>
</n-spin>
</div>
@@ -102,7 +124,7 @@
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue';
import { computed, onMounted, reactive, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import ThemeSwitch from '@/components/ThemeSwitch.vue';
import LangSwitch from '@/components/LangSwitch.vue';
@@ -135,8 +157,6 @@ const driverOptions = computed(() => [
{ label: 'OSS / S3', value: 'oss' },
]);
const baseTrim = computed(() => (form.baseUrl || '').replace(/\/+$/, ''));
const form = reactive<InstallForm>({
appName: tt('defaultAppName'),
baseUrl: location.origin,
@@ -155,8 +175,10 @@ const form = reactive<InstallForm>({
},
});
const step = ref(0);
const loading = ref(true);
const submitting = ref(false);
const advancing = ref(false);
const installed = ref(false);
const error = ref('');
const success = ref('');
@@ -167,6 +189,38 @@ const mysqlTest = ref<{ ok: boolean; msg: string } | null>(null);
const redisTest = ref<{ ok: boolean; msg: string } | null>(null);
const storageTest = ref<{ ok: boolean; msg: string } | null>(null);
const baseTrim = computed(() => (form.baseUrl || '').replace(/\/+$/, ''));
// 配置变化后作废旧的测试结果,需重新测试
watch(() => ({ ...form.mysql }), () => (mysqlTest.value = null), { deep: true });
watch(() => ({ ...form.redis }), () => (redisTest.value = null), { deep: true });
watch(() => ({ ...form.storage }), () => (storageTest.value = null), { deep: true });
// 当前步骤的问题清单:非空则禁用「下一步/安装」并逐条展示
const stepErrors = computed<string[]>(() => {
const errs: string[] = [];
if (step.value === 0) {
if (!form.appName.trim()) errs.push(tt('errAppName'));
if (!/^https?:\/\/.+/i.test(baseTrim.value)) errs.push(tt('errBaseUrl'));
if (!form.admin.username.trim()) errs.push(tt('errAdminUser'));
if (!form.admin.password || form.admin.password.length < 6) errs.push(tt('errAdminPwd'));
} else if (step.value === 1) {
if (!form.mysql.host.trim() || !form.mysql.port) errs.push(tt('errMysqlHost'));
if (!/^[A-Za-z0-9_]+$/.test(form.mysql.database || '')) errs.push(tt('errMysqlDb'));
if (!form.mysql.username.trim()) errs.push(tt('errMysqlUser'));
if (!form.redis.host.trim() || !form.redis.port) errs.push(tt('errRedisHost'));
} else {
if (form.storage.driver === 'local') {
if (!form.storage.localDir.trim()) errs.push(tt('errLocalDir'));
} else {
if (!form.storage.ossEndpoint.trim()) errs.push(tt('errOssEndpoint'));
if (!form.storage.ossBucket.trim()) errs.push(tt('errOssBucket'));
if (!form.storage.ossAccessKeyId.trim() || !form.storage.ossAccessKeySecret.trim()) errs.push(tt('errOssKey'));
}
}
return errs;
});
function goAdmin(): void {
location.href = '/admin';
}
@@ -186,10 +240,9 @@ async function post(path: string, payload: Record<string, unknown>): Promise<{ o
}
}
async function testMysql(): Promise<void> {
async function testMysql(): Promise<{ ok: boolean; msg: string }> {
testingMysql.value = true;
mysqlTest.value = null;
mysqlTest.value = await post('/api/install/test-connection', {
const result = await post('/api/install/test-connection', {
target: 'mysql',
host: form.mysql.host,
port: form.mysql.port,
@@ -197,26 +250,51 @@ async function testMysql(): Promise<void> {
username: form.mysql.username,
password: form.mysql.password,
});
mysqlTest.value = result;
testingMysql.value = false;
return result;
}
async function testRedis(): Promise<void> {
async function testRedis(): Promise<{ ok: boolean; msg: string }> {
testingRedis.value = true;
redisTest.value = null;
redisTest.value = await post('/api/install/test-connection', {
const result = await post('/api/install/test-connection', {
target: 'redis',
host: form.redis.host,
port: form.redis.port,
password: form.redis.password,
});
redisTest.value = result;
testingRedis.value = false;
return result;
}
async function testStorage(): Promise<void> {
async function testStorage(): Promise<{ ok: boolean; msg: string }> {
testingStorage.value = true;
storageTest.value = null;
storageTest.value = await post('/api/install/test-storage', { ...form.storage });
const result = await post('/api/install/test-storage', { ...form.storage });
storageTest.value = result;
testingStorage.value = false;
return result;
}
async function onNext(): Promise<void> {
error.value = '';
if (step.value === 0) {
step.value = 1;
return;
}
if (step.value === 1) {
// 进入下一步前自动测试数据库连接,全部通过才放行
advancing.value = true;
try {
const mysqlOk = mysqlTest.value?.ok ? mysqlTest.value : await testMysql();
const redisOk = redisTest.value?.ok ? redisTest.value : await testRedis();
if (mysqlOk.ok && redisOk.ok) step.value = 2;
} finally {
advancing.value = false;
}
return;
}
await submit();
}
onMounted(async () => {
@@ -259,6 +337,9 @@ async function submit(): Promise<void> {
success.value = '';
submitting.value = true;
try {
// 安装前先确认存储可用
const storageOk = storageTest.value?.ok ? storageTest.value : await testStorage();
if (!storageOk.ok) return;
const res = await fetch('/api/install', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -288,7 +369,7 @@ async function submit(): Promise<void> {
}
.install-card {
width: 100%;
max-width: 1180px;
max-width: 720px;
background: var(--card-bg, #fff);
border: 1px solid var(--border, #d9e0ea);
border-radius: 12px;
@@ -317,10 +398,8 @@ async function submit(): Promise<void> {
font-size: 13px;
color: var(--n-text-color-3, #6a7687);
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 14px;
.steps {
margin-bottom: 16px;
}
.box {
border: 1px solid var(--border, #e1e7f0);
@@ -410,6 +489,25 @@ async function submit(): Promise<void> {
.test-result.fail {
color: #d03050;
}
.problems {
margin: 10px 0 0;
padding: 8px 12px 8px 28px;
border: 1px solid rgba(208, 48, 80, 0.25);
border-radius: 8px;
background: rgba(208, 48, 80, 0.06);
color: #d03050;
font-size: 12px;
line-height: 1.8;
}
.wizard-foot {
display: flex;
align-items: center;
gap: 12px;
margin-top: 16px;
}
.spacer {
flex: 1;
}
.mt {
margin-top: 14px;
}