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 -10
View File
@@ -1,8 +1,9 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NAlert, NButton, NInput, NInputNumber, NModal, NSelect, NSwitch, useDialog, useMessage } from "naive-ui";
import { NButton, NInput, NInputNumber, NModal, NSelect, NSwitch, useDialog } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
import { useToast } from "../../shared/toast";
interface Source {
id: number;
@@ -27,9 +28,8 @@ const username = ref("");
const password = ref("");
const path = ref("");
const url = ref("");
const errorText = ref("");
const dialog = useDialog();
const message = useMessage();
const toast = useToast();
function reset(source?: Source) {
editing.value = source || null;
@@ -44,7 +44,6 @@ function reset(source?: Source) {
password.value = "";
path.value = String(source?.config.path || "");
url.value = String(source?.config.url || "");
errorText.value = "";
show.value = true;
}
@@ -54,7 +53,6 @@ async function load() {
}
async function save() {
errorText.value = "";
const config = kind.value === "nqi"
? { url: url.value }
: { protocol: protocol.value, host: host.value, port: port.value, username: username.value, password: password.value, path: path.value };
@@ -66,10 +64,10 @@ async function save() {
await api("/api/admin/sources", { method: "POST", body: JSON.stringify(body) });
}
show.value = false;
message.success("已保存");
toast.success("已保存");
await load();
} catch (error) {
errorText.value = error instanceof Error ? error.message : "保存失败";
toast.error(error instanceof Error ? error.message : "保存失败");
return false;
}
}
@@ -77,10 +75,10 @@ async function save() {
async function remove(id: number) {
try {
await api(`/api/admin/sources/${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 : "删除失败");
}
}
@@ -148,7 +146,6 @@ onMounted(load);
<template v-else>
<div class="form-row"><label>地址</label><n-input v-model:value="url" /></div>
</template>
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
</n-modal>
</Shell>
</template>