20260811165111

This commit is contained in:
oneao committed 2026-08-11 16:51:11 +08:00
1 parent 5adbf59425
commit ce78653207
34 files changed
+3793 -366

No files matched your search

@@ -0,0 +1,50 @@
import { reactive } from "vue";
interface ConfirmOptions {
title?: string;
description?: string;
confirmText?: string;
cancelText?: string;
danger?: boolean;
}
interface ConfirmState extends Required<Omit<ConfirmOptions, "danger">> {
open: boolean;
danger: boolean;
resolve: ((ok: boolean) => void) | null;
}
const state = reactive<ConfirmState>({
open: false,
title: "确认操作",
description: "",
confirmText: "确定",
cancelText: "取消",
danger: false,
resolve: null,
});
export function useConfirm() {
function confirm(options: ConfirmOptions | string): Promise<boolean> {
const opts = typeof options === "string" ? { description: options } : options;
state.title = opts.title ?? "确认操作";
state.description = opts.description ?? "";
state.confirmText = opts.confirmText ?? "确定";
state.cancelText = opts.cancelText ?? "取消";
state.danger = opts.danger ?? false;
state.open = true;
return new Promise<boolean>((resolve) => {
state.resolve = resolve;
});
}
return { confirm, state };
}
export function handleConfirm(ok: boolean) {
if (!state.resolve) return;
state.open = false;
const resolve = state.resolve;
state.resolve = null;
resolve(ok);
}