Skip to content

Commit 73eb086

Browse files
committed
断点续传限制上传大小
1 parent f1b3a37 commit 73eb086

File tree

1 file changed

+113
-8
lines changed

1 file changed

+113
-8
lines changed

QMPlusVuePage/src/view/example/breakpoint/breakpoint.vue

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
<template>
22
<div class="hello">
3-
<form id="fromCont" method="post">
4-
<input @change="choseFile" id="file" multiple="multiple" type="file" />
3+
<el-divider content-position="left">大文件上传</el-divider>
4+
<form id="fromCont" method="post" >
5+
<div class="fileUpload">
6+
选择文件<input @change="choseFile" id="file" multiple="multiple" type="file" />
7+
</div>
58
</form>
6-
<el-button @click="getFile">上传</el-button>
7-
<span
9+
<el-button @click="getFile" :disabled="limitFileSize" type="primary" size="medium" class="uploadBtn">上传文件</el-button>
10+
<div>请上传不超过5MB的文件</div>
11+
<div class="list">
12+
<transition-group name="list" tag="p">
13+
<div class="list-item" v-for="(item,i) in uploadList" v-bind:key="i" >
14+
<i class="el-icon-document"></i>
15+
<span>{{ item.name }}</span>
16+
<span v-if="file" class="percentage" >{{percentage}}%</span>
17+
<el-progress :show-text='false' :text-inside="false" :stroke-width="2" :percentage="percentage"></el-progress>
18+
</div>
19+
</transition-group>
20+
</div>
21+
22+
<!-- <span
823
v-if="this.file"
9-
>{{Math.floor(((this.formDataList.length-this.waitNum)/this.formDataList.length)*100)}}%</span>
10-
<h2>此版本为先行体验功能测试版,样式美化和性能优化正在进行中,上传切片文件和合成的完整文件分别再QMPlusserver目录的breakpointDir文件夹和fileDir文件夹</h2>
24+
>{{Math.floor(((this.formDataList.length-this.waitNum)/this.formDataList.length)*100)}}%</span> -->
25+
<h2 class="tips">此版本为先行体验功能测试版,样式美化和性能优化正在进行中,上传切片文件和合成的完整文件分别再QMPlusserver目录的breakpointDir文件夹和fileDir文件夹</h2>
1126
</div>
1227
</template>
1328
<script>
@@ -27,15 +42,25 @@ export default {
2742
fileMd5: '',
2843
formDataList: [],
2944
waitUpLoad: [],
30-
waitNum: 0
45+
waitNum: 0,
46+
limitFileSize: false,
47+
percentage:0,
48+
percentageFlage: true,
49+
customColor: '#409eff',
50+
uploadList:[]
3151
}
52+
},
53+
created(){
54+
3255
},
3356
methods: {
3457
// 选中文件的函数
3558
async choseFile(e) {
3659
const fileR = new FileReader() // 创建一个reader用来读取文件流
3760
const file = e.target.files[0] // 获取当前文件
61+
const maxSize = 5*1024*1024
3862
this.file = file // file 丢全局方便后面用 可以改进为func传参形式
63+
if(file.size<maxSize){
3964
fileR.readAsArrayBuffer(file) // 把文件读成ArrayBuffer 主要为了保持跟后端的流一致
4065
fileR.onload = async e => {
4166
// 读成arrayBuffer的回调 e 为方法自带参数 相当于 dom的e 流存在e.target.result 中
@@ -83,14 +108,27 @@ export default {
83108
}
84109
this.waitNum = this.waitUpLoad.length // 记录长度用于百分比展示
85110
}
111+
} else {
112+
this.limitFileSize = true
113+
this.$message('请上传小于5M文件')
114+
}
86115
},
87116
getFile() {
88117
// 确定按钮
89118
if (this.file == null) {
90119
this.$message('请先上传文件')
91120
return
92121
}
122+
this.percentage = Math.floor(((this.formDataList.length-this.waitNum)/this.formDataList.length)*100)
123+
if(this.percentage == 100){
124+
this.percentageFlage = false
125+
}
93126
this.sliceFile() // 上传切片
127+
if(this.percentage == 100){
128+
this.uploadList.push(this.file)
129+
console.log(this.uploadList)
130+
}
131+
94132
},
95133
sliceFile() {
96134
this.waitUpLoad &&
@@ -134,7 +172,7 @@ export default {
134172
}
135173
</script>
136174

137-
<style scoped>
175+
<style lang='scss' scoped>
138176
h3 {
139177
margin: 40px 0 0;
140178
}
@@ -149,4 +187,71 @@ li {
149187
a {
150188
color: #42b983;
151189
}
190+
#fromCont{
191+
display: inline-block;
192+
}
193+
.fileUpload{
194+
padding: 4px 10px;
195+
height: 20px;
196+
line-height: 20px;
197+
position: relative;
198+
cursor: pointer;
199+
color: #000;
200+
border: 1px solid #c1c1c1;
201+
border-radius: 4px;
202+
overflow: hidden;
203+
display: inline-block;
204+
input{
205+
position: absolute;
206+
font-size: 100px;
207+
right: 0;
208+
top: 0;
209+
opacity: 0;
210+
cursor: pointer;
211+
}
212+
213+
}
214+
.fileName{
215+
display: inline-block;
216+
vertical-align: top;
217+
margin: 6px 15px 0 15px;
218+
}
219+
.uploadBtn{
220+
position: relative;
221+
top: -10px;
222+
margin-left: 15px;
223+
}
224+
.tips{
225+
margin-top: 30px;
226+
font-size: 14px;
227+
font-weight: 400;
228+
color: #606266;
229+
}
230+
.el-divider{
231+
margin: 0 0 30px 0;
232+
}
233+
234+
.list{
235+
margin-top:15px;
236+
}
237+
.list-item {
238+
display: block;
239+
margin-right: 10px;
240+
color: #606266;
241+
line-height: 25px;
242+
margin-bottom: 5px;
243+
width: 40%;
244+
.percentage{
245+
float: right;
246+
}
247+
}
248+
.list-enter-active, .list-leave-active {
249+
transition: all 1s;
250+
}
251+
.list-enter, .list-leave-to
252+
/* .list-leave-active for below version 2.1.8 */ {
253+
opacity: 0;
254+
transform: translateY(-30px);
255+
}
256+
152257
</style>

0 commit comments

Comments
 (0)