Browse Source

2026-08-04

TID接口
master
fengyuan_yang 1 day ago
parent
commit
2469bd3ba2
  1. 4
      src/api/yieldReport/produce_report_normal.js
  2. 5
      src/utils/httpRequest.js
  3. 223
      src/views/modules/yieldReport/com_tid_upload_order.vue

4
src/api/yieldReport/produce_report_normal.js

@ -120,10 +120,10 @@ export const getMaterialRecordList = data => createAPI('schedule/getMaterialReco
export const getMesShiftData = data => createAPI('schedule/getMesShiftData', 'POST', data) export const getMesShiftData = data => createAPI('schedule/getMesShiftData', 'POST', data)
// MES上传订单日志 // MES上传订单日志
export const uploadMesOrderLog = data => createFormAPI('schedule/uploadMesOrderLog', 'POST', data)
export const uploadMesOrderLog = (data, options = {}) => createFormAPI('schedule/uploadMesOrderLog', 'POST', data, options)
// MES结束班次 // MES结束班次
export const finishMesShift = data => createAPI('schedule/finishMesShift', 'POST', data) export const finishMesShift = data => createAPI('schedule/finishMesShift', 'POST', data)
// MES上传MT日志 // MES上传MT日志
export const uploadMesMtLog = data => createFormAPI('schedule/uploadMesMtLog', 'POST', data)
export const uploadMesMtLog = (data, options = {}) => createFormAPI('schedule/uploadMesMtLog', 'POST', data, options)

5
src/utils/httpRequest.js

@ -201,10 +201,11 @@ instanceForm.interceptors.response.use(response => {
return Promise.reject(error) return Promise.reject(error)
}) })
export const createFormAPI = (url, method, data) => {
export const createFormAPI = (url, method, data, options = {}) => {
return instanceForm({ return instanceForm({
url, url,
method, method,
data
data,
...options
}) })
} }

223
src/views/modules/yieldReport/com_tid_upload_order.vue

@ -151,7 +151,7 @@
<span> {{ uploadOrderFileList.length }} </span> <span> {{ uploadOrderFileList.length }} </span>
</div> </div>
<el-table :data="uploadOrderFileList" border :height="rightTableHeight" style="width: 100%;"> <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"> <template slot-scope="scope">
{{ scope.row.name }} {{ scope.row.name }}
</template> </template>
@ -161,7 +161,7 @@
{{ formatFileSize(scope.row.size) }} {{ formatFileSize(scope.row.size) }}
</template> </template>
</el-table-column> </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"> <template slot-scope="scope">
<el-link style="cursor: pointer" @click="removePendingUploadFile(scope.$index)">移除</el-link> <el-link style="cursor: pointer" @click="removePendingUploadFile(scope.$index)">移除</el-link>
</template> </template>
@ -172,6 +172,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>
@ -182,7 +183,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>
@ -234,6 +235,16 @@ export default {
uploadOrderFileList: [], uploadOrderFileList: [],
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
@ -265,6 +276,7 @@ export default {
this.uploadForm.operatorNo = '' this.uploadForm.operatorNo = ''
this.uploadForm.date = this.getTodayDateString() this.uploadForm.date = this.getTodayDateString()
this.uploadResults = [] this.uploadResults = []
this.resetUploadProgress()
this.uploadOrderFileList = [] this.uploadOrderFileList = []
this.mesShiftData = {} this.mesShiftData = {}
this.mesShiftLogs = [] this.mesShiftLogs = []
@ -470,7 +482,7 @@ export default {
}, },
getMesLogFileName (row) { getMesLogFileName (row) {
const value = this.getMesLogFieldValue(row, ['logFilename'])
const value = this.getMesLogFieldValue(row, ['logFilename', 'filename', 'fileName', 'FileName', 'logFileName', 'logName', 'name'])
return value || '-' return value || '-'
}, },
@ -479,7 +491,6 @@ export default {
return value || '-' return value || '-'
}, },
getMesLogStatus (row) { getMesLogStatus (row) {
return this.getMesLogFieldValue(row, ['status', 'Status', 'state', 'State']) return this.getMesLogFieldValue(row, ['status', 'Status', 'state', 'State'])
}, },
@ -548,15 +559,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.uploadOrderFileList.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++
@ -579,6 +601,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 + ' 个')
} }
@ -588,6 +616,34 @@ export default {
this.uploadOrderFileList.splice(index, 1) 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) { formatFileSize (size) {
if (!size) { if (!size) {
return '-' return '-'
@ -596,6 +652,9 @@ export default {
}, },
validateUploadOrderForm () { validateUploadOrderForm () {
if (this.saveLoading) {
return false
}
if (!this.uploadForm.process) { if (!this.uploadForm.process) {
this.$message.warning('请选择工序') this.$message.warning('请选择工序')
return false return false
@ -616,9 +675,68 @@ export default {
this.$message.warning('请先选择上传文件') this.$message.warning('请先选择上传文件')
return false return false
} }
if (this.uploadOrderFileList.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 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 () { async saveUploadOrder () {
if (!this.validateUploadOrderForm()) { if (!this.validateUploadOrderForm()) {
return return
@ -627,64 +745,54 @@ export default {
const shiftValue = this.getShiftValueForApi() const shiftValue = this.getShiftValueForApi()
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.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) { extractErrorMessage (error, defaultMessage) {
@ -708,6 +816,7 @@ export default {
handleDialogClosed () { handleDialogClosed () {
this.uploadOrderFileList = [] this.uploadOrderFileList = []
this.uploadResults = [] this.uploadResults = []
this.resetUploadProgress()
if (this.$refs.orderFileInput) { if (this.$refs.orderFileInput) {
this.$refs.orderFileInput.value = '' this.$refs.orderFileInput.value = ''
} }

Loading…
Cancel
Save