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
+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>