diff --git a/web/src/ui/dialogs.ts b/web/src/ui/dialogs.ts index a9b00a8..896202e 100644 --- a/web/src/ui/dialogs.ts +++ b/web/src/ui/dialogs.ts @@ -1,4 +1,4 @@ -import { w2confirm, w2popup, w2utils } from "../vendor/w2ui"; +import { w2popup, w2utils } from "../vendor/w2ui"; type PopupActionEvent = { detail: { @@ -23,14 +23,27 @@ export function notifyError(error: unknown) { export function confirmDialog(message: string, title = "确认") { return new Promise((resolve) => { - w2confirm({ - msg: message, + let settled = false; + const settle = (value: boolean) => { + if (settled) return; + settled = true; + resolve(value); + }; + + w2utils.confirm({ + box: "body", title, - yes: "确定", - no: "取消" - }, undefined, (action: string) => { - resolve(action === "yes" || action === "Yes"); - }); + text: message, + btn_yes: { + text: "确定" + }, + btn_no: { + text: "取消" + } + }) + .yes(() => settle(true)) + .no(() => settle(false)) + .close(() => settle(false)); }); } diff --git a/web/src/vendor/w2ui.ts b/web/src/vendor/w2ui.ts index e183a64..5021054 100644 --- a/web/src/vendor/w2ui.ts +++ b/web/src/vendor/w2ui.ts @@ -28,6 +28,29 @@ type W2Utils = { title?: string; text?: string; }): unknown; + confirm(options: { + box?: string | HTMLElement; + title?: string; + text?: string; + btn_yes?: { + text?: string; + class?: string; + style?: string; + attrs?: string; + }; + btn_no?: { + text?: string; + class?: string; + style?: string; + attrs?: string; + }; + }): W2ConfirmPromise; +}; + +type W2ConfirmPromise = { + yes(callback: (event: unknown) => void): W2ConfirmPromise; + no(callback: (event: unknown) => void): W2ConfirmPromise; + close(callback: (event: unknown) => void): W2ConfirmPromise; }; type W2LayoutOptions = {