diff --git a/src/api/yieldReport/produce_report_normal.js b/src/api/yieldReport/produce_report_normal.js
index 196d902..9822818 100644
--- a/src/api/yieldReport/produce_report_normal.js
+++ b/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)
// MES上传订单日志
-export const uploadMesOrderLog = data => createFormAPI('schedule/uploadMesOrderLog', 'POST', data)
+export const uploadMesOrderLog = (data, options = {}) => createFormAPI('schedule/uploadMesOrderLog', 'POST', data, options)
// MES结束班次
export const finishMesShift = data => createAPI('schedule/finishMesShift', 'POST', data)
// MES上传MT日志
-export const uploadMesMtLog = data => createFormAPI('schedule/uploadMesMtLog', 'POST', data)
+export const uploadMesMtLog = (data, options = {}) => createFormAPI('schedule/uploadMesMtLog', 'POST', data, options)
diff --git a/src/utils/httpRequest.js b/src/utils/httpRequest.js
index b3015eb..d9aa094 100644
--- a/src/utils/httpRequest.js
+++ b/src/utils/httpRequest.js
@@ -201,10 +201,11 @@ instanceForm.interceptors.response.use(response => {
return Promise.reject(error)
})
-export const createFormAPI = (url, method, data) => {
+export const createFormAPI = (url, method, data, options = {}) => {
return instanceForm({
url,
method,
- data
+ data,
+ ...options
})
}
diff --git a/src/views/modules/yieldReport/com_tid_upload_order.vue b/src/views/modules/yieldReport/com_tid_upload_order.vue
index c38a97e..11fdcbd 100644
--- a/src/views/modules/yieldReport/com_tid_upload_order.vue
+++ b/src/views/modules/yieldReport/com_tid_upload_order.vue
@@ -151,7 +151,7 @@
共 {{ uploadOrderFileList.length }} 个
-
+
{{ scope.row.name }}
@@ -161,7 +161,7 @@
{{ formatFileSize(scope.row.size) }}
-
+
移除
@@ -172,6 +172,7 @@
@@ -182,7 +183,7 @@
-
+
@@ -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 = ''
}