refactor: 简化首次安装部署,安装向导并入后台并自动建库

This commit is contained in:
Nixevol
2026-07-08 17:46:34 +08:00
parent 3517ad9088
commit b498a49a9b
21 changed files with 555 additions and 486 deletions
+26
View File
@@ -4,6 +4,12 @@ import { loadingBar } from '@/utils/feedback';
import MainLayout from '@/layouts/MainLayout.vue';
export const routes: RouteRecordRaw[] = [
{
path: '/install',
name: 'install',
component: () => import('@/views/Install.vue'),
meta: { public: true },
},
{
path: '/login',
name: 'login',
@@ -39,8 +45,28 @@ const router = createRouter({
routes,
});
// 首次运行探测:未安装则强制进入安装向导,安装完成后不再进入
let installResolved = false;
let needInstall = false;
async function ensureInstallStatus(): Promise<void> {
if (installResolved) return;
try {
const res = await fetch('/api/install/status');
const body = await res.json();
needInstall = body?.data?.installed === false;
} catch {
needInstall = false;
}
installResolved = true;
}
router.beforeEach(async (to) => {
loadingBar.start();
await ensureInstallStatus();
if (needInstall) {
return to.name === 'install' ? true : { name: 'install' };
}
if (to.name === 'install') return { name: 'dashboard' };
const auth = useAuthStore();
if (to.meta.public) {
if (auth.isLoggedIn && to.name === 'login') return { name: 'dashboard' };