优化全局上传器
This commit is contained in:
parent
8816b444ed
commit
d099d94a43
@ -34,6 +34,7 @@
|
|||||||
"vue-router": "3.0.6",
|
"vue-router": "3.0.6",
|
||||||
"vue-simple-uploader": "^0.7.4",
|
"vue-simple-uploader": "^0.7.4",
|
||||||
"vue-touch": "^2.0.0-beta.4",
|
"vue-touch": "^2.0.0-beta.4",
|
||||||
|
"vue-wechat-title": "^2.0.5",
|
||||||
"vuex": "3.1.0",
|
"vuex": "3.1.0",
|
||||||
"we-vue": "^2.3.3",
|
"we-vue": "^2.3.3",
|
||||||
"webuploader": "^0.1.8",
|
"webuploader": "^0.1.8",
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="global-uploader">
|
<div id="global-uploader" v-wechat-title="process === -10 || process===100 ? $route.meta.title : process+'%'+' | '+$route.meta.title" >
|
||||||
|
|
||||||
<!-- 上传 -->
|
<!-- 上传 -->
|
||||||
<uploader
|
<uploader
|
||||||
@ -47,11 +47,16 @@
|
|||||||
|
|
||||||
</uploader>
|
</uploader>
|
||||||
|
|
||||||
<div v-if="isShrink" class="process-area" id="drag-ball" @click="expand">
|
<div class="process-area" id="drag-ball" @click="expand" :style="processAreaClass">
|
||||||
<div class="process-anime">
|
<div class="process-anime">
|
||||||
<div class="cube-a" :style="{'top': -process-65+'%'}"></div>
|
<div class="cube-a" :style="{'top': -process-65+'%'}"></div>
|
||||||
<div class="cube-b" :style="{'top': -process-65+'%'}"></div>
|
<div class="cube-b" :style="{'top': -process-65+'%'}"></div>
|
||||||
|
|
||||||
|
<div v-if="process < 100" class="process-info">
|
||||||
|
<div class="process">{{process}}%</div>
|
||||||
|
<div v-if="isUploading" class="net-speed">{{netSpeed}}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="process >= 100" class="done">
|
<div v-if="process >= 100" class="done">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" class="done-icon checkmark">
|
<svg xmlns="http://www.w3.org/2000/svg" class="done-icon checkmark">
|
||||||
<!--"M 14.1 27.2 l 7.1 7.2 l 16.7 -16.8"-->
|
<!--"M 14.1 27.2 l 7.1 7.2 l 16.7 -16.8"-->
|
||||||
@ -77,6 +82,7 @@ import Bus from '@/assets/js/bus'
|
|||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
import SparkMD5 from 'spark-md5'
|
import SparkMD5 from 'spark-md5'
|
||||||
import api from '@/api/upload-api'
|
import api from '@/api/upload-api'
|
||||||
|
import { formatNetSpeed } from '@/utils/number'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {},
|
components: {},
|
||||||
@ -86,6 +92,8 @@ export default {
|
|||||||
options: {
|
options: {
|
||||||
target: api.simpleUploadURL,
|
target: api.simpleUploadURL,
|
||||||
chunkSize: 1024 * 1024,
|
chunkSize: 1024 * 1024,
|
||||||
|
// speedSmoothingFactor: 0.1,
|
||||||
|
// progressCallbacksInterval: 500,
|
||||||
maxChunkRetries: 1, // 最大重试次数
|
maxChunkRetries: 1, // 最大重试次数
|
||||||
simultaneousUploads: 1, // 并发上传数
|
simultaneousUploads: 1, // 并发上传数
|
||||||
testChunks: true, // 是否开启服务器分片校验
|
testChunks: true, // 是否开启服务器分片校验
|
||||||
@ -126,9 +134,13 @@ export default {
|
|||||||
},
|
},
|
||||||
panelShow: false, // 选择文件后,展示上传panel
|
panelShow: false, // 选择文件后,展示上传panel
|
||||||
collapse: false,
|
collapse: false,
|
||||||
isShrink: false,
|
isShrink: true,
|
||||||
process: 50,
|
process: -10,
|
||||||
filePanel: {}
|
pageTitle: this.$route.meta.title,
|
||||||
|
netSpeed: 0,
|
||||||
|
isUploading: false,
|
||||||
|
filePanel: {},
|
||||||
|
processAreaClass: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -155,6 +167,7 @@ export default {
|
|||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
window.uploader = this.$refs.uploader.uploader
|
window.uploader = this.$refs.uploader.uploader
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
destroyed() {
|
destroyed() {
|
||||||
Bus.$off('openUploader')
|
Bus.$off('openUploader')
|
||||||
@ -216,6 +229,20 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
onFileProgress(rootFile, file, chunk) {
|
onFileProgress(rootFile, file, chunk) {
|
||||||
|
// const fileList = window.uploader.fileList
|
||||||
|
// fileList.forEach(file => {
|
||||||
|
// file.currentSpeed
|
||||||
|
// })
|
||||||
|
this.netSpeed = formatNetSpeed(file.currentSpeed)
|
||||||
|
this.process = Math.trunc(window.uploader.progress() * 100)
|
||||||
|
if(this.process > 0 && this.process < 100){
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
return "还有文件正在上传, 确定退出吗?";
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
window.onbeforeunload = null
|
||||||
|
}
|
||||||
|
this.isUploading = window.uploader.isUploading()
|
||||||
console.log(`上传中 ${file.name},chunk:${chunk.startByte / 1024 / 1024} ~ ${chunk.endByte / 1024 / 1024}`)
|
console.log(`上传中 ${file.name},chunk:${chunk.startByte / 1024 / 1024} ~ ${chunk.endByte / 1024 / 1024}`)
|
||||||
},
|
},
|
||||||
onFileSuccess(rootFile, file, response) {
|
onFileSuccess(rootFile, file, response) {
|
||||||
@ -348,17 +375,39 @@ export default {
|
|||||||
},
|
},
|
||||||
// 展开球
|
// 展开球
|
||||||
expand() {
|
expand() {
|
||||||
this.isShrink = false
|
|
||||||
this.filePanel = {
|
this.filePanel = {
|
||||||
'width': '720px',
|
'width': '720px',
|
||||||
'height': '300px',
|
'height': '300px',
|
||||||
}
|
}
|
||||||
|
this.processAreaClass = {
|
||||||
|
'right': '66px',
|
||||||
|
'bottom': '66px',
|
||||||
|
'width': '0',
|
||||||
|
'height': '0',
|
||||||
|
}
|
||||||
|
this.isShrink = false
|
||||||
},
|
},
|
||||||
// 收缩成球
|
// 收缩成球
|
||||||
shrink(){
|
shrink(){
|
||||||
const that = this
|
const that = this
|
||||||
|
this.filePanel = {
|
||||||
|
'color': 'white',
|
||||||
|
'z-index': '-1',
|
||||||
|
'right': '20px',
|
||||||
|
'bottom': '20px',
|
||||||
|
'width': '92px',
|
||||||
|
'height': '92px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
'border-radius': '50%',
|
||||||
|
}
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
that.isShrink = true
|
that.isShrink = true
|
||||||
|
that.processAreaClass = {
|
||||||
|
'right': '20px',
|
||||||
|
'bottom': '20px',
|
||||||
|
'width': '92px',
|
||||||
|
'height': '92px',
|
||||||
|
}
|
||||||
that.filePanel = {
|
that.filePanel = {
|
||||||
'color': 'white',
|
'color': 'white',
|
||||||
'z-index': '-1',
|
'z-index': '-1',
|
||||||
@ -370,20 +419,21 @@ export default {
|
|||||||
'border-radius': '50%',
|
'border-radius': '50%',
|
||||||
}
|
}
|
||||||
},500)
|
},500)
|
||||||
this.filePanel = {
|
|
||||||
'color': 'white',
|
|
||||||
'z-index': '-1',
|
|
||||||
'right': '20px',
|
|
||||||
'bottom': '20px',
|
|
||||||
'width': '92px',
|
|
||||||
'height': '92px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
'border-radius': '50%',
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
close() {
|
close() {
|
||||||
this.uploader.cancel()
|
if(this.process === -10 || this.process === 100){
|
||||||
this.panelShow = false
|
this.uploader.cancel()
|
||||||
|
this.panelShow = false
|
||||||
|
} else {
|
||||||
|
this.$confirm('还有文件正在上传, 确定要关闭吗?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
this.uploader.cancel()
|
||||||
|
this.panelShow = false
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -472,8 +522,8 @@ export default {
|
|||||||
background-size: 100% 100%;
|
background-size: 100% 100%;
|
||||||
border-radius: 7px 7px 0 0;
|
border-radius: 7px 7px 0 0;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
-webkit-transition: all .5s cubic-bezier(0.4, 0, 1, 1) 0s;
|
-webkit-transition: all .5s ease-in-out 0s;
|
||||||
transition: all .5s cubic-bezier(0.4, 0, 1, 1) 0s;
|
transition: all .5s ease-in-out 0s;
|
||||||
|
|
||||||
ul{
|
ul{
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@ -599,11 +649,12 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
.process-area {
|
.process-area {
|
||||||
z-index: -1;
|
right: 66px;
|
||||||
/*right: 20px;*/
|
bottom: 66px;
|
||||||
/*bottom: 20px;*/
|
width: 0;
|
||||||
/*width: 92px;*/
|
height: 0;
|
||||||
/*height: 92px;*/
|
-webkit-box-shadow: 5px 5px 10px rgba(0,0,0,0.2);
|
||||||
|
box-shadow: 5px 5px 10px rgba(0,0,0,0.2);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: #eee;
|
background: #eee;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
@ -611,9 +662,27 @@ export default {
|
|||||||
background-size: 100% 100%;
|
background-size: 100% 100%;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
animation: load-process-area .5s 1 linear forwards;
|
/*animation: load-process-area .5s 1 linear forwards;*/
|
||||||
transition: .5s;
|
/*transition: all .5s;*/
|
||||||
|
-webkit-transition: all .5s ease-in-out 0s;
|
||||||
|
transition: all .5s ease-in-out 0s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.process-area .process-info {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%,-50%);
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.process-area .process-info .process {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
.process-area .process-info .net-speed {
|
||||||
|
font-size: .7rem;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.process-anime {
|
.process-anime {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import EVueContextmenu from 'e-vue-contextmenu'
|
|||||||
import App from './App'
|
import App from './App'
|
||||||
import store from './store'
|
import store from './store'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
|
import VueWechatTitle from 'vue-wechat-title'
|
||||||
// import WeVue from 'we-vue'
|
// import WeVue from 'we-vue'
|
||||||
// import 'we-vue/lib/style.css'
|
// import 'we-vue/lib/style.css'
|
||||||
import { Button, Cell, CellGroup, Image, List, PullRefresh, SwipeCell, Col, Row, Divider, Sticky, NavBar, Icon, Tabbar, TabbarItem, ActionSheet} from 'vant';
|
import { Button, Cell, CellGroup, Image, List, PullRefresh, SwipeCell, Col, Row, Divider, Sticky, NavBar, Icon, Tabbar, TabbarItem, ActionSheet} from 'vant';
|
||||||
@ -42,6 +43,8 @@ Vue.use(VueTouch, {name:'v-touch'})
|
|||||||
Vue.use(ElementUI)
|
Vue.use(ElementUI)
|
||||||
// Vue.use(WeVue)
|
// Vue.use(WeVue)
|
||||||
|
|
||||||
|
Vue.use(VueWechatTitle)
|
||||||
|
|
||||||
// 有赞的移动UI
|
// 有赞的移动UI
|
||||||
Vue.use(Button);
|
Vue.use(Button);
|
||||||
Vue.use(Cell);
|
Vue.use(Cell);
|
||||||
|
|||||||
@ -99,7 +99,7 @@ export function formatTime(agoTime) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* formatSize
|
* formatSize
|
||||||
* @param {*} size
|
* @param {*} size
|
||||||
*/
|
*/
|
||||||
export function formatSize(size) {
|
export function formatSize(size) {
|
||||||
if (size === 0) {
|
if (size === 0) {
|
||||||
@ -114,3 +114,21 @@ export function formatSize(size) {
|
|||||||
return (size/(1024 * 1024 * 1024)).toFixed(2) + 'G'
|
return (size/(1024 * 1024 * 1024)).toFixed(2) + 'G'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* formatNetSpeed
|
||||||
|
* @param {*} size
|
||||||
|
*/
|
||||||
|
export function formatNetSpeed(size) {
|
||||||
|
if (size === 0) {
|
||||||
|
return '0 B/s'
|
||||||
|
} else if (size < 1024) {
|
||||||
|
return size + ' B/s'
|
||||||
|
} else if (size < 1024 * 1024) {
|
||||||
|
return (size/1024).toFixed(2) + ' KB/s'
|
||||||
|
} else if (size < 1024 * 1024 * 1024) {
|
||||||
|
return (size/(1024 * 1024)).toFixed(2) + ' MB/s'
|
||||||
|
} else {
|
||||||
|
return (size/(1024 * 1024 * 1024)).toFixed(2) + ' GB/s'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user