feat: 用安装页和编排完成部署,并整理登录页

This commit is contained in:
2026-10-30 09:49:20 +08:00
parent 7ed299bbf6
commit 3fa4f83180
30 changed files with 635 additions and 121 deletions
+4 -2
View File
@@ -39,7 +39,9 @@ const overrides = computed<GlobalThemeOverrides>(() => ({
</script>
<template>
<n-config-provider :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="overrides">
<router-view />
<n-config-provider class="app-root" :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="overrides">
<div class="app-root">
<router-view />
</div>
</n-config-provider>
</template>
+8 -20
View File
@@ -3,7 +3,7 @@ import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { NAlert, NButton, NInput } from "naive-ui";
import { api, saveSession } from "../../shared/http";
import { setThemeChoice, themeChoice, type ThemeChoice } from "../../shared/theme";
import ThemeButton from "../../shell/ThemeButton.vue";
const props = defineProps<{ purpose?: "login" | "pool" }>();
const emit = defineEmits<{ done: [] }>();
@@ -18,11 +18,6 @@ const smsCode = ref("");
const smsRequired = ref(false);
const errorText = ref("");
const busy = ref(false);
const themes = [
{ label: "跟随系统", value: "system" },
{ label: "深色", value: "dark" },
{ label: "浅色", value: "light" },
];
onMounted(async () => {
if (props.purpose === "pool") {
@@ -132,23 +127,16 @@ async function finishNqi() {
busy.value = false;
}
}
function chooseTheme(value: ThemeChoice) {
setThemeChoice(value);
}
</script>
<template>
<div :class="purpose === 'pool' ? '' : 'gate'">
<div class="gate-card">
<h1 style="margin: 0 0 16px; font-size: 20px; display: flex; justify-content: space-between; align-items: center;">
<span>{{ purpose === "pool" ? "添加账号" : "DecomEval" }}</span>
<select v-if="purpose !== 'pool'" :value="themeChoice" @change="chooseTheme(($event.target as HTMLSelectElement).value as ThemeChoice)">
<option value="system">跟随系统</option>
<option value="dark">深色</option>
<option value="light">浅色</option>
</select>
</h1>
<ThemeButton v-if="purpose !== 'pool'" />
<section class="gate-card">
<div class="gate-brand">
<div class="brand-mark" aria-hidden="true">D</div>
<h1>{{ purpose === "pool" ? "添加账号" : "DecomEval" }}</h1>
</div>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
<div class="form-grid">
<label>账号</label>
@@ -175,6 +163,6 @@ function chooseTheme(value: ThemeChoice) {
<n-button v-if="captchaUrl" type="primary" :loading="busy" @click="finishNqi">登录</n-button>
</template>
</div>
</div>
</section>
</div>
</template>
+90
View File
@@ -0,0 +1,90 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { NAlert, NButton, NInput, NInputNumber, NSwitch } from "naive-ui";
import { api } from "../../shared/http";
import { markInstalled } from "../../shared/installState";
import ThemeButton from "../../shell/ThemeButton.vue";
const router = useRouter();
const host = ref("127.0.0.1");
const port = ref(5432);
const database = ref("decom");
const username = ref("postgres");
const password = ref("nixevol@242520");
const adminUsername = ref("admin");
const adminPassword = ref("nixevol@242520");
const separateWorker = ref(true);
const errorText = ref("");
const busy = ref(false);
onMounted(async () => {
const status = await api<{ defaults?: { host?: string; port?: number; database?: string; username?: string } }>("/api/install/status");
const defaults = status.defaults;
if (!defaults) return;
if (defaults.host) host.value = defaults.host;
if (defaults.port) port.value = defaults.port;
if (defaults.database) database.value = defaults.database;
if (defaults.username) username.value = defaults.username;
});
async function submit() {
busy.value = true;
errorText.value = "";
try {
await api("/api/install", {
method: "POST",
body: JSON.stringify({
host: host.value,
port: port.value,
database: database.value,
username: username.value,
password: password.value,
adminUsername: adminUsername.value,
adminPassword: adminPassword.value,
separateWorker: separateWorker.value,
}),
});
markInstalled();
router.push("/login");
} catch (error) {
errorText.value = error instanceof Error ? error.message : "安装失败";
} finally {
busy.value = false;
}
}
</script>
<template>
<div class="gate">
<ThemeButton />
<section class="gate-card wide">
<div class="gate-brand">
<div class="brand-mark" aria-hidden="true">D</div>
<h1>安装 DecomEval</h1>
</div>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
<div class="form-grid">
<label>数据库主机</label>
<n-input v-model:value="host" />
<label>端口</label>
<n-input-number v-model:value="port" :min="1" :max="65535" />
<label>数据库名</label>
<n-input v-model:value="database" />
<label>数据库用户</label>
<n-input v-model:value="username" />
<label>数据库密码</label>
<n-input v-model:value="password" type="password" />
<label>管理员账号</label>
<n-input v-model:value="adminUsername" />
<label>管理员密码</label>
<n-input v-model:value="adminPassword" type="password" />
<label>独立排队进程</label>
<n-switch v-model:value="separateWorker" />
</div>
<div style="margin-top: 16px; display: flex; justify-content: flex-end;">
<n-button type="primary" :loading="busy" @click="submit">完成安装</n-button>
</div>
</section>
</div>
</template>
+8 -1
View File
@@ -1,6 +1,7 @@
import { createApp } from "vue";
import { createRouter, createWebHistory } from "vue-router";
import App from "./App.vue";
import InstallView from "./features/install/InstallView.vue";
import LoginView from "./features/auth/LoginView.vue";
import TasksView from "./features/user/TasksView.vue";
import SettingsView from "./features/admin/SettingsView.vue";
@@ -8,11 +9,13 @@ import UsersView from "./features/admin/UsersView.vue";
import PoolView from "./features/admin/PoolView.vue";
import SourcesView from "./features/admin/SourcesView.vue";
import { token } from "./shared/http";
import { installed, refreshInstalled } from "./shared/installState";
import "./styles.css";
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: "/install", component: InstallView },
{ path: "/login", component: LoginView },
{ path: "/", redirect: "/tasks" },
{ path: "/tasks", component: TasksView, meta: { role: "user" } },
@@ -23,7 +26,11 @@ const router = createRouter({
],
});
router.beforeEach((to) => {
router.beforeEach(async (to) => {
if (installed === null) await refreshInstalled();
if (!installed && to.path !== "/install") return "/install";
if (installed && to.path === "/install") return "/login";
if (to.path === "/install") return true;
if (to.path === "/login") return token() ? "/" : true;
if (!token()) return "/login";
const role = sessionStorage.getItem("decom-role");
+11
View File
@@ -0,0 +1,11 @@
export let installed: boolean | null = null;
export async function refreshInstalled() {
const response = await fetch("/api/install/status");
installed = Boolean((await response.json()).installed);
return installed;
}
export function markInstalled() {
installed = true;
}
+6
View File
@@ -22,3 +22,9 @@ export function setThemeChoice(choice: ThemeChoice) {
themeChoice.value = choice;
localStorage.setItem(STORAGE_KEY, choice);
}
export function cycleTheme() {
const order: ThemeChoice[] = ["system", "dark", "light"];
const index = order.indexOf(themeChoice.value);
setThemeChoice(order[(index + 1) % order.length]);
}
+2 -12
View File
@@ -1,8 +1,7 @@
<script setup lang="ts">
import { useRoute, useRouter } from "vue-router";
import { NSelect } from "naive-ui";
import { api, clearSession, token } from "../shared/http";
import { setThemeChoice, themeChoice, type ThemeChoice } from "../shared/theme";
import ThemeButton from "./ThemeButton.vue";
const route = useRoute();
const router = useRouter();
@@ -16,15 +15,6 @@ const items = role === "admin"
{ label: "采集", path: "/admin/sources" },
]
: [{ label: "任务", path: "/tasks" }];
const themes = [
{ label: "跟随系统", value: "system" },
{ label: "深色", value: "dark" },
{ label: "浅色", value: "light" },
];
function chooseTheme(value: ThemeChoice) {
setThemeChoice(value);
}
async function logout() {
if (token()) {
@@ -48,7 +38,7 @@ async function logout() {
</nav>
<div class="sider-foot">
<div class="who">{{ name }}</div>
<n-select :value="themeChoice" :options="themes" size="small" @update:value="chooseTheme" />
<ThemeButton />
<button class="text-button" @click="logout">退出</button>
</div>
</aside>
+31
View File
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { NButton, NIcon, NTooltip } from "naive-ui";
import { cycleTheme, themeChoice } from "../shared/theme";
const label = { system: "跟随系统", dark: "深色", light: "浅色" } as const;
</script>
<template>
<n-tooltip>
<template #trigger>
<n-button class="theme-switch" quaternary circle :aria-label="label[themeChoice]" @click="cycleTheme">
<template #icon>
<n-icon>
<svg v-if="themeChoice === 'system'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
<rect x="3" y="4" width="18" height="12" rx="1.5" />
<path d="M8 20h8M12 16v4" />
</svg>
<svg v-else-if="themeChoice === 'dark'" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
<path d="M16 3.2A8.5 8.5 0 1 0 20.8 14 7 7 0 0 1 16 3.2z" />
</svg>
<svg v-else viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8">
<circle cx="12" cy="12" r="4" />
<path d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5 5l1.6 1.6M17.4 17.4 19 19M19 5l-1.6 1.6M6.6 17.4 5 19" />
</svg>
</n-icon>
</template>
</n-button>
</template>
{{ label[themeChoice] }}
</n-tooltip>
</template>
+37 -4
View File
@@ -5,7 +5,7 @@
font-size: 14px;
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
html, body, #app, .n-config-provider, .app-root { margin: 0; height: 100%; }
body { background: var(--bg); }
button, input, select { font: inherit; }
::selection { background: var(--accent-soft); }
@@ -64,7 +64,8 @@ button, input, select { font: inherit; }
.topbar h1 { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 6px; }
.content { padding: 16px; overflow: auto; }
.panel { background: var(--panel); border: 1px solid var(--line); }
.filters, .form-grid { display: grid; grid-template-columns: 96px minmax(0, 280px); gap: 8px 12px; align-items: center; }
.filters, .form-grid { display: grid; grid-template-columns: 112px minmax(0, 280px); gap: 8px 12px; align-items: center; }
.gate-card.wide .form-grid { grid-template-columns: 112px minmax(0, 1fr); }
.hint {
width: 16px;
height: 16px;
@@ -76,13 +77,45 @@ button, input, select { font: inherit; }
text-align: center;
cursor: default;
}
.app-root { height: 100%; }
.gate {
min-height: 100%;
position: relative;
height: 100%;
min-height: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 32px 16px;
overflow: auto;
background: var(--bg);
}
.gate .theme-switch { position: absolute; top: 16px; right: 16px; }
.sider-foot .theme-switch { position: static; align-self: flex-start; }
.gate-card {
width: min(440px, 100%);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 4px;
padding: 28px 28px 22px;
}
.gate-card.wide { width: min(560px, 100%); }
.gate-brand {
display: flex;
gap: 14px;
align-items: center;
justify-content: center;
margin-bottom: 22px;
}
.gate-brand h1 { margin: 0; font-size: 20px; }
.brand-mark {
width: 36px;
height: 36px;
border-radius: 4px;
border: 1px solid var(--accent);
color: var(--accent);
display: grid;
place-items: center;
font-weight: 650;
}
.gate-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); padding: 28px; }
.captcha { height: 40px; cursor: pointer; }
.row-actions { display: flex; gap: 8px; }