|
@ -5,7 +5,6 @@ |
|
|
:options="initOptions" |
|
|
:options="initOptions" |
|
|
:file-status-text="fileStatusText" |
|
|
:file-status-text="fileStatusText" |
|
|
:auto-start="false" |
|
|
:auto-start="false" |
|
|
|
|
|
|
|
|
class="uploader-app" |
|
|
class="uploader-app" |
|
|
@file-added="onFileAdded" |
|
|
@file-added="onFileAdded" |
|
|
@file-success="onUploadSuccess" |
|
|
@file-success="onUploadSuccess" |
|
@ -147,6 +146,7 @@ export default { |
|
|
clearInterval(this.queryTimer) |
|
|
clearInterval(this.queryTimer) |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
|
|
|
|
|
|
clickUploader(e) { |
|
|
clickUploader(e) { |
|
|
this.$refs.uploadBtn.$el.click() |
|
|
this.$refs.uploadBtn.$el.click() |
|
|
}, |
|
|
}, |
|
@ -273,32 +273,151 @@ export default { |
|
|
this.skip = false |
|
|
this.skip = false |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
// handleUploadConfirm() { |
|
|
|
|
|
// if (this.$refs.uploader.fileList.length === 0) { |
|
|
|
|
|
// this.$message({ message: '请选择要上传的文件!', type: 'error', offset: 8 }) |
|
|
|
|
|
// return false |
|
|
|
|
|
// } |
|
|
|
|
|
// this.nowDate = getCurrentTime() |
|
|
|
|
|
// const jsonArrayToSend = [] |
|
|
|
|
|
// this.isSyncUpload = true |
|
|
|
|
|
// // 使用 Promise.all 确保所有异步操作完成 |
|
|
|
|
|
// Promise.all(this.$refs.uploader.fileList.map(async(item) => { |
|
|
|
|
|
// console.log('item', item) |
|
|
|
|
|
// const json = {} |
|
|
|
|
|
// const jsonArray = [] |
|
|
|
|
|
// const jsonString = {} |
|
|
|
|
|
|
|
|
|
|
|
// if (item.file.type.substring(0, item.file.type.indexOf('/')) === 'image') { |
|
|
|
|
|
// const fileBase64 = await this.getBase64(item.file) |
|
|
|
|
|
// const imgRes = await this.getImgPx(fileBase64) |
|
|
|
|
|
// item.file.px = imgRes.width + 'px*' + imgRes.height + 'px' |
|
|
|
|
|
// } else { |
|
|
|
|
|
// item.file.px = '' |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// jsonString.file_name = item.file.name |
|
|
|
|
|
// jsonString.file_size = item.file.size |
|
|
|
|
|
// jsonString.file_type = item.file.name.substring(item.name.lastIndexOf('.') + 1, item.file.name.length) |
|
|
|
|
|
// json.last_modified = item.file.lastModified |
|
|
|
|
|
// jsonString.file_path = '' |
|
|
|
|
|
// jsonString.sequence = null |
|
|
|
|
|
// jsonString.archive_id = this.arcId |
|
|
|
|
|
// jsonString.file_dpi = item.file.px |
|
|
|
|
|
// jsonString.file_thumbnail = '' |
|
|
|
|
|
// jsonString.create_time = this.nowDate |
|
|
|
|
|
// jsonString.id = null |
|
|
|
|
|
// jsonArray.push(jsonString) |
|
|
|
|
|
|
|
|
|
|
|
// if (this.isBatchMount === 'true') { |
|
|
|
|
|
// json.categoryId = this.selectedCategory.id |
|
|
|
|
|
// } else { |
|
|
|
|
|
// json.documentId = this.selectedDocument.id |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// json.archivesId = this.arcId |
|
|
|
|
|
// json.identifier = item.uniqueIdentifier |
|
|
|
|
|
// json.filename = item.name |
|
|
|
|
|
// json.totalChunks = item.chunks.length - 1 |
|
|
|
|
|
// json.totalSize = item.size |
|
|
|
|
|
// json.fileJsonString = JSON.stringify(jsonArray) |
|
|
|
|
|
|
|
|
|
|
|
// jsonArrayToSend.push(json) |
|
|
|
|
|
// })).then(() => { |
|
|
|
|
|
// console.log('jsonArrayToSend', jsonArrayToSend) |
|
|
|
|
|
|
|
|
|
|
|
// if (this.$refs.uploader.fileList.every(item => item.completed) && this.isUpload) { |
|
|
|
|
|
// if (this.isBatchMount === 'true') { |
|
|
|
|
|
// // 本地挂接 |
|
|
|
|
|
// axios.post(this.baseApi + '/api/collect/merge', jsonArrayToSend, { |
|
|
|
|
|
// headers: { |
|
|
|
|
|
// 'Authorization': getToken() |
|
|
|
|
|
// } |
|
|
|
|
|
// }).then((res) => { |
|
|
|
|
|
// console.log(res) |
|
|
|
|
|
// if (res.data.code === 200 && res.data.data.length === 1 && res.data.data[0] !== '') { |
|
|
|
|
|
// this.$message({ message: '文件上传成功', type: 'success', offset: 8 }) |
|
|
|
|
|
// this.$emit('onUploadSuccess', res.data.data[0], this.fileName, jsonArrayToSend) |
|
|
|
|
|
// } else { |
|
|
|
|
|
// this.$message({ message: '文件上传失败', type: 'error', offset: 8 }) |
|
|
|
|
|
// } |
|
|
|
|
|
// this.isSyncUpload = false |
|
|
|
|
|
// setTimeout(() => { |
|
|
|
|
|
// this.isUpload = false |
|
|
|
|
|
// }, 2000) |
|
|
|
|
|
// }).catch(err => { |
|
|
|
|
|
// this.isSyncUpload = false |
|
|
|
|
|
// setTimeout(() => { |
|
|
|
|
|
// this.isUpload = false |
|
|
|
|
|
// }, 2000) |
|
|
|
|
|
// this.$emit('onUploadError', err) |
|
|
|
|
|
// this.$message({ message: '上传服务器失败', type: 'error', offset: 8 }) |
|
|
|
|
|
// clearInterval(this.queryTimer) |
|
|
|
|
|
// }) |
|
|
|
|
|
// } else { |
|
|
|
|
|
// // 预归档库 |
|
|
|
|
|
// axios.post(this.baseApi + '/api/re-document/merge', jsonArrayToSend, { |
|
|
|
|
|
// headers: { |
|
|
|
|
|
// 'Authorization': getToken() |
|
|
|
|
|
// } |
|
|
|
|
|
// }).then((res) => { |
|
|
|
|
|
// console.log(res) |
|
|
|
|
|
// if (res.data.code === 200 && res.data.data.length === 1 && res.data.data[0] !== '') { |
|
|
|
|
|
// this.$message({ message: '文件上传成功', type: 'success', offset: 8 }) |
|
|
|
|
|
// this.$emit('onUploadSuccess', res.data.data[0], this.fileName, jsonArrayToSend) |
|
|
|
|
|
// } else { |
|
|
|
|
|
// this.$message({ message: '文件上传失败', type: 'error', offset: 8 }) |
|
|
|
|
|
// } |
|
|
|
|
|
// this.isSyncUpload = false |
|
|
|
|
|
// }).catch(err => { |
|
|
|
|
|
// this.isSyncUpload = false |
|
|
|
|
|
// setTimeout(() => { |
|
|
|
|
|
// this.isUpload = false |
|
|
|
|
|
// }, 2000) |
|
|
|
|
|
// this.$emit('onUploadError', err) |
|
|
|
|
|
// this.$message({ message: '上传服务器失败', type: 'error', offset: 8 }) |
|
|
|
|
|
// clearInterval(this.queryTimer) |
|
|
|
|
|
// }) |
|
|
|
|
|
// } |
|
|
|
|
|
// } else { |
|
|
|
|
|
// this.isSyncUpload = false |
|
|
|
|
|
// setTimeout(() => { |
|
|
|
|
|
// this.isUpload = false |
|
|
|
|
|
// }, 2000) |
|
|
|
|
|
// this.$message({ message: '请耐心等待文件上传完成后再保存!', type: 'error', offset: 8 }) |
|
|
|
|
|
// } |
|
|
|
|
|
// }) |
|
|
|
|
|
// }, |
|
|
handleUploadConfirm() { |
|
|
handleUploadConfirm() { |
|
|
|
|
|
// 检查是否选择了文件 |
|
|
if (this.$refs.uploader.fileList.length === 0) { |
|
|
if (this.$refs.uploader.fileList.length === 0) { |
|
|
this.$message({ message: '请选择要上传的文件!', type: 'error', offset: 8 }) |
|
|
|
|
|
|
|
|
this.showMessage('请选择要上传的文件!', 'error') |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.nowDate = getCurrentTime() |
|
|
this.nowDate = getCurrentTime() |
|
|
const jsonArrayToSend = [] |
|
|
const jsonArrayToSend = [] |
|
|
this.isSyncUpload = true |
|
|
this.isSyncUpload = true |
|
|
// 使用 Promise.all 确保所有异步操作完成 |
|
|
|
|
|
Promise.all(this.$refs.uploader.fileList.map(async(item) => { |
|
|
|
|
|
console.log('item', item) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理文件列表 |
|
|
|
|
|
const processFile = async(item) => { |
|
|
const json = {} |
|
|
const json = {} |
|
|
const jsonArray = [] |
|
|
const jsonArray = [] |
|
|
const jsonString = {} |
|
|
const jsonString = {} |
|
|
|
|
|
|
|
|
if (item.file.type.substring(0, item.file.type.indexOf('/')) === 'image') { |
|
|
|
|
|
|
|
|
// 处理图片文件 |
|
|
|
|
|
if (item.file.type.startsWith('image')) { |
|
|
const fileBase64 = await this.getBase64(item.file) |
|
|
const fileBase64 = await this.getBase64(item.file) |
|
|
const imgRes = await this.getImgPx(fileBase64) |
|
|
const imgRes = await this.getImgPx(fileBase64) |
|
|
item.file.px = imgRes.width + 'px*' + imgRes.height + 'px' |
|
|
|
|
|
|
|
|
item.file.px = `${imgRes.width}px*${imgRes.height}px` |
|
|
} else { |
|
|
} else { |
|
|
item.file.px = '' |
|
|
item.file.px = '' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 填充 jsonString 对象 |
|
|
jsonString.file_name = item.file.name |
|
|
jsonString.file_name = item.file.name |
|
|
jsonString.file_size = item.file.size |
|
|
jsonString.file_size = item.file.size |
|
|
jsonString.file_type = item.file.name.substring(item.name.lastIndexOf('.') + 1, item.file.name.length) |
|
|
|
|
|
|
|
|
jsonString.file_type = item.file.name.split('.').pop() |
|
|
json.last_modified = item.file.lastModified |
|
|
json.last_modified = item.file.lastModified |
|
|
jsonString.file_path = '' |
|
|
jsonString.file_path = '' |
|
|
jsonString.sequence = null |
|
|
jsonString.sequence = null |
|
@ -308,14 +427,15 @@ export default { |
|
|
jsonString.create_time = this.nowDate |
|
|
jsonString.create_time = this.nowDate |
|
|
jsonString.id = null |
|
|
jsonString.id = null |
|
|
jsonArray.push(jsonString) |
|
|
jsonArray.push(jsonString) |
|
|
console.log('isBatchMount', this.isBatchMount) |
|
|
|
|
|
console.log('isBatchMount', typeof this.isBatchMount) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 根据挂载类型设置不同的 id |
|
|
if (this.isBatchMount === 'true') { |
|
|
if (this.isBatchMount === 'true') { |
|
|
json.categoryId = this.selectedCategory.id |
|
|
json.categoryId = this.selectedCategory.id |
|
|
} else { |
|
|
} else { |
|
|
json.documentId = this.selectedDocument.id |
|
|
json.documentId = this.selectedDocument.id |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 填充 json 对象 |
|
|
json.archivesId = this.arcId |
|
|
json.archivesId = this.arcId |
|
|
json.identifier = item.uniqueIdentifier |
|
|
json.identifier = item.uniqueIdentifier |
|
|
json.filename = item.name |
|
|
json.filename = item.name |
|
@ -324,68 +444,74 @@ export default { |
|
|
json.fileJsonString = JSON.stringify(jsonArray) |
|
|
json.fileJsonString = JSON.stringify(jsonArray) |
|
|
|
|
|
|
|
|
jsonArrayToSend.push(json) |
|
|
jsonArrayToSend.push(json) |
|
|
})).then(() => { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 使用 Promise.all 确保所有异步操作完成 |
|
|
|
|
|
Promise.all(this.$refs.uploader.fileList.map(processFile)) |
|
|
|
|
|
.then(() => { |
|
|
console.log('jsonArrayToSend', jsonArrayToSend) |
|
|
console.log('jsonArrayToSend', jsonArrayToSend) |
|
|
|
|
|
|
|
|
|
|
|
// 检查文件是否全部上传完成 |
|
|
if (this.$refs.uploader.fileList.every(item => item.completed) && this.isUpload) { |
|
|
if (this.$refs.uploader.fileList.every(item => item.completed) && this.isUpload) { |
|
|
if (this.isBatchMount === 'true') { |
|
|
|
|
|
axios.post(this.baseApi + '/api/collect/merge', jsonArrayToSend, { |
|
|
|
|
|
headers: { |
|
|
|
|
|
'Authorization': getToken() |
|
|
|
|
|
} |
|
|
|
|
|
}).then((res) => { |
|
|
|
|
|
console.log(res) |
|
|
|
|
|
if (res.data.code === 200 && res.data.data[0] !== '') { |
|
|
|
|
|
this.$message({ message: '文件上传成功', type: 'success', offset: 8 }) |
|
|
|
|
|
this.$emit('onUploadSuccess', res.data.data, this.fileName, jsonArrayToSend) |
|
|
|
|
|
|
|
|
const apiUrl = this.isBatchMount === 'true' |
|
|
|
|
|
? `${this.baseApi}/api/collect/merge` |
|
|
|
|
|
: `${this.baseApi}/api/re-document/merge` |
|
|
|
|
|
|
|
|
|
|
|
// 发送请求 |
|
|
|
|
|
this.sendRequest(apiUrl, jsonArrayToSend) |
|
|
|
|
|
.then((res) => { |
|
|
|
|
|
if (res.data.code === 200 && res.data.data.length === 1 && res.data.data[0] !== '') { |
|
|
|
|
|
this.showMessage('文件上传成功', 'success') |
|
|
|
|
|
this.$emit('onUploadSuccess', res.data.data[0], this.fileName, jsonArrayToSend) |
|
|
} else { |
|
|
} else { |
|
|
this.$message({ message: '文件上传失败', type: 'error', offset: 8 }) |
|
|
|
|
|
|
|
|
this.showMessage('文件上传失败', 'error') |
|
|
} |
|
|
} |
|
|
this.isSyncUpload = false |
|
|
this.isSyncUpload = false |
|
|
|
|
|
if (this.isBatchMount === 'true') { |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
this.isUpload = false |
|
|
this.isUpload = false |
|
|
}, 2000) |
|
|
}, 2000) |
|
|
}).catch(err => { |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((err) => { |
|
|
|
|
|
this.handleRequestError(err) |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
this.isSyncUpload = false |
|
|
this.isSyncUpload = false |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
this.isUpload = false |
|
|
this.isUpload = false |
|
|
}, 2000) |
|
|
}, 2000) |
|
|
this.$emit('onUploadError', err) |
|
|
|
|
|
this.$message({ message: '上传服务器失败', type: 'error', offset: 8 }) |
|
|
|
|
|
clearInterval(this.queryTimer) |
|
|
|
|
|
|
|
|
this.showMessage('请耐心等待文件上传完成后再保存!', 'error') |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
|
|
|
axios.post(this.baseApi + '/api/re-document/merge', jsonArrayToSend, { |
|
|
|
|
|
|
|
|
.catch((err) => { |
|
|
|
|
|
this.handleRequestError(err) |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 显示消息的方法 |
|
|
|
|
|
showMessage(message, type) { |
|
|
|
|
|
this.$message({ message, type, offset: 8 }) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 发送请求的方法 |
|
|
|
|
|
sendRequest(url, data) { |
|
|
|
|
|
return axios.post(url, data, { |
|
|
headers: { |
|
|
headers: { |
|
|
'Authorization': getToken() |
|
|
'Authorization': getToken() |
|
|
} |
|
|
} |
|
|
}).then((res) => { |
|
|
|
|
|
console.log(res) |
|
|
|
|
|
if (res.data.code === 200 && res.data.data !== '') { |
|
|
|
|
|
this.$message({ message: '文件上传成功', type: 'success', offset: 8 }) |
|
|
|
|
|
this.$emit('onUploadSuccess', res.data.data, this.fileName, jsonArrayToSend) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.$message({ message: '文件上传失败', type: 'error', offset: 8 }) |
|
|
|
|
|
} |
|
|
|
|
|
this.isSyncUpload = false |
|
|
|
|
|
}).catch(err => { |
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 处理请求错误的方法 |
|
|
|
|
|
handleRequestError(err) { |
|
|
this.isSyncUpload = false |
|
|
this.isSyncUpload = false |
|
|
setTimeout(() => { |
|
|
setTimeout(() => { |
|
|
this.isUpload = false |
|
|
this.isUpload = false |
|
|
}, 2000) |
|
|
}, 2000) |
|
|
this.$emit('onUploadError', err) |
|
|
this.$emit('onUploadError', err) |
|
|
this.$message({ message: '上传服务器失败', type: 'error', offset: 8 }) |
|
|
|
|
|
|
|
|
this.showMessage('上传服务器失败', 'error') |
|
|
clearInterval(this.queryTimer) |
|
|
clearInterval(this.queryTimer) |
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
this.isSyncUpload = false |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
this.isUpload = false |
|
|
|
|
|
}, 2000) |
|
|
|
|
|
this.$message({ message: '请耐心等待文件上传完成后再保存!', type: 'error', offset: 8 }) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
}, |
|
|
// 上传失败 |
|
|
// 上传失败 |
|
|
onFileError(rootFile, file, response, chunk) { |
|
|
onFileError(rootFile, file, response, chunk) { |
|
@ -414,6 +540,23 @@ export default { |
|
|
resolve({ width, height }) |
|
|
resolve({ width, height }) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
handleClearData() { |
|
|
|
|
|
this.isStartUpload = false |
|
|
|
|
|
this.md5ProgressText = 0 |
|
|
|
|
|
this.isMd5Upload = false |
|
|
|
|
|
this.isUpload = false |
|
|
|
|
|
this.uploadProcessNum = 0 |
|
|
|
|
|
this.uploadSpeed = 0 |
|
|
|
|
|
this.fileName = '' |
|
|
|
|
|
this.isSyncUpload = false |
|
|
|
|
|
const uploaderInstance = this.$refs.uploader.uploader |
|
|
|
|
|
console.log('uploaderInstance.fileList222', uploaderInstance.fileList) |
|
|
|
|
|
uploaderInstance.fileList.forEach(file => file.cancel()) |
|
|
|
|
|
uploaderInstance.fileList = [] |
|
|
|
|
|
uploaderInstance.files = [] |
|
|
|
|
|
this.$refs.uploader.files = [] |
|
|
|
|
|
this.$refs.uploader.fileList = [] |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|