fix: 管理页对齐表单,操作用提示条和确认框
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user