gaoluyang
昨天 df1406d0f571972d033dffd6a93fb4b94febeb56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * 对话框管理组合式函数
 * 提供对话框的打开、关闭、数据处理等功能
 */
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
    };
}