统一模型库确认框调用方式
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { w2confirm, w2popup, w2utils } from "../vendor/w2ui";
|
import { w2popup, w2utils } from "../vendor/w2ui";
|
||||||
|
|
||||||
type PopupActionEvent = {
|
type PopupActionEvent = {
|
||||||
detail: {
|
detail: {
|
||||||
@@ -23,14 +23,27 @@ export function notifyError(error: unknown) {
|
|||||||
|
|
||||||
export function confirmDialog(message: string, title = "确认") {
|
export function confirmDialog(message: string, title = "确认") {
|
||||||
return new Promise<boolean>((resolve) => {
|
return new Promise<boolean>((resolve) => {
|
||||||
w2confirm({
|
let settled = false;
|
||||||
msg: message,
|
const settle = (value: boolean) => {
|
||||||
|
if (settled) return;
|
||||||
|
settled = true;
|
||||||
|
resolve(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
w2utils.confirm({
|
||||||
|
box: "body",
|
||||||
title,
|
title,
|
||||||
yes: "确定",
|
text: message,
|
||||||
no: "取消"
|
btn_yes: {
|
||||||
}, undefined, (action: string) => {
|
text: "确定"
|
||||||
resolve(action === "yes" || action === "Yes");
|
},
|
||||||
});
|
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;
|
title?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
}): unknown;
|
}): 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 = {
|
type W2LayoutOptions = {
|
||||||
|
|||||||
Reference in New Issue
Block a user