feat: 安装向导改为三步分段引导并说明对外访问地址填写方式
基础配置/数据库/存储三步走:当前步有未填或不合法项时禁用下一步并逐条列出问题; 数据库步点下一步自动测试 MySQL/Redis,全部通过才放行; 存储步按钮变为「安装」,安装前自动先做存储读写测试;去掉右上角开始安装按钮; 对外访问地址补充说明(域名 / 服务器IP:端口 / 本地默认),配置变更后自动作废旧测试结果。
This commit is contained in:
@@ -192,9 +192,28 @@
|
|||||||
"base": "Base",
|
"base": "Base",
|
||||||
"appName": "Platform Name",
|
"appName": "Platform Name",
|
||||||
"baseUrl": "Public URL",
|
"baseUrl": "Public URL",
|
||||||
|
"baseUrlHint": "The address users actually visit: use your domain if bound (e.g. https://art.example.com); otherwise server IP with port (e.g. http://1.2.3.4:3000); keep the default for local trials.",
|
||||||
"urlAdmin": "Admin",
|
"urlAdmin": "Admin",
|
||||||
"urlClient": "Client",
|
"urlClient": "Client",
|
||||||
"dbCard": "Database",
|
"dbCard": "Database",
|
||||||
|
"stepBase": "Basics",
|
||||||
|
"stepDb": "Database",
|
||||||
|
"stepStorage": "Storage",
|
||||||
|
"prev": "Back",
|
||||||
|
"next": "Next",
|
||||||
|
"install": "Install",
|
||||||
|
"errAppName": "Platform name is required",
|
||||||
|
"errBaseUrl": "Public URL must start with http:// or https://",
|
||||||
|
"errAdminUser": "Admin account is required",
|
||||||
|
"errAdminPwd": "Admin password must be at least 6 characters",
|
||||||
|
"errMysqlHost": "MySQL host and port are required",
|
||||||
|
"errMysqlDb": "MySQL database name allows letters, digits and underscore only",
|
||||||
|
"errMysqlUser": "MySQL username is required",
|
||||||
|
"errRedisHost": "Redis host and port are required",
|
||||||
|
"errLocalDir": "Local storage directory is required",
|
||||||
|
"errOssEndpoint": "OSS endpoint is required",
|
||||||
|
"errOssBucket": "OSS bucket is required",
|
||||||
|
"errOssKey": "OSS AccessKey ID / Secret are required",
|
||||||
"host": "Host",
|
"host": "Host",
|
||||||
"port": "Port",
|
"port": "Port",
|
||||||
"database": "Database",
|
"database": "Database",
|
||||||
|
|||||||
@@ -192,9 +192,28 @@
|
|||||||
"base": "基础",
|
"base": "基础",
|
||||||
"appName": "平台名称",
|
"appName": "平台名称",
|
||||||
"baseUrl": "对外访问地址",
|
"baseUrl": "对外访问地址",
|
||||||
|
"baseUrlHint": "用户实际访问系统的地址:已绑定域名填域名(如 https://art.example.com);未绑定域名可填服务器 IP 加端口(如 http://1.2.3.4:3000);本地体验保持默认即可。",
|
||||||
"urlAdmin": "后台",
|
"urlAdmin": "后台",
|
||||||
"urlClient": "客户端",
|
"urlClient": "客户端",
|
||||||
"dbCard": "数据库",
|
"dbCard": "数据库",
|
||||||
|
"stepBase": "基础配置",
|
||||||
|
"stepDb": "数据库",
|
||||||
|
"stepStorage": "存储",
|
||||||
|
"prev": "上一步",
|
||||||
|
"next": "下一步",
|
||||||
|
"install": "安装",
|
||||||
|
"errAppName": "平台名称不能为空",
|
||||||
|
"errBaseUrl": "对外访问地址需以 http:// 或 https:// 开头",
|
||||||
|
"errAdminUser": "管理员账号不能为空",
|
||||||
|
"errAdminPwd": "管理员密码至少 6 位",
|
||||||
|
"errMysqlHost": "MySQL 主机与端口不能为空",
|
||||||
|
"errMysqlDb": "MySQL 数据库名仅允许字母、数字和下划线",
|
||||||
|
"errMysqlUser": "MySQL 账号不能为空",
|
||||||
|
"errRedisHost": "Redis 主机与端口不能为空",
|
||||||
|
"errLocalDir": "本地存储目录不能为空",
|
||||||
|
"errOssEndpoint": "OSS Endpoint 不能为空",
|
||||||
|
"errOssBucket": "OSS Bucket 不能为空",
|
||||||
|
"errOssKey": "OSS AccessKey ID / Secret 不能为空",
|
||||||
"host": "主机",
|
"host": "主机",
|
||||||
"port": "端口",
|
"port": "端口",
|
||||||
"database": "数据库",
|
"database": "数据库",
|
||||||
|
|||||||
@@ -9,9 +9,6 @@
|
|||||||
<div class="head-actions">
|
<div class="head-actions">
|
||||||
<lang-switch />
|
<lang-switch />
|
||||||
<theme-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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -28,11 +25,18 @@
|
|||||||
</n-result>
|
</n-result>
|
||||||
|
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="grid">
|
<n-steps :current="step + 1" size="small" class="steps">
|
||||||
<section class="box">
|
<n-step :title="tt('stepBase')" />
|
||||||
|
<n-step :title="tt('stepDb')" />
|
||||||
|
<n-step :title="tt('stepStorage')" />
|
||||||
|
</n-steps>
|
||||||
|
|
||||||
|
<!-- 第 1 步:基础配置(含管理员) -->
|
||||||
|
<section v-show="step === 0" class="box">
|
||||||
<h2>{{ tt('base') }}</h2>
|
<h2>{{ tt('base') }}</h2>
|
||||||
<label><span>{{ tt('appName') }}<i class="req">*</i></span><n-input v-model:value="form.appName" /></label>
|
<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>
|
<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 class="urls">
|
||||||
<div><span>{{ tt('urlAdmin') }}</span>{{ baseTrim }}/admin</div>
|
<div><span>{{ tt('urlAdmin') }}</span>{{ baseTrim }}/admin</div>
|
||||||
<div><span>{{ tt('urlClient') }}</span>{{ baseTrim }}/trace</div>
|
<div><span>{{ tt('urlClient') }}</span>{{ baseTrim }}/trace</div>
|
||||||
@@ -44,7 +48,8 @@
|
|||||||
<label><span>{{ tt('realName') }}</span><n-input v-model:value="form.admin.realName" /></label>
|
<label><span>{{ tt('realName') }}</span><n-input v-model:value="form.admin.realName" /></label>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="box">
|
<!-- 第 2 步:数据库(MySQL + Redis) -->
|
||||||
|
<section v-show="step === 1" class="box">
|
||||||
<h2>{{ tt('dbCard') }}</h2>
|
<h2>{{ tt('dbCard') }}</h2>
|
||||||
|
|
||||||
<div class="sub-row">
|
<div class="sub-row">
|
||||||
@@ -68,7 +73,8 @@
|
|||||||
<p v-if="redisTest" class="test-result" :class="redisTest.ok ? 'ok' : 'fail'">{{ redisTest.msg }}</p>
|
<p v-if="redisTest" class="test-result" :class="redisTest.ok ? 'ok' : 'fail'">{{ redisTest.msg }}</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="box">
|
<!-- 第 3 步:存储 -->
|
||||||
|
<section v-show="step === 2" class="box">
|
||||||
<div class="box-head">
|
<div class="box-head">
|
||||||
<h2>{{ tt('storage') }}</h2>
|
<h2>{{ tt('storage') }}</h2>
|
||||||
<n-button size="tiny" :loading="testingStorage" @click="testStorage">{{ tt('testConnection') }}</n-button>
|
<n-button size="tiny" :loading="testingStorage" @click="testStorage">{{ tt('testConnection') }}</n-button>
|
||||||
@@ -91,10 +97,26 @@
|
|||||||
<p class="hint">{{ tt('cdnHint') }}</p>
|
<p class="hint">{{ tt('cdnHint') }}</p>
|
||||||
<p v-if="storageTest" class="test-result" :class="storageTest.ok ? 'ok' : 'fail'">{{ storageTest.msg }}</p>
|
<p v-if="storageTest" class="test-result" :class="storageTest.ok ? 'ok' : 'fail'">{{ storageTest.msg }}</p>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
|
||||||
|
<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="error" type="error" class="mt" :title="error" />
|
||||||
<n-alert v-if="success" type="success" class="mt" :title="success" />
|
<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>
|
</template>
|
||||||
</n-spin>
|
</n-spin>
|
||||||
</div>
|
</div>
|
||||||
@@ -102,7 +124,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<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 { useI18n } from 'vue-i18n';
|
||||||
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
||||||
import LangSwitch from '@/components/LangSwitch.vue';
|
import LangSwitch from '@/components/LangSwitch.vue';
|
||||||
@@ -135,8 +157,6 @@ const driverOptions = computed(() => [
|
|||||||
{ label: 'OSS / S3', value: 'oss' },
|
{ label: 'OSS / S3', value: 'oss' },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const baseTrim = computed(() => (form.baseUrl || '').replace(/\/+$/, ''));
|
|
||||||
|
|
||||||
const form = reactive<InstallForm>({
|
const form = reactive<InstallForm>({
|
||||||
appName: tt('defaultAppName'),
|
appName: tt('defaultAppName'),
|
||||||
baseUrl: location.origin,
|
baseUrl: location.origin,
|
||||||
@@ -155,8 +175,10 @@ const form = reactive<InstallForm>({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const step = ref(0);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const submitting = ref(false);
|
const submitting = ref(false);
|
||||||
|
const advancing = ref(false);
|
||||||
const installed = ref(false);
|
const installed = ref(false);
|
||||||
const error = ref('');
|
const error = ref('');
|
||||||
const success = 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 redisTest = ref<{ ok: boolean; msg: string } | null>(null);
|
||||||
const storageTest = 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 {
|
function goAdmin(): void {
|
||||||
location.href = '/admin';
|
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;
|
testingMysql.value = true;
|
||||||
mysqlTest.value = null;
|
const result = await post('/api/install/test-connection', {
|
||||||
mysqlTest.value = await post('/api/install/test-connection', {
|
|
||||||
target: 'mysql',
|
target: 'mysql',
|
||||||
host: form.mysql.host,
|
host: form.mysql.host,
|
||||||
port: form.mysql.port,
|
port: form.mysql.port,
|
||||||
@@ -197,26 +250,51 @@ async function testMysql(): Promise<void> {
|
|||||||
username: form.mysql.username,
|
username: form.mysql.username,
|
||||||
password: form.mysql.password,
|
password: form.mysql.password,
|
||||||
});
|
});
|
||||||
|
mysqlTest.value = result;
|
||||||
testingMysql.value = false;
|
testingMysql.value = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testRedis(): Promise<void> {
|
async function testRedis(): Promise<{ ok: boolean; msg: string }> {
|
||||||
testingRedis.value = true;
|
testingRedis.value = true;
|
||||||
redisTest.value = null;
|
const result = await post('/api/install/test-connection', {
|
||||||
redisTest.value = await post('/api/install/test-connection', {
|
|
||||||
target: 'redis',
|
target: 'redis',
|
||||||
host: form.redis.host,
|
host: form.redis.host,
|
||||||
port: form.redis.port,
|
port: form.redis.port,
|
||||||
password: form.redis.password,
|
password: form.redis.password,
|
||||||
});
|
});
|
||||||
|
redisTest.value = result;
|
||||||
testingRedis.value = false;
|
testingRedis.value = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testStorage(): Promise<void> {
|
async function testStorage(): Promise<{ ok: boolean; msg: string }> {
|
||||||
testingStorage.value = true;
|
testingStorage.value = true;
|
||||||
storageTest.value = null;
|
const result = await post('/api/install/test-storage', { ...form.storage });
|
||||||
storageTest.value = await post('/api/install/test-storage', { ...form.storage });
|
storageTest.value = result;
|
||||||
testingStorage.value = false;
|
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 () => {
|
onMounted(async () => {
|
||||||
@@ -259,6 +337,9 @@ async function submit(): Promise<void> {
|
|||||||
success.value = '';
|
success.value = '';
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
try {
|
try {
|
||||||
|
// 安装前先确认存储可用
|
||||||
|
const storageOk = storageTest.value?.ok ? storageTest.value : await testStorage();
|
||||||
|
if (!storageOk.ok) return;
|
||||||
const res = await fetch('/api/install', {
|
const res = await fetch('/api/install', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
@@ -288,7 +369,7 @@ async function submit(): Promise<void> {
|
|||||||
}
|
}
|
||||||
.install-card {
|
.install-card {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 1180px;
|
max-width: 720px;
|
||||||
background: var(--card-bg, #fff);
|
background: var(--card-bg, #fff);
|
||||||
border: 1px solid var(--border, #d9e0ea);
|
border: 1px solid var(--border, #d9e0ea);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
@@ -317,10 +398,8 @@ async function submit(): Promise<void> {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: var(--n-text-color-3, #6a7687);
|
color: var(--n-text-color-3, #6a7687);
|
||||||
}
|
}
|
||||||
.grid {
|
.steps {
|
||||||
display: grid;
|
margin-bottom: 16px;
|
||||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
||||||
gap: 14px;
|
|
||||||
}
|
}
|
||||||
.box {
|
.box {
|
||||||
border: 1px solid var(--border, #e1e7f0);
|
border: 1px solid var(--border, #e1e7f0);
|
||||||
@@ -410,6 +489,25 @@ async function submit(): Promise<void> {
|
|||||||
.test-result.fail {
|
.test-result.fail {
|
||||||
color: #d03050;
|
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 {
|
.mt {
|
||||||
margin-top: 14px;
|
margin-top: 14px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user