|
|
|
@ -151,7 +151,7 @@ |
|
|
|
<span>共 {{ uploadOrderFileList.length }} 个</span> |
|
|
|
</div> |
|
|
|
<el-table :data="uploadOrderFileList" border :height="rightTableHeight" style="width: 100%;"> |
|
|
|
<el-table-column label="文件名" header-align="center" min-width="180" show-overflow-tooltip> |
|
|
|
<el-table-column label="文件名" header-align="center" min-width="160" show-overflow-tooltip> |
|
|
|
<template slot-scope="scope"> |
|
|
|
{{ scope.row.name }} |
|
|
|
</template> |
|
|
|
@ -161,7 +161,7 @@ |
|
|
|
{{ formatFileSize(scope.row.size) }} |
|
|
|
</template> |
|
|
|
</el-table-column> |
|
|
|
<el-table-column fixed="right" label="操作" width="70" header-align="center" align="center"> |
|
|
|
<el-table-column fixed="right" label="操作" width="60" header-align="center" align="center"> |
|
|
|
<template slot-scope="scope"> |
|
|
|
<el-link style="cursor: pointer" @click="removePendingUploadFile(scope.$index)">移除</el-link> |
|
|
|
</template> |
|
|
|
@ -172,6 +172,7 @@ |
|
|
|
<div class="panel-card upload-result-wrap"> |
|
|
|
<div class="panel-header list-header"> |
|
|
|
<span>上传结果</span> |
|
|
|
<span v-if="uploadProgress.total > 0">{{ getUploadProgressText() }}</span> |
|
|
|
</div> |
|
|
|
<el-table :data="uploadResults" border :height="rightTableHeight" style="width: 100%;"> |
|
|
|
<el-table-column prop="fileName" header-align="center" label="文件名" min-width="150" show-overflow-tooltip></el-table-column> |
|
|
|
@ -182,7 +183,7 @@ |
|
|
|
</el-tag> |
|
|
|
</template> |
|
|
|
</el-table-column> |
|
|
|
<el-table-column prop="message" label="信息" header-align="center" min-width="100" show-overflow-tooltip></el-table-column> |
|
|
|
<el-table-column prop="message" label="信息" header-align="center" min-width="90" show-overflow-tooltip></el-table-column> |
|
|
|
</el-table> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
@ -234,6 +235,16 @@ export default { |
|
|
|
uploadOrderFileList: [], |
|
|
|
uploadResults: [], |
|
|
|
uploadFileUid: 1, |
|
|
|
maxUploadFileCount: 20, |
|
|
|
maxUploadFileSize: 20 * 1024 * 1024, |
|
|
|
uploadRequestTimeoutMs: 1000 * 60 * 20, |
|
|
|
uploadProgress: { |
|
|
|
total: 0, |
|
|
|
completed: 0, |
|
|
|
success: 0, |
|
|
|
failed: 0, |
|
|
|
running: 0 |
|
|
|
}, |
|
|
|
layoutHeight: 560, |
|
|
|
leftTableHeight: 340, |
|
|
|
rightTableHeight: 150 |
|
|
|
@ -265,6 +276,7 @@ export default { |
|
|
|
this.uploadForm.operatorNo = '' |
|
|
|
this.uploadForm.date = this.getTodayDateString() |
|
|
|
this.uploadResults = [] |
|
|
|
this.resetUploadProgress() |
|
|
|
this.uploadOrderFileList = [] |
|
|
|
this.mesShiftData = {} |
|
|
|
this.mesShiftLogs = [] |
|
|
|
@ -470,7 +482,7 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
getMesLogFileName (row) { |
|
|
|
const value = this.getMesLogFieldValue(row, ['logFilename']) |
|
|
|
const value = this.getMesLogFieldValue(row, ['logFilename', 'filename', 'fileName', 'FileName', 'logFileName', 'logName', 'name']) |
|
|
|
return value || '-' |
|
|
|
}, |
|
|
|
|
|
|
|
@ -479,7 +491,6 @@ export default { |
|
|
|
return value || '-' |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
getMesLogStatus (row) { |
|
|
|
return this.getMesLogFieldValue(row, ['status', 'Status', 'state', 'State']) |
|
|
|
}, |
|
|
|
@ -548,15 +559,26 @@ export default { |
|
|
|
|
|
|
|
let invalidCount = 0 |
|
|
|
let duplicateCount = 0 |
|
|
|
let overLimitCount = 0 |
|
|
|
let overSizeCount = 0 |
|
|
|
let addedCount = 0 |
|
|
|
for (let i = 0; i < files.length; i++) { |
|
|
|
const file = files[i] |
|
|
|
const currentTotal = this.uploadOrderFileList.length + addedCount |
|
|
|
if (currentTotal >= this.maxUploadFileCount) { |
|
|
|
overLimitCount++ |
|
|
|
continue |
|
|
|
} |
|
|
|
const lowerName = (file.name || '').toLowerCase() |
|
|
|
const ext = lowerName.lastIndexOf('.') > -1 ? lowerName.substring(lowerName.lastIndexOf('.')) : '' |
|
|
|
if (!allowedExtMap[ext]) { |
|
|
|
invalidCount++ |
|
|
|
continue |
|
|
|
} |
|
|
|
if (Number(file.size || 0) > this.maxUploadFileSize) { |
|
|
|
overSizeCount++ |
|
|
|
continue |
|
|
|
} |
|
|
|
const fileKey = [file.name || '', file.size || 0, file.lastModified || 0].join('|') |
|
|
|
if (keyMap[fileKey]) { |
|
|
|
duplicateCount++ |
|
|
|
@ -579,6 +601,12 @@ export default { |
|
|
|
if (duplicateCount > 0) { |
|
|
|
this.$message.info('已自动忽略重复文件 ' + duplicateCount + ' 个') |
|
|
|
} |
|
|
|
if (overSizeCount > 0) { |
|
|
|
this.$message.warning('单个文件不能超过 20MB,已忽略 ' + overSizeCount + ' 个') |
|
|
|
} |
|
|
|
if (overLimitCount > 0) { |
|
|
|
this.$message.warning('最多可上传 20 个文件,已忽略 ' + overLimitCount + ' 个') |
|
|
|
} |
|
|
|
if (addedCount > 0) { |
|
|
|
this.$message.success('已添加文件 ' + addedCount + ' 个') |
|
|
|
} |
|
|
|
@ -588,6 +616,34 @@ export default { |
|
|
|
this.uploadOrderFileList.splice(index, 1) |
|
|
|
}, |
|
|
|
|
|
|
|
removeUploadedPendingFile (fileItem) { |
|
|
|
if (!fileItem || !this.uploadOrderFileList || this.uploadOrderFileList.length === 0) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let targetIndex = -1 |
|
|
|
if (fileItem.uid) { |
|
|
|
targetIndex = this.uploadOrderFileList.findIndex(item => item && item.uid === fileItem.uid) |
|
|
|
} |
|
|
|
if (targetIndex === -1) { |
|
|
|
targetIndex = this.uploadOrderFileList.findIndex(item => item === fileItem) |
|
|
|
} |
|
|
|
if (targetIndex === -1) { |
|
|
|
const targetName = fileItem.name || '' |
|
|
|
const targetSize = fileItem.size || 0 |
|
|
|
const targetLastModified = fileItem.lastModified || 0 |
|
|
|
targetIndex = this.uploadOrderFileList.findIndex(item => |
|
|
|
(item.name || '') === targetName && |
|
|
|
(item.size || 0) === targetSize && |
|
|
|
(item.lastModified || 0) === targetLastModified |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
if (targetIndex > -1) { |
|
|
|
this.uploadOrderFileList.splice(targetIndex, 1) |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
formatFileSize (size) { |
|
|
|
if (!size) { |
|
|
|
return '-' |
|
|
|
@ -596,6 +652,9 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
validateUploadOrderForm () { |
|
|
|
if (this.saveLoading) { |
|
|
|
return false |
|
|
|
} |
|
|
|
if (!this.uploadForm.process) { |
|
|
|
this.$message.warning('请选择工序') |
|
|
|
return false |
|
|
|
@ -616,9 +675,68 @@ export default { |
|
|
|
this.$message.warning('请先选择上传文件') |
|
|
|
return false |
|
|
|
} |
|
|
|
if (this.uploadOrderFileList.length > this.maxUploadFileCount) { |
|
|
|
this.$message.warning('最多只能上传 20 个文件') |
|
|
|
return false |
|
|
|
} |
|
|
|
return true |
|
|
|
}, |
|
|
|
|
|
|
|
getUploadProgressText () { |
|
|
|
const progress = this.uploadProgress |
|
|
|
return '已完成 ' + progress.completed + '/' + progress.total + |
|
|
|
'(成功 ' + progress.success + ',失败 ' + progress.failed + |
|
|
|
(progress.running > 0 ? ',进行中 ' + progress.running : '') + ')' |
|
|
|
}, |
|
|
|
|
|
|
|
resetUploadProgress () { |
|
|
|
this.uploadProgress = { |
|
|
|
total: 0, |
|
|
|
completed: 0, |
|
|
|
success: 0, |
|
|
|
failed: 0, |
|
|
|
running: 0 |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
async uploadSingleOrderFile (fileItem, index, commonPayload) { |
|
|
|
const realFile = fileItem.raw || fileItem |
|
|
|
if (!realFile) { |
|
|
|
return { |
|
|
|
fileName: fileItem.name || '未知文件', |
|
|
|
success: false, |
|
|
|
statusText: '失败', |
|
|
|
message: '文件内容为空' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const formData = new FormData() |
|
|
|
formData.append('process', commonPayload.process) |
|
|
|
formData.append('machineNo', commonPayload.machineNo) |
|
|
|
formData.append('date', commonPayload.currentDate) |
|
|
|
formData.append('shift', commonPayload.shiftValue) |
|
|
|
formData.append('operatorNo', commonPayload.operatorNo) |
|
|
|
formData.append('log', realFile, fileItem.name || realFile.name || ('log_' + (index + 1) + '.txt')) |
|
|
|
|
|
|
|
try { |
|
|
|
const { data } = await uploadMesOrderLog(formData, { timeout: this.uploadRequestTimeoutMs }) |
|
|
|
const isSuccess = data && data.code === 0 |
|
|
|
return { |
|
|
|
fileName: fileItem.name || realFile.name || ('log_' + (index + 1)), |
|
|
|
success: isSuccess, |
|
|
|
statusText: isSuccess ? '成功' : '失败', |
|
|
|
message: (data && data.msg) || (isSuccess ? '上传成功' : '上传失败') |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
return { |
|
|
|
fileName: fileItem.name || realFile.name || ('log_' + (index + 1)), |
|
|
|
success: false, |
|
|
|
statusText: '失败', |
|
|
|
message: this.extractErrorMessage(e, '上传失败') |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
async saveUploadOrder () { |
|
|
|
if (!this.validateUploadOrderForm()) { |
|
|
|
return |
|
|
|
@ -627,64 +745,54 @@ export default { |
|
|
|
const shiftValue = this.getShiftValueForApi() |
|
|
|
this.uploadForm.date = currentDate |
|
|
|
this.saveLoading = true |
|
|
|
const resultList = [] |
|
|
|
let successCount = 0 |
|
|
|
this.uploadResults = [] |
|
|
|
this.resetUploadProgress() |
|
|
|
|
|
|
|
for (let i = 0; i < this.uploadOrderFileList.length; i++) { |
|
|
|
const fileItem = this.uploadOrderFileList[i] |
|
|
|
const realFile = fileItem.raw || fileItem |
|
|
|
if (!realFile) { |
|
|
|
resultList.push({ |
|
|
|
fileName: fileItem.name || '未知文件', |
|
|
|
success: false, |
|
|
|
statusText: '失败', |
|
|
|
message: '文件内容为空' |
|
|
|
}) |
|
|
|
continue |
|
|
|
try { |
|
|
|
const taskFileList = this.uploadOrderFileList.slice() |
|
|
|
this.uploadProgress.total = taskFileList.length |
|
|
|
const commonPayload = { |
|
|
|
process: this.uploadForm.process, |
|
|
|
machineNo: this.uploadForm.machineNo, |
|
|
|
currentDate: currentDate, |
|
|
|
shiftValue: shiftValue, |
|
|
|
operatorNo: this.uploadForm.operatorNo |
|
|
|
} |
|
|
|
|
|
|
|
const formData = new FormData() |
|
|
|
formData.append('process', this.uploadForm.process) |
|
|
|
formData.append('machineNo', this.uploadForm.machineNo) |
|
|
|
formData.append('date', currentDate) |
|
|
|
formData.append('shift', shiftValue) |
|
|
|
formData.append('operatorNo', this.uploadForm.operatorNo) |
|
|
|
formData.append('log', realFile, fileItem.name || realFile.name || ('log_' + (i + 1) + '.txt')) |
|
|
|
|
|
|
|
try { |
|
|
|
const { data } = await uploadMesOrderLog(formData) |
|
|
|
const isSuccess = data && data.code === 0 |
|
|
|
if (isSuccess) { |
|
|
|
successCount += 1 |
|
|
|
const resultList = [] |
|
|
|
|
|
|
|
for (let i = 0; i < taskFileList.length; i++) { |
|
|
|
const currentFileItem = taskFileList[i] |
|
|
|
this.uploadProgress.running = 1 |
|
|
|
const result = await this.uploadSingleOrderFile(currentFileItem, i, commonPayload) |
|
|
|
this.uploadProgress.running = 0 |
|
|
|
|
|
|
|
resultList.push(result) |
|
|
|
this.uploadProgress.completed += 1 |
|
|
|
if (result.success) { |
|
|
|
this.uploadProgress.success += 1 |
|
|
|
this.removeUploadedPendingFile(currentFileItem) |
|
|
|
} else { |
|
|
|
this.uploadProgress.failed += 1 |
|
|
|
} |
|
|
|
resultList.push({ |
|
|
|
fileName: fileItem.name || realFile.name || ('log_' + (i + 1)), |
|
|
|
success: isSuccess, |
|
|
|
statusText: isSuccess ? '成功' : '失败', |
|
|
|
message: (data && data.msg) || (isSuccess ? '上传成功' : '上传失败') |
|
|
|
}) |
|
|
|
} catch (e) { |
|
|
|
resultList.push({ |
|
|
|
fileName: fileItem.name || realFile.name || ('log_' + (i + 1)), |
|
|
|
success: false, |
|
|
|
statusText: '失败', |
|
|
|
message: this.extractErrorMessage(e, '上传失败') |
|
|
|
}) |
|
|
|
this.uploadResults = resultList.slice() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.uploadResults = resultList |
|
|
|
const failCount = resultList.length - successCount |
|
|
|
if (failCount === 0) { |
|
|
|
this.$message.success('上传完成:' + successCount + ' 个成功') |
|
|
|
} else if (successCount > 0) { |
|
|
|
this.$message.warning('上传完成:成功 ' + successCount + ' 个,失败 ' + failCount + ' 个') |
|
|
|
} else { |
|
|
|
this.$message.error('上传完成:全部失败') |
|
|
|
} |
|
|
|
this.uploadResults = resultList |
|
|
|
const successCount = this.uploadProgress.success |
|
|
|
const failCount = this.uploadProgress.failed |
|
|
|
if (failCount === 0) { |
|
|
|
this.$message.success('上传完成:' + successCount + ' 个成功') |
|
|
|
} else if (successCount > 0) { |
|
|
|
this.$message.warning('上传完成:成功 ' + successCount + ' 个,失败 ' + failCount + ' 个') |
|
|
|
} else { |
|
|
|
this.$message.error('上传完成:全部失败') |
|
|
|
} |
|
|
|
|
|
|
|
await this.loadMesShiftData(false) |
|
|
|
this.saveLoading = false |
|
|
|
await this.loadMesShiftData(false) |
|
|
|
} finally { |
|
|
|
this.uploadProgress.running = 0 |
|
|
|
this.saveLoading = false |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
extractErrorMessage (error, defaultMessage) { |
|
|
|
@ -708,6 +816,7 @@ export default { |
|
|
|
handleDialogClosed () { |
|
|
|
this.uploadOrderFileList = [] |
|
|
|
this.uploadResults = [] |
|
|
|
this.resetUploadProgress() |
|
|
|
if (this.$refs.orderFileInput) { |
|
|
|
this.$refs.orderFileInput.value = '' |
|
|
|
} |
|
|
|
|