Merge pull request #188 from jamebal/dev

perf: 优化上传文件夹时显示的速度
This commit is contained in:
jmal 2024-06-16 23:10:54 +08:00 committed by GitHub
commit c108564b9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 13 deletions

View File

@ -132,7 +132,7 @@ export default {
// speedSmoothingFactor: 0.1,
// progressCallbacksInterval: 500,
maxChunkRetries: 3, // 最大重试次数
simultaneousUploads: 2, // 并发上传数
simultaneousUploads: 3, // 并发上传数
testChunks: true, // 是否开启服务器分片校验
// 服务器分片校验函数,秒传及断点续传基础
checkChunkUploadedByResponse: function (chunk, message) {
@ -408,12 +408,11 @@ export default {
}
},
onFileProgress(rootFile, file, chunk) {
this.netSpeed = formatNetSpeed(file.currentSpeed)
this.netSpeed = formatNetSpeed(file.currentSpeed, false)
this.process = Math.trunc(window.uploader.progress() * 100)
if (this.process === -10 || this.process === 100 || this.fileListLength === 0) {
document.title = `${this.$route.meta.title}`
} else {
document.title = `${this.process}% | ${this.$route.meta.title}`
this.setPageTitle()
if (rootFile.isFolder && this.process < 100) {
this.statusSet(rootFile.id, 'progress', formatNetSpeed(file.currentSpeed, true))
}
if (this.process > 0 && this.process < 100 && window.uploader.fileList.length > 0) {
window.onbeforeunload = function () {
@ -662,8 +661,12 @@ export default {
* @param id
* @param status
*/
statusSet(id, status) {
statusSet(id, status, progressText) {
const statusMap = {
progress: {
text: progressText,
bgc: '#ffffff00'
},
md5: {
text: '校验MD5',
bgc: '#fff'
@ -686,6 +689,11 @@ export default {
}
}
if (status === 'progress') {
$('.uploader-file-status').find('span:eq(1) em').text(progressText)
return
}
this.$nextTick(() => {
$(`<p class="myStatus_${id}"></p>`).appendTo(`.file_${id} .uploader-file-status`).css({
'position': 'absolute',

View File

@ -143,17 +143,18 @@ export function formatSize(size) {
/**
* formatNetSpeed
* @param {*} size
* @param space
*/
export function formatNetSpeed(size) {
export function formatNetSpeed(size, space) {
if (size === 0) {
return '0B/s'
return space ? '0 B / s' : '0B/s'
} else if (size < 1024) {
return size + 'B/s'
return size + (space ? ' B / s' : 'B/s')
} else if (size < 1024 * 1024) {
return (size/1024).toFixed(2) + 'KB/s'
return (size/1024).toFixed(2) + (space ? ' KB / s' : 'KB/s')
} else if (size < 1024 * 1024 * 1024) {
return (size/(1024 * 1024)).toFixed(2) + 'MB/s'
return (size/(1024 * 1024)).toFixed(2) + (space ? ' MB / s' : 'MB/s')
} else {
return (size/(1024 * 1024 * 1024)).toFixed(2) + 'GB/s'
return (size/(1024 * 1024 * 1024)).toFixed(2) + (space ? ' GB / s' : 'GB/s')
}
}