feat: 提示统一为可关闭的 toast
This commit is contained in:
@@ -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 : "删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NButton, NInputNumber, NRadio, NRadioGroup, useMessage } from "naive-ui";
|
||||
import { NButton, NInputNumber, NRadio, NRadioGroup } from "naive-ui";
|
||||
import Shell from "../../shell/Shell.vue";
|
||||
import { api } from "../../shared/http";
|
||||
import { useToast } from "../../shared/toast";
|
||||
|
||||
const message = useMessage();
|
||||
const toast = useToast();
|
||||
const mode = ref("local");
|
||||
const seconds = ref(300);
|
||||
const concurrency = ref(4);
|
||||
@@ -19,7 +20,7 @@ async function load() {
|
||||
concurrency.value = result.workerConcurrency;
|
||||
loaded.value = true;
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "设置没有获取到");
|
||||
toast.error(error instanceof Error ? error.message : "设置没有获取到");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +32,9 @@ async function save() {
|
||||
method: "PUT",
|
||||
body: JSON.stringify({ loginMode: mode.value, credentialRefreshSeconds: seconds.value, workerConcurrency: concurrency.value }),
|
||||
});
|
||||
message.success("已保存");
|
||||
toast.success("已保存");
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : "保存失败");
|
||||
toast.error(error instanceof Error ? error.message : "保存失败");
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NInput, NModal, NSelect, useDialog, useMessage } from "naive-ui";
|
||||
import { NButton, NInput, NModal, NSelect, useDialog } from "naive-ui";
|
||||
import Shell from "../../shell/Shell.vue";
|
||||
import { api } from "../../shared/http";
|
||||
import { useToast } from "../../shared/toast";
|
||||
|
||||
interface User { id: number; username: string; role: string }
|
||||
const dialog = useDialog();
|
||||
const message = useMessage();
|
||||
const toast = useToast();
|
||||
const users = ref<User[]>([]);
|
||||
const show = ref(false);
|
||||
const username = ref("");
|
||||
const password = ref("");
|
||||
const role = ref("user");
|
||||
const errorText = ref("");
|
||||
|
||||
async function load() {
|
||||
const result = await api<{ users: User[] }>("/api/admin/users");
|
||||
@@ -20,16 +20,15 @@ async function load() {
|
||||
}
|
||||
|
||||
async function create() {
|
||||
errorText.value = "";
|
||||
try {
|
||||
await api("/api/admin/users", { method: "POST", body: JSON.stringify({ username: username.value, password: password.value, role: role.value }) });
|
||||
show.value = false;
|
||||
username.value = "";
|
||||
password.value = "";
|
||||
message.success("已添加");
|
||||
toast.success("已添加");
|
||||
await load();
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof Error ? error.message : "添加失败";
|
||||
toast.error(error instanceof Error ? error.message : "添加失败");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -37,10 +36,10 @@ async function create() {
|
||||
async function remove(id: number) {
|
||||
try {
|
||||
await api(`/api/admin/users/${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 : "删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +88,6 @@ 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>
|
||||
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
</n-modal>
|
||||
</Shell>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user