统一模型库确认框调用方式

This commit is contained in:
zhangshun
2026-06-01 09:40:36 +08:00
parent 738476c7f9
commit 3dfed3a2df
2 changed files with 44 additions and 8 deletions

View File

@@ -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<boolean>((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));
});
}

View File

@@ -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 = {