huminmin
2026-05-28 8ef070c84a703c4a8b838bf9320d68d00a7d6dca
src/views/equipmentManagement/inspectionManagement/components/uploadFiles.vue
@@ -14,7 +14,7 @@
      <div class="exception-section">
        <div class="section-title">是否存在异常?</div>
        <el-radio-group v-model="hasException">
        <el-radio-group v-model="currentHasException">
          <el-radio :value="false">正常</el-radio>
          <el-radio :value="true">存在异常</el-radio>
        </el-radio-group>
@@ -135,11 +135,27 @@
const afterModelValue = ref([]);
const issueModelValue = ref([]);
const currentUploadType = ref("before");
const hasException = ref(null);
const hasExceptionBefore = ref(null);
const hasExceptionAfter = ref(null);
const hasExceptionIssue = ref(null);
const currentTask = ref(null);
const showVideoDialog = ref(false);
const currentVideoFile = ref(null);
// 根据当前 Tab 获取/设置对应的异常状态
const currentHasException = computed({
  get: () => {
    if (currentUploadType.value === "before") return hasExceptionBefore.value;
    if (currentUploadType.value === "after") return hasExceptionAfter.value;
    return hasExceptionIssue.value;
  },
  set: (val) => {
    if (currentUploadType.value === "before") hasExceptionBefore.value = val;
    else if (currentUploadType.value === "after") hasExceptionAfter.value = val;
    else hasExceptionIssue.value = val;
  }
});
const uploadConfig = {
  action: "/file/upload",
@@ -148,7 +164,10 @@
  fileType: ["jpg", "jpeg", "png", "gif", "webp", "mp4", "mov", "avi", "wmv"],
};
const uploadUrl = `${import.meta.env.VITE_APP_BASE_API}${uploadConfig.action}`;
const uploadUrl = computed(() => {
  const type = getTabType();
  return `${import.meta.env.VITE_APP_BASE_API}${uploadConfig.action}?type=${type}`;
});
const uploadHeaders = {
  Authorization: `Bearer ${getToken()}`,
};
@@ -213,7 +232,9 @@
  afterModelValue.value = [];
  issueModelValue.value = [];
  currentUploadType.value = "before";
  hasException.value = null;
  hasExceptionBefore.value = null;
  hasExceptionAfter.value = null;
  hasExceptionIssue.value = null;
  currentTask.value = null;
  uploadProgress.value = 0;
  uploading.value = false;
@@ -240,8 +261,12 @@
    : [];
  currentUploadType.value = "before";
  hasException.value =
    typeof rawTask.hasException === "boolean" ? rawTask.hasException : null;
  hasExceptionBefore.value =
    typeof rawTask.hasExceptionBefore === "boolean" ? rawTask.hasExceptionBefore : null;
  hasExceptionAfter.value =
    typeof rawTask.hasExceptionAfter === "boolean" ? rawTask.hasExceptionAfter : null;
  hasExceptionIssue.value =
    typeof rawTask.hasExceptionIssue === "boolean" ? rawTask.hasExceptionIssue : null;
  uploadFileList.value = [];
  showUploadDialog.value = true;
};
@@ -383,15 +408,69 @@
  }));
};
const buildSubmitFileItem = item => {
  if (!item) return null;
  return {
    id: item.id,
    tempId: item.tempId,
    tempFileId: item.tempFileId,
    type: item.type,
    url: item?.downloadUrl || item?.url || "",
    downloadUrl: item?.downloadUrl || item?.url || "",
    bucketFilename: item.bucketFilename,
    originalFilename: item.originalFilename,
    size: item.size,
    byteSize: item.byteSize,
    contentType: item.contentType,
  };
};
const buildGroupedFiles = list => {
  return (list || []).map(buildSubmitFileItem).filter(Boolean);
};
const buildSubmitPayload = () => {
  const {
    createTime,
    updateTime,
    storageBlobDTO,
    commonFileListBefore,
    commonFileListAfter,
    commonFileList,
    __raw,
    ...rest
  } = currentTask.value || {};
  const files = buildSubmitFiles();
  const tempFileIds = files
    .map(item => item?.tempId ?? item?.tempFileId ?? item?.id)
    .filter(Boolean);
  return {
    ...rest,
    hasExceptionBefore: hasExceptionBefore.value,
    hasExceptionAfter: hasExceptionAfter.value,
    hasExceptionIssue: hasExceptionIssue.value,
    tempFileIds,
    commonFileListBefore: buildGroupedFiles(beforeModelValue.value),
    commonFileListAfter: buildGroupedFiles(afterModelValue.value),
    commonFileList: buildGroupedFiles(issueModelValue.value),
  };
};
const submitUpload = async () => {
  if (hasException.value === null) {
    ElMessage.warning("请选择是否存在异常");
  // 只验证当前 Tab 的异常状态
  const currentException = currentHasException.value;
  if (currentException === null) {
    ElMessage.warning(`请选择${getUploadTypeText()}是否存在异常`);
    return;
  }
  const files = buildSubmitFiles();
  if (!files.length) {
    ElMessage.warning("请先上传文件");
  const currentFiles = getCurrentFiles();
  // 只有选择"存在异常"时才需要上传文件
  if (currentException === true && !currentFiles.length) {
    ElMessage.warning(`${getUploadTypeText()}存在异常时请上传图片或视频`);
    return;
  }
@@ -401,19 +480,7 @@
  });
  try {
    const tempFileIds = files
      .map(item => item?.tempId ?? item?.tempFileId ?? item?.id)
      .filter(Boolean);
    const payload = {
      ...currentTask.value,
      hasException: hasException.value,
      storageBlobDTO: files,
      tempFileIds,
      commonFileListBefore: beforeModelValue.value,
      commonFileListAfter: afterModelValue.value,
      commonFileList: issueModelValue.value,
    };
    const payload = buildSubmitPayload();
    const result = await uploadInspectionTask(payload);
    if (result?.code === 200 || result?.success) {