1
1
<template >
2
2
<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 >
5
8
</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
8
23
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 >
11
26
</div >
12
27
</template >
13
28
<script >
@@ -27,15 +42,25 @@ export default {
27
42
fileMd5: ' ' ,
28
43
formDataList: [],
29
44
waitUpLoad: [],
30
- waitNum: 0
45
+ waitNum: 0 ,
46
+ limitFileSize: false ,
47
+ percentage: 0 ,
48
+ percentageFlage: true ,
49
+ customColor: ' #409eff' ,
50
+ uploadList: []
31
51
}
52
+ },
53
+ created (){
54
+
32
55
},
33
56
methods: {
34
57
// 选中文件的函数
35
58
async choseFile (e ) {
36
59
const fileR = new FileReader () // 创建一个reader用来读取文件流
37
60
const file = e .target .files [0 ] // 获取当前文件
61
+ const maxSize = 5 * 1024 * 1024
38
62
this .file = file // file 丢全局方便后面用 可以改进为func传参形式
63
+ if (file .size < maxSize){
39
64
fileR .readAsArrayBuffer (file) // 把文件读成ArrayBuffer 主要为了保持跟后端的流一致
40
65
fileR .onload = async e => {
41
66
// 读成arrayBuffer的回调 e 为方法自带参数 相当于 dom的e 流存在e.target.result 中
@@ -83,14 +108,27 @@ export default {
83
108
}
84
109
this .waitNum = this .waitUpLoad .length // 记录长度用于百分比展示
85
110
}
111
+ } else {
112
+ this .limitFileSize = true
113
+ this .$message (' 请上传小于5M文件' )
114
+ }
86
115
},
87
116
getFile () {
88
117
// 确定按钮
89
118
if (this .file == null ) {
90
119
this .$message (' 请先上传文件' )
91
120
return
92
121
}
122
+ this .percentage = Math .floor (((this .formDataList .length - this .waitNum )/ this .formDataList .length )* 100 )
123
+ if (this .percentage == 100 ){
124
+ this .percentageFlage = false
125
+ }
93
126
this .sliceFile () // 上传切片
127
+ if (this .percentage == 100 ){
128
+ this .uploadList .push (this .file )
129
+ console .log (this .uploadList )
130
+ }
131
+
94
132
},
95
133
sliceFile () {
96
134
this .waitUpLoad &&
@@ -134,7 +172,7 @@ export default {
134
172
}
135
173
</script >
136
174
137
- <style scoped>
175
+ <style lang='scss' scoped>
138
176
h3 {
139
177
margin : 40px 0 0 ;
140
178
}
@@ -149,4 +187,71 @@ li {
149
187
a {
150
188
color : #42b983 ;
151
189
}
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
+
152
257
</style >
0 commit comments