diff --git a/src/views/modules/yieldReport/com_tid_upload_mt_log.vue b/src/views/modules/yieldReport/com_tid_upload_mt_log.vue
index 3f89930..1610bbc 100644
--- a/src/views/modules/yieldReport/com_tid_upload_mt_log.vue
+++ b/src/views/modules/yieldReport/com_tid_upload_mt_log.vue
@@ -44,15 +44,23 @@
:height="leftTableHeight"
v-loading="shiftLoading"
style="width: 100%; margin-top: 10px;">
-
+
+
+ {{ getMesLogFileName(scope.row) }}
+
+
-
- {{ Number(scope.row.status) === 1 ? '成功' : '失败' }}
+
+ {{ getMesLogStatusText(scope.row) }}
-
+
+
+ {{ getMesLogResultMessage(scope.row) }}
+
+
@@ -133,6 +141,7 @@
@@ -143,7 +152,7 @@
-
+
@@ -183,6 +192,16 @@ export default {
uploadMtFileList: [],
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
@@ -211,6 +230,7 @@ export default {
this.mesShiftLogs = []
this.uploadMtFileList = []
this.uploadResults = []
+ this.resetUploadProgress()
this.updateDialogLayout()
await this.loadCurrentScheduleShift()
@@ -343,8 +363,56 @@ export default {
return this.mesShiftData[fieldName]
},
+ getMesLogFieldValue (row, fieldList) {
+ if (!row || !Array.isArray(fieldList)) {
+ return ''
+ }
+ for (let i = 0; i < fieldList.length; i++) {
+ const fieldName = fieldList[i]
+ const fieldValue = row[fieldName]
+ if (fieldValue !== undefined && fieldValue !== null && fieldValue !== '') {
+ return fieldValue
+ }
+ }
+ return ''
+ },
+
+ getMesLogFileName (row) {
+ const value = this.getMesLogFieldValue(row, ['logFilename', 'filename', 'fileName', 'FileName', 'logFileName', 'logName', 'name'])
+ return value || '-'
+ },
+
+ getMesLogResultMessage (row) {
+ const value = this.getMesLogFieldValue(row, ['message', 'msg', 'Message', 'result'])
+ return value || '-'
+ },
+
+ getMesLogStatus (row) {
+ return this.getMesLogFieldValue(row, ['status', 'Status', 'state', 'State'])
+ },
+
+ getMesLogStatusText (row) {
+ const statusValue = this.getMesLogStatus(row)
+ const statusText = String(statusValue)
+ if (statusText === '1') {
+ return '成功'
+ }
+ if (statusText === '0') {
+ return '失败'
+ }
+
+ const messageText = String(this.getMesLogResultMessage(row)).toLowerCase()
+ if (messageText.indexOf('成功') > -1 || messageText.indexOf('success') > -1) {
+ return '成功'
+ }
+ if (messageText && messageText !== '-') {
+ return '失败'
+ }
+ return '-'
+ },
+
getLogStatusType (status) {
- return Number(status) === 1 ? 'success' : 'danger'
+ return String(status) === '1' ? 'success' : 'danger'
},
triggerMtFileSelect () {
@@ -387,15 +455,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.uploadMtFileList.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++
@@ -418,6 +497,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 + ' 个')
}
@@ -427,6 +512,34 @@ export default {
this.uploadMtFileList.splice(index, 1)
},
+ removeUploadedPendingFile (fileItem) {
+ if (!fileItem || !this.uploadMtFileList || this.uploadMtFileList.length === 0) {
+ return
+ }
+
+ let targetIndex = -1
+ if (fileItem.uid) {
+ targetIndex = this.uploadMtFileList.findIndex(item => item && item.uid === fileItem.uid)
+ }
+ if (targetIndex === -1) {
+ targetIndex = this.uploadMtFileList.findIndex(item => item === fileItem)
+ }
+ if (targetIndex === -1) {
+ const targetName = fileItem.name || ''
+ const targetSize = fileItem.size || 0
+ const targetLastModified = fileItem.lastModified || 0
+ targetIndex = this.uploadMtFileList.findIndex(item =>
+ (item.name || '') === targetName &&
+ (item.size || 0) === targetSize &&
+ (item.lastModified || 0) === targetLastModified
+ )
+ }
+
+ if (targetIndex > -1) {
+ this.uploadMtFileList.splice(targetIndex, 1)
+ }
+ },
+
formatFileSize (size) {
if (!size) {
return '-'
@@ -435,6 +548,9 @@ export default {
},
validateUploadMtForm () {
+ if (this.saveLoading) {
+ return false
+ }
if (!this.uploadForm.machineNo) {
this.$message.warning('机器账号不能为空')
return false
@@ -443,9 +559,65 @@ export default {
this.$message.warning('请先选择上传文件')
return false
}
+ if (this.uploadMtFileList.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 uploadSingleMtFile (fileItem, index, currentDate) {
+ const realFile = fileItem.raw || fileItem
+ if (!realFile) {
+ return {
+ fileName: fileItem.name || '未知文件',
+ success: false,
+ statusText: '失败',
+ message: '文件内容为空'
+ }
+ }
+
+ const formData = new FormData()
+ formData.append('machineNo', this.uploadForm.machineNo)
+ formData.append('date', currentDate)
+ formData.append('log', realFile, fileItem.name || realFile.name || ('mt_' + (index + 1) + '.txt'))
+
+ try {
+ const { data } = await uploadMesMtLog(formData, { timeout: this.uploadRequestTimeoutMs })
+ const isSuccess = data && data.code === 0
+ return {
+ fileName: fileItem.name || realFile.name || ('mt_' + (index + 1)),
+ success: isSuccess,
+ statusText: isSuccess ? '成功' : '失败',
+ message: (data && data.msg) || (isSuccess ? '上传成功' : '上传失败')
+ }
+ } catch (e) {
+ return {
+ fileName: fileItem.name || realFile.name || ('mt_' + (index + 1)),
+ success: false,
+ statusText: '失败',
+ message: this.extractErrorMessage(e, '上传失败')
+ }
+ }
+ },
+
async saveUploadMtLog () {
if (!this.validateUploadMtForm()) {
return
@@ -453,61 +625,47 @@ export default {
const currentDate = this.getTodayDateString()
this.uploadForm.date = currentDate
this.saveLoading = true
- const resultList = []
- let successCount = 0
+ this.uploadResults = []
+ this.resetUploadProgress()
- for (let i = 0; i < this.uploadMtFileList.length; i++) {
- const fileItem = this.uploadMtFileList[i]
- const realFile = fileItem.raw || fileItem
- if (!realFile) {
- resultList.push({
- fileName: fileItem.name || '未知文件',
- success: false,
- statusText: '失败',
- message: '文件内容为空'
- })
- continue
+ try {
+ const taskFileList = this.uploadMtFileList.slice()
+ this.uploadProgress.total = taskFileList.length
+ const resultList = []
+
+ for (let i = 0; i < taskFileList.length; i++) {
+ const currentFileItem = taskFileList[i]
+ this.uploadProgress.running = 1
+ const result = await this.uploadSingleMtFile(currentFileItem, i, currentDate)
+ 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
+ }
+ this.uploadResults = resultList.slice()
}
- const formData = new FormData()
- formData.append('machineNo', this.uploadForm.machineNo)
- formData.append('date', currentDate)
- formData.append('log', realFile, fileItem.name || realFile.name || ('mt_' + (i + 1) + '.txt'))
-
- try {
- const { data } = await uploadMesMtLog(formData)
- const isSuccess = data && data.code === 0
- if (isSuccess) {
- successCount += 1
- }
- resultList.push({
- fileName: fileItem.name || realFile.name || ('mt_' + (i + 1)),
- success: isSuccess,
- statusText: isSuccess ? '成功' : '失败',
- message: (data && data.msg) || (isSuccess ? '上传成功' : '上传失败')
- })
- } catch (e) {
- resultList.push({
- fileName: fileItem.name || realFile.name || ('mt_' + (i + 1)),
- success: false,
- statusText: '失败',
- message: this.extractErrorMessage(e, '上传失败')
- })
+ 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('上传完成:全部失败')
}
- }
- 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('上传完成:全部失败')
+ await this.loadMesShiftData(false)
+ } finally {
+ this.uploadProgress.running = 0
+ this.saveLoading = false
}
-
- await this.loadMesShiftData(false)
- this.saveLoading = false
},
extractErrorMessage (error, defaultMessage) {
@@ -531,6 +689,7 @@ export default {
handleDialogClosed () {
this.uploadMtFileList = []
this.uploadResults = []
+ this.resetUploadProgress()
if (this.$refs.mtFileInput) {
this.$refs.mtFileInput.value = ''
}
@@ -641,6 +800,25 @@ export default {
margin-top: 12px;
}
+.shift-panel /deep/ .el-table td {
+ padding-top: 2px !important;
+ padding-bottom: 2px !important;
+}
+
+.shift-panel /deep/ .el-table .cell {
+ height: auto !important;
+ line-height: 20px !important;
+}
+
+.shift-panel /deep/ .el-tag {
+ height: 20px;
+ line-height: 18px;
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ white-space: nowrap;
+}
+
.upload-form {
margin-bottom: 0;
}