This commit is contained in:
Viet An
2026-05-15 14:32:09 +07:00
parent 0ef1d29850
commit 4edb2ff22b
11 changed files with 139 additions and 83 deletions

View File

@@ -1,35 +0,0 @@
const activeModals = ref([]);
export default function useModal() {
function open(component, options = {}) {
const id = Date.now() + Math.random();
const modal = {
id,
component,
title: options.title,
width: options.width,
height: options.height,
vbind: options.props || {},
onClose: options.onClose,
onEvent: options.onEvent,
...options,
};
activeModals.value.push(modal);
return id;
}
function close(id) {
const index = activeModals.value.findIndex((m) => m.id === id);
if (index !== -1) {
const modal = activeModals.value[index];
modal.onClose?.();
activeModals.value.splice(index, 1);
}
}
function send(id, eventName, data) {
const modal = activeModals.value.find((m) => m.id === id);
modal?.onEvent?.({ name: eventName, data });
}
return { modals: activeModals, open, close, send };
}