feat: 提示统一为可关闭的 toast

This commit is contained in:
2026-10-30 12:14:26 +08:00
parent 811dc448cb
commit ccff78ef9c
8 changed files with 76 additions and 65 deletions
+7 -6
View File
@@ -1,15 +1,16 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NModal, NSelect, useDialog, useMessage } from "naive-ui";
import { NButton, NModal, NSelect, useDialog } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import LoginView from "../auth/LoginView.vue";
import { api } from "../../shared/http";
import { useToast } from "../../shared/toast";
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();
const toast = useToast();
async function load() {
const result = await api<{ accounts: Account[] }>("/api/admin/pool");
@@ -19,20 +20,20 @@ async function load() {
async function setRole(id: number, role: string) {
try {
await api(`/api/admin/pool/${id}/role`, { method: "PUT", body: JSON.stringify({ role }) });
message.success("已保存");
toast.success("已保存");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "保存失败");
toast.error(error instanceof Error ? error.message : "保存失败");
}
}
async function remove(id: number) {
try {
await api(`/api/admin/pool/${id}`, { method: "DELETE" });
message.success("已删除");
toast.success("已删除");
await load();
} catch (error) {
message.error(error instanceof Error ? error.message : "删除失败");
toast.error(error instanceof Error ? error.message : "删除失败");
}
}