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;
};
@@ -424,7 +449,9 @@
  return {
    ...rest,
    hasException: hasException.value,
    hasExceptionBefore: hasExceptionBefore.value,
    hasExceptionAfter: hasExceptionAfter.value,
    hasExceptionIssue: hasExceptionIssue.value,
    tempFileIds,
    commonFileListBefore: buildGroupedFiles(beforeModelValue.value),
    commonFileListAfter: buildGroupedFiles(afterModelValue.value),
@@ -433,14 +460,17 @@
};
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;
  }