统一模型库确认框调用方式
This commit is contained in:
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
23
web/src/vendor/w2ui.ts
vendored
23
web/src/vendor/w2ui.ts
vendored
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user