Skip to content

Commit

Permalink
Merge pull request #188 from jamebal/dev
Browse files Browse the repository at this point in the history
perf: 优化上传文件夹时显示的速度
  • Loading branch information
jamebal authored Jun 16, 2024
2 parents 0bafad2 + d917e84 commit c108564
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
22 changes: 15 additions & 7 deletions src/components/SimpleUploader/globalUploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default {
// speedSmoothingFactor: 0.1,
// progressCallbacksInterval: 500,
maxChunkRetries: 3, // 最大重试次数
simultaneousUploads: 2, // 并发上传数
simultaneousUploads: 3, // 并发上传数
testChunks: true, // 是否开启服务器分片校验
// 服务器分片校验函数,秒传及断点续传基础
checkChunkUploadedByResponse: function (chunk, message) {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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'
Expand All @@ -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',
Expand Down
13 changes: 7 additions & 6 deletions src/utils/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}

0 comments on commit c108564

Please sign in to comment.