From d76932ae3412fea0094b020f89e4fb5cfb1c98ec Mon Sep 17 00:00:00 2001 From: seaHi Date: Wed, 29 Jul 2026 21:46:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=BB=84=E4=BB=B6=E5=B9=B6=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E5=8E=9F=E6=9C=89=E7=9A=84=E8=A1=A8=E5=8D=95=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/components/Toast.svelte | 114 +++++++++++++++++++++++++ src/lib/stores/toast.svelte.ts | 34 ++++++++ src/routes/admin/+layout.svelte | 3 + src/routes/admin/files/+page.svelte | 38 +++------ src/routes/admin/settings/+page.svelte | 37 ++------ 5 files changed, 173 insertions(+), 53 deletions(-) create mode 100644 src/lib/components/Toast.svelte create mode 100644 src/lib/stores/toast.svelte.ts diff --git a/src/lib/components/Toast.svelte b/src/lib/components/Toast.svelte new file mode 100644 index 0000000..ed7ef95 --- /dev/null +++ b/src/lib/components/Toast.svelte @@ -0,0 +1,114 @@ + + +
+ {#each toastState.messages as msg (msg.id)} + +
+ {#if msg.type === 'success'} + + + + {:else if msg.type === 'error'} + + + + + + {:else} + + + + + + {/if} + {msg.text} + + +
+ {/each} +
+ + diff --git a/src/lib/stores/toast.svelte.ts b/src/lib/stores/toast.svelte.ts new file mode 100644 index 0000000..4a6f08c --- /dev/null +++ b/src/lib/stores/toast.svelte.ts @@ -0,0 +1,34 @@ +export type ToastType = 'success' | 'error' | 'info'; + +export interface ToastMessage { + id: number; + text: string; + type: ToastType; +} + +class ToastState { + messages = $state([]); + private nextId = 0; + + add(text: string, type: ToastType = 'info', duration: number = 3000) { + const id = this.nextId++; + this.messages.push({ id, text, type }); + + if (duration > 0) { + setTimeout(() => { + this.remove(id); + }, duration); + } + } + + remove(id: number) { + this.messages = this.messages.filter((msg) => msg.id !== id); + } +} + +export const toastState = new ToastState(); + +// Helper export for simpler usage +export function addToast(text: string, type: ToastType = 'info', duration: number = 3000) { + toastState.add(text, type, duration); +} diff --git a/src/routes/admin/+layout.svelte b/src/routes/admin/+layout.svelte index 5635c92..4add4ed 100644 --- a/src/routes/admin/+layout.svelte +++ b/src/routes/admin/+layout.svelte @@ -1,6 +1,8 @@
@@ -16,17 +25,6 @@
-{#if form?.success} -
- 设置保存成功! -
-{/if} - -{#if form?.error} -
- {form.error} -
-{/if}
{#if activeTab === 'basic'} @@ -166,23 +164,6 @@ border-bottom-color: var(--accent-color, #419b38); } - .success-alert { - padding: 12px 16px; - background-color: transparent; - border-left: 4px solid #419b38; - color: #419b38; - margin-bottom: 30px; - font-weight: 600; - } - - .error-alert { - padding: 12px 16px; - background-color: transparent; - border-left: 4px solid #d9534f; - color: #d9534f; - margin-bottom: 30px; - font-weight: 600; - } .settings-container { display: grid;