import { createDataSource } from "../datasource.mjs";
import { parseRouteParams, parseSingleParamValue } from "../parseRouteParams.mjs";
import { removeEmptyValues } from "../common.mjs";
import "../../../../../node_modules/element-plus/es/index.mjs";
/* empty css                                                             */
/* empty css                                                                 */
/* empty css                                                                  */
/* empty css                                                                   */
/* empty css                                                                       */
import { ElMessageBox } from "../../../../../node_modules/element-plus/es/components/message-box/index.mjs";
import { ElMessage } from "../../../../../node_modules/element-plus/es/components/message/index.mjs";
async function handlePageJump(node, data, fields, context) {
  var _a, _b, _c;
  const dialogDoms = document.querySelectorAll(".el-modal-dialog");
  if ((dialogDoms == null ? void 0 : dialogDoms.length) > 0) {
    for (let i = 0; i < dialogDoms.length; i++) {
      if (!dialogDoms[i].style.display) {
        return {
          success: true,
          message: "页面存在弹层，跳过页面跳转"
        };
      }
    }
  }
  const basic = node.basic || {};
  const transitionType = basic.transitionType || "page";
  const formComponent = (_a = context.components) == null ? void 0 : _a.form;
  const getFormDataMethod = (_c = (_b = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.getFormData;
  if (getFormDataMethod && typeof getFormDataMethod === "function") {
    data = getFormDataMethod();
  }
  const params = parseRouteParams(basic.routeParams, data, fields);
  if (transitionType === "external") {
    const url = basic.routePath;
    if (!url) {
      return {
        success: false,
        message: "外部链接地址不能为空",
        shouldShowError: true
      };
    }
    let fullUrl = url;
    if (Object.keys(params).length > 0) {
      const queryString = new URLSearchParams(params).toString();
      fullUrl = url + (url.includes("?") ? "&" : "?") + queryString;
    }
    if (basic.openNewPage) {
      window.open(fullUrl, "_blank");
    } else {
      window.location.href = fullUrl;
    }
    return {
      success: true,
      message: basic.openNewPage ? "已在新标签页打开链接" : "已在当前页面打开链接",
      url: fullUrl,
      openNewPage: basic.openNewPage
    };
  }
  if (basic.routePath) {
    const router = context.ctx.$router;
    if (router) {
      const route = { path: basic.routePath };
      if (Object.keys(params).length > 0) {
        route.query = params;
      }
      if (basic.openNewPage === true) {
        const url = router.resolve(route).href;
        window.open(url, "_blank");
      } else {
        if (basic.canNotGoBack) {
          await router.replace(route);
        } else {
          await router.push(route);
        }
      }
    }
  }
  return {
    success: true,
    message: basic.openNewPage === true ? "已在新标签页打开" : "跳转成功",
    routePath: basic.routePath,
    routeParams: params,
    transitionType,
    openNewPage: basic.openNewPage
  };
}
async function handlePageGoBack(node, data, fields, context) {
  var _a;
  const basic = node.basic || {};
  const config = {
    backLevel: basic.backLevel || 1,
    showConfirm: basic.showConfirm || false,
    confirmTitle: basic.confirmTitle || "确认回退",
    confirmMessage: basic.confirmMessage || "确定要返回上一页吗？",
    noHistoryAction: basic.noHistoryAction || "none"
  };
  if (config.showConfirm) {
    try {
      await ElMessageBox.confirm(config.confirmMessage, config.confirmTitle, {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        draggable: true,
        showClose: false
      });
    } catch (error) {
      return {
        success: false,
        message: "用户已取消回退操作",
        confirmed: false,
        shouldShowError: false
      };
    }
  }
  const router = (_a = context.ctx) == null ? void 0 : _a.$router;
  if (!router) {
    return {
      success: false,
      message: "路由实例未找到，无法执行回退操作",
      shouldShowError: true
    };
  }
  try {
    const goBackSteps = -Math.abs(config.backLevel);
    router.go(goBackSteps);
    return {
      success: true,
      message: `已成功回退 ${config.backLevel} 级`,
      backLevel: config.backLevel,
      showConfirm: config.showConfirm
    };
  } catch (error) {
    console.error("[EventFlow] 页面回退失败:", error);
    return {
      success: false,
      message: error.message || "页面回退失败",
      shouldShowError: true
    };
  }
}
async function handleApiCall(node, data, fields, context, params) {
  var _a;
  console.log("[EventFlow] 执行API调用:", node.basic);
  const basic = node.basic || {};
  const metadata = context.metadata || {};
  const isApproval = ((_a = metadata == null ? void 0 : metadata.item) == null ? void 0 : _a.isApproval) || false;
  if (!basic.dataSourceId) {
    return {
      success: false,
      message: "数据源配置不完整，缺少 dataSourceId"
    };
  }
  const dataSources = context.localConfig.dataSources || [];
  const dataSourceConfig = dataSources.find((ds) => ds.id === basic.dataSourceId);
  if (!dataSourceConfig) {
    return {
      success: false,
      message: `未找到数据源: ${basic.dataSourceId}`
    };
  }
  const dataSourceManager = createDataSource({
    http: context.ctx.$http,
    params,
    dataSources,
    currentDataSourceId: basic.dataSourceId,
    showSuccessMessage: basic.showSuccessMessage,
    data,
    fields,
    notShowMessage: isApproval
  });
  try {
    const result = await dataSourceManager.fetch();
    return {
      success: true,
      message: "API调用成功",
      data: result,
      shouldShowError: false
    };
  } catch (error) {
    console.error("[EventFlow] API调用失败:", error);
    return {
      success: false,
      message: error.message || "API调用失败",
      error,
      shouldShowError: false
      // API 调用失败需要提示错误
    };
  } finally {
    dataSourceManager.destroy();
  }
}
async function handleConfirm(node, data, fields, context) {
  const basic = node.basic || {};
  const config = {
    messageType: basic.messageType || "warning",
    title: basic.title || "确认操作",
    message: basic.message || "确定要执行此操作吗？",
    confirmText: basic.confirmText || "确定",
    cancelText: basic.cancelText || "取消",
    showCancel: basic.showCancel !== false,
    confirmAction: basic.confirmAction || "continue",
    cancelAction: basic.cancelAction || "stop"
  };
  try {
    await ElMessageBox.confirm(config.message, config.title, {
      confirmButtonText: config.confirmText,
      cancelButtonText: config.cancelText,
      type: config.messageType,
      showCancelButton: config.showCancel,
      draggable: true,
      showClose: false
    });
    if (config.confirmAction === "stop") {
      return {
        success: false,
        message: "用户确认后停止执行",
        confirmed: true,
        shouldShowError: false
      };
    }
    return {
      success: true,
      message: "用户已确认",
      confirmed: true,
      shouldShowError: false
    };
  } catch (error) {
    return {
      success: false,
      message: "用户已取消",
      confirmed: false,
      shouldShowError: false
      // 用户取消不提示错误
    };
  }
}
async function handleMessage(node, data, fields, context) {
  var _a;
  const metadata = context.metadata || {};
  const isApproval = ((_a = metadata == null ? void 0 : metadata.item) == null ? void 0 : _a.isApproval) || false;
  if (isApproval) {
    return {
      success: true,
      message: "审批按钮的消息不显示"
    };
  }
  if (node.basic) {
    const messageType = node.basic.messageType || "info";
    const message = node.basic.message || "操作成功";
    switch (messageType) {
      case "success":
        ElMessage.success(message);
        break;
      case "warning":
        ElMessage.warning(message);
        break;
      case "error":
        ElMessage.error(message);
        break;
      case "info":
      default:
        ElMessage.info(message);
        break;
    }
  }
  return {
    success: true,
    message: "消息已显示"
  };
}
async function handleTableRefresh(node, data, fields, context) {
  var _a, _b, _c;
  console.log("[EventFlow] 执行表格刷新:", node.basic);
  const basic = node.basic || {};
  const refreshOptions = {
    resetSort: basic.resetSort !== false,
    // 默认 true
    resetFilter: basic.resetFilter !== false,
    // 默认 true
    resetPagination: basic.resetPagination !== false
    // 默认 true
  };
  console.log("[EventFlow] 刷新选项:", refreshOptions);
  const tableComponent = (_a = context.components) == null ? void 0 : _a.table;
  const refreshMethod = (_c = (_b = tableComponent == null ? void 0 : tableComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.refresh;
  if (typeof refreshMethod === "function") {
    await refreshMethod(refreshOptions);
    return {
      success: true,
      message: "表格已刷新"
    };
  } else {
    console.error("[EventFlow] 未找到表格组件的 refresh 方法");
    return {
      success: false,
      message: "表格组件未正确配置或 refresh 方法未暴露",
      shouldShowError: true
    };
  }
}
async function handleTableChildRefresh(node, data, fields, context) {
  var _a, _b, _c, _d;
  console.log("[EventFlow] 执行子表格刷新:", node.basic);
  const basic = node.basic || {};
  const formComponent = (_a = context.components) == null ? void 0 : _a.form;
  const getFormItemRefMethod = (_c = (_b = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.getFormItemRef;
  if (typeof getFormItemRefMethod === "function") {
    const subTableRef = getFormItemRefMethod(
      String(basic.selectSubTableFieldId)
    );
    context.components.table = {
      $: {
        exposed: {
          refresh: (_d = subTableRef == null ? void 0 : subTableRef.subTableRef) == null ? void 0 : _d.refresh
        }
      }
    };
    return await handleTableRefresh(node, data, fields, context);
  } else {
    console.error("[EventFlow] 未找到表单组件的 getFormItemRef 方法");
    return {
      success: false,
      message: "表单组件未正确配置或 getFormItemRef 方法未暴露",
      shouldShowError: true
    };
  }
}
async function handleTableChildSelection(node, data, fields, context) {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  console.log("[EventFlow] 执行子表格选择赋值:", node.basic);
  const basic = node.basic || {};
  const formComponent = (_a = context.components) == null ? void 0 : _a.form;
  const getFormDataMethod = (_c = (_b = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.getFormData;
  const setFormDataMethod = (_e = (_d = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _d.exposed) == null ? void 0 : _e.setFormData;
  const getFormItemRefMethod = (_g = (_f = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _f.exposed) == null ? void 0 : _g.getFormItemRef;
  if (typeof getFormItemRefMethod === "function") {
    const subTableRef = getFormItemRefMethod(
      String(basic.selectSubTableFieldId)
    );
    const getSelectionMethod = (_h = subTableRef == null ? void 0 : subTableRef.subTableRef) == null ? void 0 : _h.getSelection;
    if (typeof getSelectionMethod === "function") {
      const rows = await getSelectionMethod();
      const fieldMapping = basic.subTableSelectionFieldMapping;
      if (fieldMapping && Array.isArray(fieldMapping)) {
        let formData = getFormDataMethod();
        fieldMapping.forEach((mapping) => {
          const { field, value } = mapping;
          const targetField = fields.find((item) => item.id == field);
          if (!targetField) {
            return {
              success: false,
              message: `未找到字段: ${field}`
            };
          }
          const values = rows.map((row) => row[value]);
          formData[targetField.fieldName] = values.join(",");
        });
        if (typeof setFormDataMethod === "function") {
          setFormDataMethod(formData);
          return {
            success: true,
            message: "赋值成功"
          };
        } else {
          console.error("未找到表单组件的 setFormData 方法");
          return {
            success: false,
            message: "表单组件未正确配置或 setFormData 方法未暴露",
            shouldShowError: true
          };
        }
      }
    } else {
      console.error("[EventFlow] 未找到子列表组件的 getSelection 方法");
      return {
        success: false,
        message: "子列表组件未正确配置或 getSelection 方法未暴露",
        shouldShowError: true
      };
    }
  } else {
    console.error("[EventFlow] 未找到表单组件的 getFormItemRef 方法");
    return {
      success: false,
      message: "表单组件未正确配置或 getFormItemRef 方法未暴露",
      shouldShowError: true
    };
  }
}
async function handleTableRowDelete(node, data, fields, context) {
  var _a, _b, _c;
  console.log("[EventFlow] 执行表格行删除:", node.basic);
  const basic = node.basic || {};
  if (basic.showConfirmDeleteMessage) {
    try {
      await ElMessageBox.confirm(
        "此操作将永久删除该记录, 是否继续",
        "确认操作",
        {
          // confirmButtonText: "确定",
          // cancelButtonText: "取消",
          type: "warning",
          draggable: true,
          showClose: false
        }
      );
    } catch (error) {
      return {
        success: false,
        message: "用户已取消",
        confirmed: false,
        shouldShowError: false
        // 用户取消不提示错误
      };
    }
  }
  const result = await handleApiCall(node, data, fields, context);
  if (!result.success) {
    return result;
  }
  if (basic.resetTableAfterDelete) {
    const tableComponent = (_a = context.components) == null ? void 0 : _a.table;
    const refreshMethod = (_c = (_b = tableComponent == null ? void 0 : tableComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.refresh;
    if (typeof refreshMethod === "function") {
      const refreshOptions = {
        resetSort: false,
        resetFilter: false,
        resetPagination: false
      };
      await refreshMethod(refreshOptions);
      return {
        success: true,
        message: "表格已刷新"
      };
    } else {
      console.error("[EventFlow] 未找到表格组件的 refresh 方法");
      return {
        success: false,
        message: "表格组件未正确配置或 refresh 方法未暴露",
        shouldShowError: true
      };
    }
  }
  return {
    success: true,
    message: "列表数据已删除"
  };
}
async function handleCustomAction(node, data, fields, context) {
  console.log("[EventFlow] 执行自定义动作:", node.basic);
  return {
    success: true,
    message: "自定义动作已执行"
  };
}
async function handleFormSetValue(node, data, fields, context) {
  var _a, _b, _c, _d;
  const basic = node.basic || {};
  if (!(basic == null ? void 0 : basic.dataSourceId)) {
    console.error("form-setValue: 缺少 dataSourceId 配置");
    return;
  }
  const metadata = context.metadata || {};
  const initSearchData = (metadata == null ? void 0 : metadata.initSearchData) || {};
  const result = await handleApiCall(
    node,
    data,
    fields,
    context,
    initSearchData
  );
  if (!result.success) {
    return result;
  }
  let formData = result.data;
  if (basic.fieldMapping && Array.isArray(basic.fieldMapping)) {
    basic.fieldMapping.forEach((mapping) => {
      const { field, value } = mapping;
      const targetField = fields.find((item) => item.id == field);
      if (!targetField) {
        return {
          success: false,
          message: `未找到字段: ${field}`
        };
      }
      formData[targetField.fieldName] = formData[value];
      delete formData[value];
    });
  }
  formData = removeEmptyValues(formData);
  formData == null ? true : delete formData.pageNo;
  formData == null ? true : delete formData.pageSize;
  const formComponent = ((_a = context.components) == null ? void 0 : _a.form) || ((_b = context.components) == null ? void 0 : _b.table);
  const setFormDataMethod = (_d = (_c = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _c.exposed) == null ? void 0 : _d.setFormData;
  if (typeof setFormDataMethod === "function") {
    setFormDataMethod(formData);
    return {
      success: true,
      message: "表单已赋值"
    };
  } else {
    console.error("未找到表单组件的 setFormData 方法");
    return {
      success: false,
      message: "表单组件未正确配置或 setFormData 方法未暴露",
      shouldShowError: true
    };
  }
}
async function handleFormSubmit(node, data, fields, context) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
  const basic = node.basic || {};
  if (!(basic == null ? void 0 : basic.dataSourceId)) {
    console.error("form-setValue: 缺少 dataSourceId 配置");
    return;
  }
  const formComponent = (_a = context.components) == null ? void 0 : _a.form;
  const validateMethod = (_c = (_b = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.validate;
  const getFormDataMethod = (_e = (_d = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _d.exposed) == null ? void 0 : _e.getFormData;
  if (basic == null ? void 0 : basic.formValidate) {
    try {
      if (typeof validateMethod === "function") {
        await validateMethod();
      } else {
        console.error("未找到表单组件的 validate 方法");
        return {
          success: false,
          message: "表单组件未正确配置或 validate 方法未暴露",
          shouldShowError: true
        };
      }
    } catch (error) {
      return {
        success: false,
        message: "表单验证失败！",
        shouldShowError: false
      };
    }
  }
  if (basic == null ? void 0 : basic.docValidate) {
    const docValidateMethod = (_g = (_f = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _f.exposed) == null ? void 0 : _g.docValidate;
    try {
      if (typeof docValidateMethod === "function") {
        await docValidateMethod();
      } else {
        console.error("未找到表单组件的 docValidate 方法");
        return {
          success: false,
          message: "表单组件未正确配置或 docValidate 方法未暴露",
          shouldShowError: true
        };
      }
    } catch (error) {
      return {
        success: false,
        message: "要件校验失败！",
        shouldShowError: false
      };
    }
  }
  if (typeof getFormDataMethod === "function") {
    try {
      let formData = getFormDataMethod();
      if (basic.fieldMapping && Array.isArray(basic.fieldMapping)) {
        basic.fieldMapping.forEach((mapping) => {
          const { field, value } = mapping;
          const targetField = fields.find((item) => item.id == field);
          if (!targetField) {
            return {
              success: false,
              message: `未找到字段: ${field}`
            };
          }
          formData[value] = formData[targetField.fieldName];
          delete formData[targetField.fieldName];
        });
      }
      const result = await handleApiCall(node, data, fields, context, formData);
      if (!result.success) {
        return result;
      }
      if (basic.returnToForm) {
        formData = removeEmptyValues(result.data || {});
        delete formData.pageNo;
        delete formData.pageSize;
        const formComponent2 = (_h = context.components) == null ? void 0 : _h.form;
        const setFormDataMethod = (_j = (_i = formComponent2 == null ? void 0 : formComponent2.$) == null ? void 0 : _i.exposed) == null ? void 0 : _j.setFormData;
        if (typeof setFormDataMethod === "function") {
          setFormDataMethod(formData);
        } else {
          console.error("未找到表单组件的 setFormData 方法");
          return {
            success: false,
            message: "表单组件未正确配置或 setFormData 方法未暴露",
            shouldShowError: true
          };
        }
      }
      return {
        success: true,
        message: "表单提交成功"
      };
    } catch (error) {
      return {
        success: false,
        message: "表单验证失败！",
        shouldShowError: false
      };
    }
  } else {
    console.error("未找到表单组件的 getFormData 方法");
    return {
      success: false,
      message: "表单组件未正确配置或 getFormData 方法未暴露",
      shouldShowError: true
    };
  }
}
async function handleDialog(node, data, fields, context) {
  const basic = node.basic || {};
  if (!(basic == null ? void 0 : basic.dialogId)) {
    console.error("ui-dialog: 缺少 dialogId 配置");
    return;
  }
  let dialog = null;
  if (basic.dialogSource == "global") {
    const data2 = await api.getTemplateDialogById(
      context.ctx.$http,
      basic.dialogId
    );
    dialog = JSON.parse(data2.config);
    dialog.id = data2.id;
    dialog.name = data2.name;
    dialog.selectionMode = basic.selectionMode;
    dialog.displayFormat = basic.displayFormat;
    dialog.displayFormatText = basic.displayFormatText;
    dialog.fieldMapping = basic.fieldMapping;
    dialog.callbackEventConfig = basic.callbackEventConfig;
  } else if (basic.dialogSource == "custom") {
    const dialogList = context.localConfig.dialogs || [];
    dialog = dialogList.find((item) => item.id == (basic == null ? void 0 : basic.dialogId));
    dialog.subFormMode = basic.subFormMode;
  }
  if (!dialog) {
    console.error("ui-dialog: 未找到匹配的弹层配置，" + (basic == null ? void 0 : basic.dialogId));
    return;
  }
  try {
    await openDialog(
      basic.displayFieldName,
      dialog,
      context.instance,
      context.ctx,
      fields,
      data
    );
    return {
      success: true,
      message: "用户已确认",
      shouldShowError: false
    };
  } catch (error) {
    return {
      success: false,
      message: "用户已取消",
      confirmed: false,
      shouldShowError: false
      // 用户取消不提示错误
    };
  }
}
async function handleRiskSchDialog(node, data, fields, context) {
  var _a, _b, _c, _d, _e, _f;
  const basic = node.basic || {};
  if (!(basic == null ? void 0 : basic.schNo)) {
    console.error("风险拦截校验: 缺少 schNo 配置");
    return;
  }
  if (!(basic == null ? void 0 : basic.busNo)) {
    console.error("风险拦截校验: 缺少 busNo 配置");
    return;
  }
  if (basic == null ? void 0 : basic.formValidate) {
    const formComponent = (_a = context.components) == null ? void 0 : _a.form;
    const validateMethod = (_c = (_b = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _b.exposed) == null ? void 0 : _c.validate;
    if (typeof validateMethod === "function") {
      await validateMethod();
    }
  }
  if (basic == null ? void 0 : basic.docValidate) {
    const formComponent = (_d = context.components) == null ? void 0 : _d.form;
    const docValidateMethod = (_f = (_e = formComponent == null ? void 0 : formComponent.$) == null ? void 0 : _e.exposed) == null ? void 0 : _f.docValidate;
    if (typeof docValidateMethod === "function") {
      await docValidateMethod();
    }
  }
  const schNo = basic.schNo;
  const paramList = parseRouteParams(basic == null ? void 0 : basic.params, data, fields);
  const busNo = parseSingleParamValue(basic.busNo, data, fields);
  try {
    await openRiskSch(
      { schNo, busNo, paramList },
      context.instance,
      context.ctx
    );
    return {
      success: true,
      message: "用户已确认",
      shouldShowError: false
    };
  } catch (error) {
    return {
      success: false,
      message: "用户已取消",
      confirmed: false,
      shouldShowError: false
      // 用户取消不提示错误
    };
  }
}
async function handleUpload(node, data, fields, context) {
  const basic = node.basic || {};
  console.log("[EventFlow] 执行文件上传动作:", basic);
  const dataSourceId = basic.dataSourceId || "";
  const acceptType = basic.acceptType || [];
  const maxSize = basic.maxSize || 0;
  const multipleUpload = basic.multipleUpload || false;
  if (!dataSourceId) {
    return {
      success: false,
      message: "文件上传动作缺少必要的数据源配置（dataSourceId）",
      shouldShowError: true
    };
  }
  const acceptArr = [];
  if (acceptType.includes("image")) {
    acceptArr.push("image/*");
  }
  if (acceptType.includes("video")) {
    acceptArr.push("video/*");
  }
  if (acceptType.includes("audio")) {
    acceptArr.push("audio/*");
  }
  if (acceptType.includes("text")) {
    acceptArr.push("text/plain");
  }
  if (acceptType.includes("doc")) {
    acceptArr.push(".doc");
    acceptArr.push(".docx");
  }
  if (acceptType.includes("xls")) {
    acceptArr.push(".xls");
    acceptArr.push(".xlsx");
  }
  if (acceptType.includes("ppt")) {
    acceptArr.push(".ppt");
    acceptArr.push(".pptx");
  }
  if (acceptType.includes("pdf")) {
    acceptArr.push("application/pdf");
  }
  if (acceptType.includes("zip")) {
    acceptArr.push("application/zip");
    acceptArr.push("application/x-rar-compressed");
  }
  let accept = "";
  if (acceptArr.length < 13) {
    accept = acceptArr.join(",");
  }
  const files = await new Promise((resolve, reject) => {
    const input = document.createElement("input");
    input.type = "file";
    input.multiple = multipleUpload;
    input.accept = accept;
    input.click();
    input.onchange = () => {
      let files2 = Array.from(input.files || []);
      if (files2.length === 0) return resolve([]);
      if (maxSize > 0) {
        const maxByte = maxSize * 1024 * 1024;
        const invalidFiles = files2.some((f) => f.size > maxByte);
        if (invalidFiles) {
          reject(new Error(`文件不能超过 ${maxSize}MB`));
          return;
        }
      }
      resolve(files2);
    };
  });
  if (!files || files.length === 0) {
    return { success: false, message: "未选择文件" };
  }
  try {
    const params = multipleUpload ? { files } : { file: files[0] };
    const result = await handleApiCall(node, data, fields, context, params);
    if (!result.success) {
      return result;
    }
    return {
      success: true,
      message: `文件上传成功'}`,
      data: {
        dataSourceId,
        acceptType,
        maxSize,
        multipleUpload,
        acceptType
      }
    };
  } catch (error) {
    return {
      success: false,
      message: "上传失败",
      shouldShowError: false
    };
  }
}
const defaultActionHandlers = {
  "page-jump": handlePageJump,
  "page-go-back": handlePageGoBack,
  "request-send": handleApiCall,
  "ui-confirm": handleConfirm,
  "ui-message": handleMessage,
  "table-refresh": handleTableRefresh,
  "table-row-delete": handleTableRowDelete,
  "table-child-refresh": handleTableChildRefresh,
  "table-child-selection": handleTableChildSelection,
  "form-setValue": handleFormSetValue,
  "form-submit": handleFormSubmit,
  custom: handleCustomAction,
  "ui-dialog": handleDialog,
  "ui-upload": handleUpload,
  riskSchDialog: handleRiskSchDialog
};
export {
  defaultActionHandlers as default,
  defaultActionHandlers,
  handleApiCall,
  handleConfirm,
  handleCustomAction,
  handleDialog,
  handleMessage,
  handlePageGoBack,
  handlePageJump,
  handleRiskSchDialog,
  handleTableChildRefresh,
  handleTableChildSelection,
  handleTableRefresh,
  handleTableRowDelete,
  handleUpload
};
