From ffde675f3a3ae6f4512a49a36134a842cdb375f4 Mon Sep 17 00:00:00 2001 From: seaHi Date: Sat, 15 Aug 2026 11:46:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E5=AF=B9=E8=AF=9D=E6=A1=86=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8F=8A=E7=8A=B6=E6=80=81=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/components/ConfirmDialog.svelte | 142 ++++++++++++++++++++++++ src/lib/stores/confirm.svelte.ts | 36 ++++++ src/routes/admin/+layout.svelte | 2 + 3 files changed, 180 insertions(+) create mode 100644 src/lib/components/ConfirmDialog.svelte create mode 100644 src/lib/stores/confirm.svelte.ts diff --git a/src/lib/components/ConfirmDialog.svelte b/src/lib/components/ConfirmDialog.svelte new file mode 100644 index 0000000..cd3b0c4 --- /dev/null +++ b/src/lib/components/ConfirmDialog.svelte @@ -0,0 +1,142 @@ + + +{#if confirmState.isOpen} + + +
{ + if (e.target === e.currentTarget) confirmState.cancel(); + }} + > + +
+{/if} + + diff --git a/src/lib/stores/confirm.svelte.ts b/src/lib/stores/confirm.svelte.ts new file mode 100644 index 0000000..2ca89fc --- /dev/null +++ b/src/lib/stores/confirm.svelte.ts @@ -0,0 +1,36 @@ +import { untrack } from 'svelte'; + +class ConfirmState { + isOpen = $state(false); + message = $state(''); + private resolve: ((value: boolean) => void) | null = null; + + async show(message: string): Promise { + this.message = message; + this.isOpen = true; + return new Promise((res) => { + this.resolve = res; + }); + } + + confirm() { + untrack(() => { + if (this.resolve) this.resolve(true); + this.close(); + }); + } + + cancel() { + untrack(() => { + if (this.resolve) this.resolve(false); + this.close(); + }); + } + + private close() { + this.isOpen = false; + this.resolve = null; + } +} + +export const confirmState = new ConfirmState(); diff --git a/src/routes/admin/+layout.svelte b/src/routes/admin/+layout.svelte index 06ad37e..c4ee8b9 100644 --- a/src/routes/admin/+layout.svelte +++ b/src/routes/admin/+layout.svelte @@ -3,6 +3,7 @@ import { page } from '$app/stores'; import { onMount } from 'svelte'; import Toast from '$lib/components/Toast.svelte'; + import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; let { children } = $props(); @@ -102,6 +103,7 @@ +