fix: 管理页对齐表单,操作用提示条和确认框

This commit is contained in:
2026-10-30 11:37:33 +08:00
parent 564968472d
commit 06549316f9
7 changed files with 173 additions and 65 deletions
+8 -4
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, watch } from "vue";
import { darkTheme, dateZhCN, NConfigProvider, zhCN } from "naive-ui";
import { darkTheme, dateZhCN, NConfigProvider, NDialogProvider, NMessageProvider, zhCN } from "naive-ui";
import type { GlobalThemeOverrides } from "naive-ui";
import { isDark } from "./shared/theme";
@@ -40,8 +40,12 @@ const overrides = computed<GlobalThemeOverrides>(() => ({
<template>
<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-message-provider>
<n-dialog-provider>
<div class="app-root">
<router-view />
</div>
</n-dialog-provider>
</n-message-provider>
</n-config-provider>
</template>
+29 -6
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NModal, NSelect } from "naive-ui";
import { NButton, NModal, NSelect, useDialog, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import LoginView from "../auth/LoginView.vue";
import { api } from "../../shared/http";
@@ -8,6 +8,8 @@ import { api } from "../../shared/http";
interface Account { id: number; loginId: string; userName: string; cityName: string; role: string; sessionOpen: boolean; credentialValid: boolean }
const accounts = ref<Account[]>([]);
const show = ref(false);
const dialog = useDialog();
const message = useMessage();
async function load() {
const result = await api<{ accounts: Account[] }>("/api/admin/pool");
@@ -15,13 +17,34 @@ async function load() {
}
async function setRole(id: number, role: string) {
await api(`/api/admin/pool/${id}/role`, { method: "PUT", body: JSON.stringify({ role }) });
await load();
try {
await api(`/api/admin/pool/${id}/role`, { method: "PUT", body: JSON.stringify({ role }) });
message.success("已保存");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "保存失败");
}
}
async function remove(id: number) {
await api(`/api/admin/pool/${id}`, { method: "DELETE" });
await load();
try {
await api(`/api/admin/pool/${id}`, { method: "DELETE" });
message.success("已删除");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "删除失败");
}
}
function confirmRemove(account: Account) {
dialog.warning({
title: "删除账号",
content: `从账号池删除 ${account.loginId}?`,
positiveText: "删除",
negativeText: "取消",
positiveButtonProps: { type: "error" },
onPositiveClick: () => remove(account.id),
});
}
onMounted(load);
@@ -57,7 +80,7 @@ onMounted(load);
<td>
<n-select :value="account.role" size="small" style="width: 120px" :options="[{ label: '用户', value: 'user' }, { label: '管理员', value: 'admin' }]" @update:value="(value) => setRole(account.id, value)" />
</td>
<td><n-button size="small" quaternary @click="remove(account.id)">删除</n-button></td>
<td><n-button size="small" quaternary @click="confirmRemove(account)">删除</n-button></td>
</tr>
</tbody>
</table>
+48 -30
View File
@@ -1,31 +1,41 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInputNumber, NRadio, NRadioGroup } from "naive-ui";
import { NButton, NInputNumber, NRadio, NRadioGroup, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
const message = useMessage();
const mode = ref("local");
const seconds = ref(300);
const concurrency = ref(4);
const message = ref("");
const saving = ref(false);
const loaded = ref(false);
async function load() {
const result = await api<{ loginMode: string; credentialRefreshSeconds: number; workerConcurrency: number }>("/api/admin/settings");
mode.value = result.loginMode;
seconds.value = result.credentialRefreshSeconds;
concurrency.value = result.workerConcurrency;
try {
const result = await api<{ loginMode: string; credentialRefreshSeconds: number; workerConcurrency: number }>("/api/admin/settings");
mode.value = result.loginMode;
seconds.value = result.credentialRefreshSeconds;
concurrency.value = result.workerConcurrency;
loaded.value = true;
} catch (error) {
message.error(error instanceof Error ? error.message : "设置没有获取到");
}
}
async function save() {
message.value = "";
if (saving.value || !loaded.value) return;
saving.value = true;
try {
await api("/api/admin/settings", {
method: "PUT",
body: JSON.stringify({ loginMode: mode.value, credentialRefreshSeconds: seconds.value, workerConcurrency: concurrency.value }),
});
message.value = "已保存";
message.success("已保存");
} catch (error) {
message.value = error instanceof Error ? error.message : "保存失败";
message.error(error instanceof Error ? error.message : "保存失败");
} finally {
saving.value = false;
}
}
@@ -35,28 +45,36 @@ onMounted(load);
<template>
<Shell>
<section class="page admin-page">
<header class="page-head">
<h2>设置</h2>
<n-button type="primary" @click="save">保存</n-button>
</header>
<div class="settings-form">
<div class="form-row">
<label>方式</label>
<n-radio-group v-model:value="mode">
<n-radio value="local">自有账号</n-radio>
<n-radio value="nqi">大数据平台账号</n-radio>
</n-radio-group>
<form class="settings-form" @submit.prevent="save">
<header class="page-head">
<h2>设置</h2>
<n-button type="primary" attr-type="submit" :loading="saving" :disabled="!loaded">保存</n-button>
</header>
<div v-if="loaded" class="admin-scroll">
<div class="form-row">
<label for="login-mode">方式</label>
<n-radio-group id="login-mode" v-model:value="mode">
<n-radio value="local">自有账号</n-radio>
<n-radio value="nqi">大数据平台账号</n-radio>
</n-radio-group>
</div>
<div class="form-row">
<label for="refresh-seconds">刷新间隔</label>
<div class="setting-control">
<n-input-number id="refresh-seconds" v-model:value="seconds" button-placement="both" :min="60" :max="86400" :precision="0" />
<span class="setting-unit">秒</span>
</div>
</div>
<div class="form-row">
<label for="worker-concurrency">并行数量</label>
<div class="setting-control">
<n-input-number id="worker-concurrency" v-model:value="concurrency" button-placement="both" :min="1" :max="32" :precision="0" />
<span class="setting-unit">个</span>
</div>
</div>
</div>
<div class="form-row">
<label>刷新间隔</label>
<n-input-number v-model:value="seconds" :min="60" :max="86400" :show-button="false" />
</div>
<div class="form-row">
<label>并行数量</label>
<n-input-number v-model:value="concurrency" :min="1" :max="32" :show-button="false" />
</div>
<p v-if="message">{{ message }}</p>
</div>
<p v-else class="admin-status">正在获取</p>
</form>
</section>
</Shell>
</template>
+24 -5
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInput, NInputNumber, NModal, NSelect, NSwitch } from "naive-ui";
import { NAlert, NButton, NInput, NInputNumber, NModal, NSelect, NSwitch, useDialog, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
@@ -28,6 +28,8 @@ const password = ref("");
const path = ref("");
const url = ref("");
const errorText = ref("");
const dialog = useDialog();
const message = useMessage();
function reset(source?: Source) {
editing.value = source || null;
@@ -64,6 +66,7 @@ async function save() {
await api("/api/admin/sources", { method: "POST", body: JSON.stringify(body) });
}
show.value = false;
message.success("已保存");
await load();
} catch (error) {
errorText.value = error instanceof Error ? error.message : "保存失败";
@@ -72,8 +75,24 @@ async function save() {
}
async function remove(id: number) {
await api(`/api/admin/sources/${id}`, { method: "DELETE" });
await load();
try {
await api(`/api/admin/sources/${id}`, { method: "DELETE" });
message.success("已删除");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "删除失败");
}
}
function confirmRemove(source: Source) {
dialog.warning({
title: "删除采集",
content: `删除 ${source.name}?`,
positiveText: "删除",
negativeText: "取消",
positiveButtonProps: { type: "error" },
onPositiveClick: () => remove(source.id),
});
}
onMounted(load);
@@ -105,7 +124,7 @@ onMounted(load);
<td>{{ source.lastError || (source.enabled ? "启用" : "停用") }}</td>
<td>
<n-button size="small" quaternary @click="reset(source)">编辑</n-button>
<n-button size="small" quaternary @click="remove(source.id)">删除</n-button>
<n-button size="small" quaternary @click="confirmRemove(source)">删除</n-button>
</td>
</tr>
</tbody>
@@ -129,7 +148,7 @@ onMounted(load);
<template v-else>
<div class="form-row"><label>地址</label><n-input v-model:value="url" /></div>
</template>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
</n-modal>
</Shell>
</template>
+24 -5
View File
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInput, NModal, NSelect } from "naive-ui";
import { NAlert, NButton, NInput, NModal, NSelect, useDialog, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
interface User { id: number; username: string; role: string }
const dialog = useDialog();
const message = useMessage();
const users = ref<User[]>([]);
const show = ref(false);
const username = ref("");
@@ -24,6 +26,7 @@ async function create() {
show.value = false;
username.value = "";
password.value = "";
message.success("已添加");
await load();
} catch (error) {
errorText.value = error instanceof Error ? error.message : "添加失败";
@@ -32,8 +35,24 @@ async function create() {
}
async function remove(id: number) {
await api(`/api/admin/users/${id}`, { method: "DELETE" });
await load();
try {
await api(`/api/admin/users/${id}`, { method: "DELETE" });
message.success("已删除");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "删除失败");
}
}
function confirmRemove(user: User) {
dialog.warning({
title: "删除用户",
content: `删除账号 ${user.username}?`,
positiveText: "删除",
negativeText: "取消",
positiveButtonProps: { type: "error" },
onPositiveClick: () => remove(user.id),
});
}
onMounted(load);
@@ -59,7 +78,7 @@ onMounted(load);
<tr v-for="user in users" :key="user.id">
<td>{{ user.username }}</td>
<td>{{ user.role === "admin" ? "管理员" : "用户" }}</td>
<td><n-button size="small" quaternary @click="remove(user.id)">删除</n-button></td>
<td><n-button size="small" quaternary @click="confirmRemove(user)">删除</n-button></td>
</tr>
</tbody>
</table>
@@ -70,7 +89,7 @@ onMounted(load);
<div class="form-row"><label>账号</label><n-input v-model:value="username" /></div>
<div class="form-row"><label>密码</label><n-input v-model:value="password" type="password" /></div>
<div class="form-row"><label>角色</label><n-select v-model:value="role" :options="[{ label: '用户', value: 'user' }, { label: '管理员', value: 'admin' }]" /></div>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
</n-modal>
</Shell>
</template>
+25 -12
View File
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NInput, NModal, NSelect } from "naive-ui";
import { NAlert, NButton, NInput, NModal, NSelect, useMessage } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api, token } from "../../shared/http";
interface Task { id: number; status: string; format: string; cellKey: string; error: string }
const tasks = ref<Task[]>([]);
const message = useMessage();
const show = ref(false);
const format = ref("xlsx");
const cellKey = ref("");
@@ -34,6 +35,7 @@ async function submit() {
body: JSON.stringify({ format: format.value, cellKey: cellKey.value, start: start.value, end: end.value }),
});
show.value = false;
message.success("已提交");
await load();
} catch (error) {
errorText.value = error instanceof Error ? error.message : "提交失败";
@@ -41,14 +43,22 @@ async function submit() {
}
async function download(row: Task) {
const response = await fetch(`/api/tasks/${row.id}/file`, { headers: { Authorization: `Bearer ${token()}` } });
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `结果.${row.format}`;
link.click();
URL.revokeObjectURL(url);
try {
const response = await fetch(`/api/tasks/${row.id}/file`, { headers: { Authorization: `Bearer ${token()}` } });
if (!response.ok) {
message.error("结果还不能下载");
return;
}
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `结果.${row.format}`;
link.click();
URL.revokeObjectURL(url);
} catch {
message.error("下载失败");
}
}
onMounted(load);
@@ -75,8 +85,11 @@ onMounted(load);
<tr v-for="row in tasks" :key="row.id">
<td>{{ row.cellKey || "全部" }}</td>
<td>{{ row.format }}</td>
<td>{{ statusLabel(row.status) }}</td>
<td><n-button v-if="row.status === 'done'" size="small" quaternary @click="download(row)">下载</n-button></td>
<td :class="row.status === 'failed' ? 'late' : ''">{{ statusLabel(row.status) }}</td>
<td>
<n-button v-if="row.status === 'done'" size="small" quaternary @click="download(row)">下载</n-button>
<span v-else-if="row.error" class="late">{{ row.error }}</span>
</td>
</tr>
</tbody>
</table>
@@ -88,7 +101,7 @@ onMounted(load);
<div class="form-row"><label>小区</label><n-input v-model:value="cellKey" placeholder="留空则导出全部" /></div>
<div class="form-row"><label>开始</label><n-input v-model:value="start" placeholder="YYYY-MM-DD" /></div>
<div class="form-row"><label>结束</label><n-input v-model:value="end" placeholder="YYYY-MM-DD" /></div>
<p v-if="errorText" style="color: var(--danger)">{{ errorText }}</p>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
</n-modal>
</Shell>
</template>
+15 -3
View File
@@ -5,7 +5,7 @@
font-size: 14px;
}
* { box-sizing: border-box; }
html, body, #app, .n-config-provider, .app-root { margin: 0; height: 100%; }
html, body, #app, .n-config-provider, .n-message-provider, .n-dialog-provider, .app-root { margin: 0; height: 100%; }
body { background: var(--bg); }
button, input, select { font: inherit; }
::selection { background: var(--accent-soft); }
@@ -135,8 +135,20 @@ button, input, select { font: inherit; }
justify-content: start;
margin-bottom: 12px;
}
.form-row label { white-space: nowrap; }
.settings-form { max-width: 640px; }
.form-row .n-input,
.form-row .n-select,
.form-row .n-input-number { width: 100%; }
.late { color: var(--danger); }
.settings-form { max-width: 720px; }
.settings-form .form-row label { min-width: 8em; }
.setting-control {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.setting-control .n-input-number { flex: 1; width: 100%; min-width: 0; }
.setting-unit { flex: none; color: var(--muted); }
.topbar {
position: sticky;
top: 0;