/**
|
* 对话框管理组合式函数
|
* 提供对话框的打开、关闭、数据处理等功能
|
*/
|
import { ref } from 'vue';
|
|
export function useDialog() {
|
const dialogVisible = ref(false);
|
const dialogType = ref('add');
|
const dialogRef = ref(null);
|
const currentRowData = ref(null);
|
|
// 打开对话框
|
const openDialog = (type = 'add', rowData = null) => {
|
dialogType.value = type;
|
currentRowData.value = rowData;
|
dialogVisible.value = true;
|
|
// 调用对话框组件的初始化方法
|
if (dialogRef.value) {
|
if (type === 'add') {
|
dialogRef.value.Initialization?.();
|
} else if (type === 'edit' && rowData) {
|
dialogRef.value.editInitialization?.(rowData);
|
}
|
}
|
};
|
|
// 关闭对话框
|
const closeDialog = () => {
|
dialogVisible.value = false;
|
dialogType.value = 'add';
|
currentRowData.value = null;
|
};
|
|
// 对话框成功回调
|
const handleDialogSuccess = (callback) => {
|
closeDialog();
|
if (typeof callback === 'function') {
|
callback();
|
}
|
};
|
|
return {
|
// 状态
|
dialogVisible,
|
dialogType,
|
dialogRef,
|
currentRowData,
|
|
// 方法
|
openDialog,
|
closeDialog,
|
handleDialogSuccess
|
};
|
}
|