Browse Source

2026-08-05

TID接口
master
fengyuan_yang 2 months ago
parent
commit
2a6815042f
  1. 288
      src/views/modules/yieldReport/com_tid_upload_mt_log.vue

288
src/views/modules/yieldReport/com_tid_upload_mt_log.vue

@ -44,15 +44,23 @@
:height="leftTableHeight" :height="leftTableHeight"
v-loading="shiftLoading" v-loading="shiftLoading"
style="width: 100%; margin-top: 10px;"> style="width: 100%; margin-top: 10px;">
<el-table-column prop="filename" label="文件名" min-width="180" show-overflow-tooltip></el-table-column>
<el-table-column label="文件名" min-width="180" show-overflow-tooltip>
<template slot-scope="scope">
{{ getMesLogFileName(scope.row) }}
</template>
</el-table-column>
<el-table-column label="状态" width="90" align="center"> <el-table-column label="状态" width="90" align="center">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="getLogStatusType(scope.row.status)">
{{ Number(scope.row.status) === 1 ? '成功' : '失败' }}
<el-tag :type="getLogStatusType(getMesLogStatus(scope.row))">
{{ getMesLogStatusText(scope.row) }}
</el-tag> </el-tag>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="message" label="结果" min-width="140" show-overflow-tooltip></el-table-column>
<el-table-column label="结果" min-width="140" show-overflow-tooltip>
<template slot-scope="scope">
{{ getMesLogResultMessage(scope.row) }}
</template>
</el-table-column>
</el-table> </el-table>
</div> </div>
@ -133,6 +141,7 @@
<div class="panel-card upload-result-wrap"> <div class="panel-card upload-result-wrap">
<div class="panel-header list-header"> <div class="panel-header list-header">
<span>上传结果</span> <span>上传结果</span>
<span v-if="uploadProgress.total > 0">{{ getUploadProgressText() }}</span>
</div> </div>
<el-table :data="uploadResults" border :height="rightTableHeight" style="width: 100%;"> <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> <el-table-column prop="fileName" header-align="center" label="文件名" min-width="150" show-overflow-tooltip></el-table-column>
@ -143,7 +152,7 @@
</el-tag> </el-tag>
</template> </template>
</el-table-column> </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> </el-table>
</div> </div>
</div> </div>
@ -183,6 +192,16 @@ export default {
uploadMtFileList: [], uploadMtFileList: [],
uploadResults: [], uploadResults: [],
uploadFileUid: 1, 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, layoutHeight: 560,
leftTableHeight: 340, leftTableHeight: 340,
rightTableHeight: 150 rightTableHeight: 150
@ -211,6 +230,7 @@ export default {
this.mesShiftLogs = [] this.mesShiftLogs = []
this.uploadMtFileList = [] this.uploadMtFileList = []
this.uploadResults = [] this.uploadResults = []
this.resetUploadProgress()
this.updateDialogLayout() this.updateDialogLayout()
await this.loadCurrentScheduleShift() await this.loadCurrentScheduleShift()
@ -343,8 +363,56 @@ export default {
return this.mesShiftData[fieldName] 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) { getLogStatusType (status) {
return Number(status) === 1 ? 'success' : 'danger'
return String(status) === '1' ? 'success' : 'danger'
}, },
triggerMtFileSelect () { triggerMtFileSelect () {
@ -387,15 +455,26 @@ export default {
let invalidCount = 0 let invalidCount = 0
let duplicateCount = 0 let duplicateCount = 0
let overLimitCount = 0
let overSizeCount = 0
let addedCount = 0 let addedCount = 0
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
const file = files[i] const file = files[i]
const currentTotal = this.uploadMtFileList.length + addedCount
if (currentTotal >= this.maxUploadFileCount) {
overLimitCount++
continue
}
const lowerName = (file.name || '').toLowerCase() const lowerName = (file.name || '').toLowerCase()
const ext = lowerName.lastIndexOf('.') > -1 ? lowerName.substring(lowerName.lastIndexOf('.')) : '' const ext = lowerName.lastIndexOf('.') > -1 ? lowerName.substring(lowerName.lastIndexOf('.')) : ''
if (!allowedExtMap[ext]) { if (!allowedExtMap[ext]) {
invalidCount++ invalidCount++
continue continue
} }
if (Number(file.size || 0) > this.maxUploadFileSize) {
overSizeCount++
continue
}
const fileKey = [file.name || '', file.size || 0, file.lastModified || 0].join('|') const fileKey = [file.name || '', file.size || 0, file.lastModified || 0].join('|')
if (keyMap[fileKey]) { if (keyMap[fileKey]) {
duplicateCount++ duplicateCount++
@ -418,6 +497,12 @@ export default {
if (duplicateCount > 0) { if (duplicateCount > 0) {
this.$message.info('已自动忽略重复文件 ' + duplicateCount + ' 个') this.$message.info('已自动忽略重复文件 ' + duplicateCount + ' 个')
} }
if (overSizeCount > 0) {
this.$message.warning('单个文件不能超过 20MB,已忽略 ' + overSizeCount + ' 个')
}
if (overLimitCount > 0) {
this.$message.warning('最多可上传 20 个文件,已忽略 ' + overLimitCount + ' 个')
}
if (addedCount > 0) { if (addedCount > 0) {
this.$message.success('已添加文件 ' + addedCount + ' 个') this.$message.success('已添加文件 ' + addedCount + ' 个')
} }
@ -427,6 +512,34 @@ export default {
this.uploadMtFileList.splice(index, 1) 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) { formatFileSize (size) {
if (!size) { if (!size) {
return '-' return '-'
@ -435,6 +548,9 @@ export default {
}, },
validateUploadMtForm () { validateUploadMtForm () {
if (this.saveLoading) {
return false
}
if (!this.uploadForm.machineNo) { if (!this.uploadForm.machineNo) {
this.$message.warning('机器账号不能为空') this.$message.warning('机器账号不能为空')
return false return false
@ -443,9 +559,65 @@ export default {
this.$message.warning('请先选择上传文件') this.$message.warning('请先选择上传文件')
return false return false
} }
if (this.uploadMtFileList.length > this.maxUploadFileCount) {
this.$message.warning('最多只能上传 20 个文件')
return false
}
return true 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 () { async saveUploadMtLog () {
if (!this.validateUploadMtForm()) { if (!this.validateUploadMtForm()) {
return return
@ -453,61 +625,47 @@ export default {
const currentDate = this.getTodayDateString() const currentDate = this.getTodayDateString()
this.uploadForm.date = currentDate this.uploadForm.date = currentDate
this.saveLoading = true 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) { extractErrorMessage (error, defaultMessage) {
@ -531,6 +689,7 @@ export default {
handleDialogClosed () { handleDialogClosed () {
this.uploadMtFileList = [] this.uploadMtFileList = []
this.uploadResults = [] this.uploadResults = []
this.resetUploadProgress()
if (this.$refs.mtFileInput) { if (this.$refs.mtFileInput) {
this.$refs.mtFileInput.value = '' this.$refs.mtFileInput.value = ''
} }
@ -641,6 +800,25 @@ export default {
margin-top: 12px; 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 { .upload-form {
margin-bottom: 0; margin-bottom: 0;
} }

Loading…
Cancel
Save