优化全局上传器
This commit is contained in:
parent
d099d94a43
commit
d98e7b55cf
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="global-uploader" v-wechat-title="process === -10 || process===100 ? $route.meta.title : process+'%'+' | '+$route.meta.title" >
|
<div id="global-uploader" v-wechat-title="process === -10 || process===100 || this.fileListLength === 0 ? $route.meta.title : process+'%'+' | '+$route.meta.title" >
|
||||||
|
|
||||||
<!-- 上传 -->
|
<!-- 上传 -->
|
||||||
<uploader
|
<uploader
|
||||||
@ -12,6 +12,7 @@
|
|||||||
@file-success="onFileSuccess"
|
@file-success="onFileSuccess"
|
||||||
@file-progress="onFileProgress"
|
@file-progress="onFileProgress"
|
||||||
@file-error="onFileError"
|
@file-error="onFileError"
|
||||||
|
@file-removed="onFileRemoved"
|
||||||
>
|
>
|
||||||
<uploader-unsupport></uploader-unsupport>
|
<uploader-unsupport></uploader-unsupport>
|
||||||
|
|
||||||
@ -24,7 +25,7 @@
|
|||||||
<div class="file-title">
|
<div class="file-title">
|
||||||
<h2 class="files-title">文件列表</h2>
|
<h2 class="files-title">文件列表</h2>
|
||||||
<div class="operate">
|
<div class="operate">
|
||||||
<el-button type="text" class="button-collapse" @click="shrink">
|
<el-button v-if="fileListLength > 0" type="text" class="button-collapse" @click="shrink">
|
||||||
<i class="iconfont el-icon-position"></i>
|
<i class="iconfont el-icon-position"></i>
|
||||||
</el-button>
|
</el-button>
|
||||||
<!--<el-button type="text" class="button-collapse" :title="collapse ? '展开':'折叠' " @click="fileListShow">-->
|
<!--<el-button type="text" class="button-collapse" :title="collapse ? '展开':'折叠' " @click="fileListShow">-->
|
||||||
@ -132,6 +133,7 @@ export default {
|
|||||||
paused: '暂停中',
|
paused: '暂停中',
|
||||||
waiting: '等待中'
|
waiting: '等待中'
|
||||||
},
|
},
|
||||||
|
fileListLength: 0,
|
||||||
panelShow: false, // 选择文件后,展示上传panel
|
panelShow: false, // 选择文件后,展示上传panel
|
||||||
collapse: false,
|
collapse: false,
|
||||||
isShrink: true,
|
isShrink: true,
|
||||||
@ -182,6 +184,7 @@ export default {
|
|||||||
// Bus.$emit('fileAdded')
|
// Bus.$emit('fileAdded')
|
||||||
// },
|
// },
|
||||||
onFilesAdded(files) {
|
onFilesAdded(files) {
|
||||||
|
this.fileListLength = this.uploader.fileList.length
|
||||||
const filePaths = this.uploader.filePaths
|
const filePaths = this.uploader.filePaths
|
||||||
const paths = Object.keys(filePaths)
|
const paths = Object.keys(filePaths)
|
||||||
const pathsLength = paths.length
|
const pathsLength = paths.length
|
||||||
@ -233,9 +236,10 @@ export default {
|
|||||||
// fileList.forEach(file => {
|
// fileList.forEach(file => {
|
||||||
// file.currentSpeed
|
// file.currentSpeed
|
||||||
// })
|
// })
|
||||||
|
console.log('window.uploader',window.uploader)
|
||||||
this.netSpeed = formatNetSpeed(file.currentSpeed)
|
this.netSpeed = formatNetSpeed(file.currentSpeed)
|
||||||
this.process = Math.trunc(window.uploader.progress() * 100)
|
this.process = Math.trunc(window.uploader.progress() * 100)
|
||||||
if(this.process > 0 && this.process < 100){
|
if(this.process > 0 && this.process < 100 && window.uploader.fileList.length > 0){
|
||||||
window.onbeforeunload = function() {
|
window.onbeforeunload = function() {
|
||||||
return "还有文件正在上传, 确定退出吗?";
|
return "还有文件正在上传, 确定退出吗?";
|
||||||
}
|
}
|
||||||
@ -297,6 +301,9 @@ export default {
|
|||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
onFileRemoved() {
|
||||||
|
this.fileListLength = this.uploader.fileList.length
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 计算md5,实现断点续传及秒传
|
* 计算md5,实现断点续传及秒传
|
||||||
* @param file
|
* @param file
|
||||||
@ -421,7 +428,7 @@ export default {
|
|||||||
},500)
|
},500)
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
if(this.process === -10 || this.process === 100){
|
if(this.process === -10 || this.process === 100 || this.fileListLength === 0){
|
||||||
this.uploader.cancel()
|
this.uploader.cancel()
|
||||||
this.panelShow = false
|
this.panelShow = false
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user