| | |
| | | width="560px" |
| | | :before-close="closeUploadDialog" |
| | | > |
| | | <el-tabs v-model="currentUploadType"> |
| | | <el-tab-pane label="生产前" name="before" /> |
| | | <el-tab-pane label="生产中" name="after" /> |
| | | <el-tab-pane label="生产后" name="issue" /> |
| | | </el-tabs> |
| | | |
| | | <div class="exception-section"> |
| | | <div class="section-title">是否存在异常?</div> |
| | | <el-radio-group v-model="currentHasException"> |
| | | <el-radio-group v-model="hasException"> |
| | | <el-radio :value="false">正常</el-radio> |
| | | <el-radio :value="true">存在异常</el-radio> |
| | | </el-radio-group> |
| | |
| | | :on-success="handleUploadSuccess" |
| | | :on-error="handleUploadError" |
| | | :on-progress="handleUploadProgress" |
| | | :disabled="uploading || getCurrentFiles().length >= uploadConfig.limit" |
| | | :disabled="uploading || fileList.length >= uploadConfig.limit" |
| | | > |
| | | <el-button |
| | | type="primary" |
| | | :loading="uploading" |
| | | :disabled="getCurrentFiles().length >= uploadConfig.limit" |
| | | :disabled="fileList.length >= uploadConfig.limit" |
| | | > |
| | | 选择图片/视频 |
| | | </el-button> |
| | |
| | | style="margin: 12px 0" |
| | | /> |
| | | |
| | | <div v-if="getCurrentFiles().length" class="file-list"> |
| | | <div v-if="fileList.length" class="file-list"> |
| | | <div |
| | | v-for="(file, index) in getCurrentFiles()" |
| | | v-for="(file, index) in fileList" |
| | | :key="file.uid || file.id || index" |
| | | class="file-item" |
| | | > |
| | |
| | | |
| | | <el-empty |
| | | v-else |
| | | :description="`请选择要上传的${getUploadTypeText()}图片或视频`" |
| | | description="请选择要上传的图片或视频" |
| | | /> |
| | | |
| | | <div class="upload-summary"> |
| | | 生产前:{{ beforeModelValue.length }} 个 | |
| | | 生产中:{{ afterModelValue.length }} 个 | |
| | | 生产后:{{ issueModelValue.length }} 个 |
| | | 已上传 {{ fileList.length }} 个文件 |
| | | </div> |
| | | |
| | | <template #footer> |
| | | <el-button type="primary" @click="submitUpload">提交</el-button> |
| | | <el-button type="primary" @click="submitUpload">提交</el-button> |
| | | <el-button @click="closeUploadDialog">取消</el-button> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | const uploadRef = ref(null); |
| | | const uploadFileList = ref([]); |
| | | |
| | | const beforeModelValue = ref([]); |
| | | const afterModelValue = ref([]); |
| | | const issueModelValue = ref([]); |
| | | const currentUploadType = ref("before"); |
| | | const hasExceptionBefore = ref(null); |
| | | const hasExceptionAfter = ref(null); |
| | | const hasExceptionIssue = ref(null); |
| | | const fileList = ref([]); |
| | | const hasException = 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 INSPECTION_TYPE = 10; |
| | | |
| | | const uploadConfig = { |
| | | action: "/file/upload", |
| | |
| | | }; |
| | | |
| | | const uploadUrl = computed(() => { |
| | | const type = getTabType(); |
| | | return `${import.meta.env.VITE_APP_BASE_API}${uploadConfig.action}?type=${type}`; |
| | | return `${import.meta.env.VITE_APP_BASE_API}${uploadConfig.action}?type=${INSPECTION_TYPE}`; |
| | | }); |
| | | const uploadHeaders = { |
| | | Authorization: `Bearer ${getToken()}`, |
| | |
| | | return fileUrl; |
| | | }; |
| | | |
| | | const mapExistingFile = (file, type) => ({ |
| | | const mapExistingFile = (file) => ({ |
| | | ...file, |
| | | id: file?.id, |
| | | tempId: file?.tempId ?? file?.tempFileId ?? file?.id, |
| | |
| | | size: file?.size || file?.byteSize, |
| | | byteSize: file?.byteSize || file?.size, |
| | | contentType: file?.contentType || "", |
| | | type, |
| | | uid: file?.uid || `${type}-${file?.id || file?.url || Math.random()}`, |
| | | type: INSPECTION_TYPE, |
| | | uid: file?.uid || `${INSPECTION_TYPE}-${file?.id || file?.url || Math.random()}`, |
| | | }); |
| | | |
| | | const resetDialogState = () => { |
| | | beforeModelValue.value = []; |
| | | afterModelValue.value = []; |
| | | issueModelValue.value = []; |
| | | currentUploadType.value = "before"; |
| | | hasExceptionBefore.value = null; |
| | | hasExceptionAfter.value = null; |
| | | hasExceptionIssue.value = null; |
| | | fileList.value = []; |
| | | hasException.value = null; |
| | | currentTask.value = null; |
| | | uploadProgress.value = 0; |
| | | uploading.value = false; |
| | |
| | | storageBlobDTO: [], |
| | | }; |
| | | |
| | | beforeModelValue.value = Array.isArray(rawTask.commonFileListBefore) |
| | | ? rawTask.commonFileListBefore.map(file => mapExistingFile(file, 10)) |
| | | : []; |
| | | afterModelValue.value = Array.isArray(rawTask.commonFileListAfter) |
| | | ? rawTask.commonFileListAfter.map(file => mapExistingFile(file, 11)) |
| | | : []; |
| | | issueModelValue.value = Array.isArray(rawTask.commonFileList) |
| | | ? rawTask.commonFileList.map(file => mapExistingFile(file, 12)) |
| | | fileList.value = Array.isArray(rawTask.commonFileList) |
| | | ? rawTask.commonFileList.map(file => mapExistingFile(file)) |
| | | : []; |
| | | |
| | | currentUploadType.value = "before"; |
| | | 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; |
| | | hasException.value = |
| | | typeof rawTask.hasException === "boolean" ? rawTask.hasException : null; |
| | | uploadFileList.value = []; |
| | | showUploadDialog.value = true; |
| | | }; |
| | |
| | | emit("closeDia"); |
| | | }; |
| | | |
| | | const getCurrentFiles = () => { |
| | | if (currentUploadType.value === "before") return beforeModelValue.value; |
| | | if (currentUploadType.value === "after") return afterModelValue.value; |
| | | return issueModelValue.value; |
| | | }; |
| | | |
| | | const getUploadTypeText = () => { |
| | | if (currentUploadType.value === "before") return "生产前"; |
| | | if (currentUploadType.value === "after") return "生产中"; |
| | | return "生产后"; |
| | | }; |
| | | |
| | | const getTabType = () => { |
| | | if (currentUploadType.value === "before") return 10; |
| | | if (currentUploadType.value === "after") return 11; |
| | | return 12; |
| | | }; |
| | | |
| | | const handleBeforeUpload = file => { |
| | | if (getCurrentFiles().length >= uploadConfig.limit) { |
| | | if (fileList.value.length >= uploadConfig.limit) { |
| | | ElMessage.warning(`最多只能选择${uploadConfig.limit}个文件`); |
| | | return false; |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | const type = getTabType(); |
| | | const objectUrl = file?.raw ? URL.createObjectURL(file.raw) : ""; |
| | | const fileData = { |
| | | id: uploadedFile.id, |
| | |
| | | byteSize: uploadedFile.byteSize || uploadedFile.size || file.size, |
| | | createTime: uploadedFile.createTime || Date.now(), |
| | | contentType: uploadedFile.contentType || file.raw?.type || "", |
| | | type, |
| | | type: INSPECTION_TYPE, |
| | | uid: `${Date.now()}-${Math.random()}`, |
| | | }; |
| | | |
| | | if (currentUploadType.value === "before") { |
| | | beforeModelValue.value.push(fileData); |
| | | } else if (currentUploadType.value === "after") { |
| | | afterModelValue.value.push(fileData); |
| | | } else { |
| | | issueModelValue.value.push(fileData); |
| | | } |
| | | |
| | | fileList.value.push(fileData); |
| | | ElMessage.success("上传成功"); |
| | | }; |
| | | |
| | |
| | | await ElMessageBox.confirm("确定要删除这个文件吗?", "确认删除", { |
| | | type: "warning", |
| | | }); |
| | | |
| | | if (currentUploadType.value === "before") { |
| | | beforeModelValue.value.splice(index, 1); |
| | | } else if (currentUploadType.value === "after") { |
| | | afterModelValue.value.splice(index, 1); |
| | | } else { |
| | | issueModelValue.value.splice(index, 1); |
| | | } |
| | | |
| | | fileList.value.splice(index, 1); |
| | | ElMessage.success("删除成功"); |
| | | } catch {} |
| | | }; |
| | | |
| | | const buildSubmitFiles = () => { |
| | | const list = [ |
| | | ...beforeModelValue.value, |
| | | ...afterModelValue.value, |
| | | ...issueModelValue.value, |
| | | ]; |
| | | |
| | | return list.map(item => ({ |
| | | ...item, |
| | | url: item?.downloadUrl || item?.url || "", |
| | | })); |
| | | }; |
| | | |
| | | 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 = () => { |
| | |
| | | ...rest |
| | | } = currentTask.value || {}; |
| | | |
| | | const files = buildSubmitFiles(); |
| | | const files = fileList.value.map(item => ({ |
| | | ...item, |
| | | url: item?.downloadUrl || item?.url || "", |
| | | })); |
| | | |
| | | const tempFileIds = files |
| | | .map(item => item?.tempId ?? item?.tempFileId ?? item?.id) |
| | | .filter(Boolean); |
| | | |
| | | return { |
| | | ...rest, |
| | | hasExceptionBefore: hasExceptionBefore.value, |
| | | hasExceptionAfter: hasExceptionAfter.value, |
| | | hasExceptionIssue: hasExceptionIssue.value, |
| | | hasException: hasException.value, |
| | | tempFileIds, |
| | | commonFileListBefore: buildGroupedFiles(beforeModelValue.value), |
| | | commonFileListAfter: buildGroupedFiles(afterModelValue.value), |
| | | commonFileList: buildGroupedFiles(issueModelValue.value), |
| | | commonFileList: files.map(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, |
| | | }; |
| | | }).filter(Boolean), |
| | | }; |
| | | }; |
| | | |
| | | const submitUpload = async () => { |
| | | // 只验证当前 Tab 的异常状态 |
| | | const currentException = currentHasException.value; |
| | | if (currentException === null) { |
| | | ElMessage.warning(`请选择${getUploadTypeText()}是否存在异常`); |
| | | if (hasException.value === null) { |
| | | ElMessage.warning("请选择是否存在异常"); |
| | | return; |
| | | } |
| | | |
| | | const currentFiles = getCurrentFiles(); |
| | | // 只有选择"存在异常"时才需要上传文件 |
| | | if (currentException === true && !currentFiles.length) { |
| | | ElMessage.warning(`${getUploadTypeText()}存在异常时请上传图片或视频`); |
| | | if (hasException.value === true && !fileList.value.length) { |
| | | ElMessage.warning("存在异常时请上传图片或视频"); |
| | | return; |
| | | } |
| | | |
| | |
| | | |
| | | try { |
| | | const payload = buildSubmitPayload(); |
| | | |
| | | const result = await uploadInspectionTask(payload); |
| | | if (result?.code === 200 || result?.success) { |
| | | ElMessage.success("提交成功"); |
| | |
| | | } finally { |
| | | loadingInstance.close(); |
| | | } |
| | | }; |
| | | |
| | | const goToRepair = () => { |
| | | const taskInfo = { |
| | | taskId: currentTask.value?.taskId || currentTask.value?.id, |
| | | taskName: currentTask.value?.taskName, |
| | | inspectionLocation: currentTask.value?.inspectionLocation, |
| | | inspector: currentTask.value?.inspector, |
| | | uploadedFiles: { |
| | | before: beforeModelValue.value, |
| | | after: afterModelValue.value, |
| | | issue: issueModelValue.value, |
| | | }, |
| | | }; |
| | | |
| | | sessionStorage.setItem("repairTaskInfo", JSON.stringify(taskInfo)); |
| | | window.location.href = "/equipmentManagement/repair"; |
| | | }; |
| | | |
| | | const previewAttachment = file => { |