کار اولیه
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { reactive, readonly } from "vue";
|
||||
|
||||
// یک state مشترک برای تمام کامپوننتها
|
||||
const confirmState = reactive({
|
||||
isOpen: false,
|
||||
title: "تأیید عملیات",
|
||||
message: "آیا از انجام این عملیات اطمینان دارید؟",
|
||||
confirmText: "تأیید",
|
||||
cancelText: "انصراف",
|
||||
resolve: null as ((value: boolean) => void) | null,
|
||||
});
|
||||
|
||||
export const useConfirmState = () => readonly(confirmState);
|
||||
|
||||
export const useConfirm = () => {
|
||||
const ucoShowConfirmModal = (
|
||||
options: {
|
||||
title?: string;
|
||||
message?: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
} = {}
|
||||
): Promise<boolean> => {
|
||||
confirmState.title = options.title || "تأیید عملیات";
|
||||
confirmState.message = options.message || "آیا از انجام این عملیات اطمینان دارید؟";
|
||||
confirmState.confirmText = options.confirmText || "تأیید";
|
||||
confirmState.cancelText = options.cancelText || "انصراف";
|
||||
confirmState.isOpen = true;
|
||||
|
||||
return new Promise((resolve) => {
|
||||
confirmState.resolve = resolve;
|
||||
});
|
||||
};
|
||||
|
||||
return { ucoShowConfirmModal };
|
||||
};
|
||||
|
||||
export const useConfirmActions = () => {
|
||||
const ucoConfirm = () => {
|
||||
confirmState.isOpen = false;
|
||||
if (confirmState.resolve) confirmState.resolve(true);
|
||||
confirmState.resolve = null;
|
||||
};
|
||||
|
||||
const ucoCancelConfirmModal = () => {
|
||||
confirmState.isOpen = false;
|
||||
if (confirmState.resolve) confirmState.resolve(false);
|
||||
confirmState.resolve = null;
|
||||
};
|
||||
|
||||
return { ucoConfirm, ucoCancelConfirmModal };
|
||||
};
|
||||
Reference in New Issue
Block a user