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