11<template >
22 <div class =" upload-container" >
33 <div >
4- <div class =" input-btns" style = " margin-bottom : 10 px ; " >
5- < input
6- ref =" input"
7- type =" file"
8- style =" display :none ;"
9- @change =" handleChange"
10- :multiple =" multiple"
11- />
12- < div v-if = " img " class =" upload-img" >
4+ <div class =" input-btns"
5+ style = " margin-bottom : 10 px ; " >
6+ < input ref =" input"
7+ type =" file"
8+ style =" display :none ;"
9+ @change =" handleChange"
10+ :multiple =" multiple" />
11+ < div v-if = " img "
12+ class =" upload-img" >
1313 <!-- v-for="(file,index) in fileInfo.length>0?fileInfo: files" -->
14- <div v-for =" (file,index) in files.length>0?files:fileInfo" :key =" index" class =" img-item" >
14+ <div v-for =" (file,index) in files.length>0?files:fileInfo"
15+ :key =" index"
16+ class =" img-item" >
1517 <div class =" operation" >
1618 <div class =" action" >
17- <Icon type =" md-eye" @click =" previewImg(index)" class =" view" ></Icon >
18- <Icon type =" md-close" @click =" removeFile(index)" class =" remove" ></Icon >
19+ <Icon type =" md-eye"
20+ @click =" previewImg(index)"
21+ class =" view" ></Icon >
22+ <Icon type =" md-close"
23+ @click =" removeFile(index)"
24+ class =" remove" ></Icon >
1925 </div >
2026 <div class =" mask" ></div >
2127 </div >
22- <img :src =" getImgSrc(file)" :onerror =" errorImg" />
28+ <img :src =" getImgSrc(file)"
29+ :onerror =" errorImg" />
2330 </div >
24- <div
25- v-show =" !autoUpload||(autoUpload&&files.length<maxFile&&fileInfo.length<maxFile)"
26- class =" img-selector"
27- :class =" getSelector()"
28- >
29- <div class =" selector" @click =" handleClick" >
31+ <div v-show =" !autoUpload||(autoUpload&&files.length<maxFile&&fileInfo.length<maxFile)"
32+ class =" img-selector"
33+ :class =" getSelector()" >
34+ <div class =" selector"
35+ @click =" handleClick" >
3036 <Icon type =" ios-camera" ></Icon >
3137 </div >
32- <div v-if =" !autoUpload" class =" s-btn" :class =" {readonly:changed}" @click =" upload" >
38+ <div v-if =" !autoUpload"
39+ class =" s-btn"
40+ :class =" {readonly:changed}"
41+ @click =" upload" >
3342 <div >{{loadText}}</div >
3443 </div >
3544 </div >
3645 </div >
37- <Button v-else @click =" handleClick" icon =" ios-cloud-upload-outline" >选择{{img?'图片':'文件'}}</Button >
46+ <Button v-else
47+ @click =" handleClick"
48+ icon =" ios-cloud-upload-outline" >选择{{img?'图片':'文件'}}</Button >
3849
39- <Button
40- v-if =" !autoUpload&& !img"
41- type =" info"
42- :disabled =" changed"
43- icon =" md-arrow-round-up"
44- @click =" upload"
45- :loading =" loadingStatus"
46- >上传文件</Button >
50+ <Button v-if =" !autoUpload&& !img"
51+ type =" info"
52+ :disabled =" changed"
53+ icon =" md-arrow-round-up"
54+ @click =" upload"
55+ :loading =" loadingStatus" >上传文件</Button >
4756 </div >
4857 <slot ></slot >
4958 <div v-if =" desc" >
5059 <Alert show-icon >{{getText()}}文件大小不超过{{maxSize||3}}M</Alert >
5160 </div >
5261 <slot name =" content" ></slot >
5362 <div v-if =" !img" >
54- <ul class =" upload-list" v-show =" fileList" >
55- <li class =" list-file" v-for =" (file,index) in files.length>0?files:fileInfo" :key =" index" >
63+ <ul class =" upload-list"
64+ v-show =" fileList" >
65+ <li class =" list-file"
66+ v-for =" (file,index) in files.length>0?files:fileInfo"
67+ :key =" index" >
5668 <a >
5769 <span @click =" fileOnClick(index,file)" >
5870 <Icon :type =" format(file)" ></Icon >
6375 style="margin-left:15px;"
6476 >大小{{(file.size / 1024).toFixed(2)}}KB</span>-->
6577 </a >
66- <span @click =" removeFile(index)" class =" file-remove" >
78+ <span @click =" removeFile(index)"
79+ class =" file-remove" >
6780 <Icon type =" md-close" ></Icon >
6881 </span >
6982 </li >
@@ -191,25 +204,25 @@ export default {
191204 default: false
192205 }
193206 },
194- data () {
207+ data () {
195208 return {
196209 errorImg: ' this.src="' + require (" @/assets/imgs/error-img.png" ) + ' "' ,
197210 changed: false , // 手动上传成功后禁止重复上传,必须重新选择
198211 model: true ,
199212 files: [],
200213 bigImg: " " ,
201214 loadingStatus: false ,
202- loadText: ' 上传文件'
215+ loadText: ' 上传文件'
203216 };
204217 },
205- created () {
218+ created () {
206219 // 默认有图片的禁止上传操作
207220 if (this .fileInfo ) {
208221 this .changed = true ;
209222 }
210223 },
211224 methods: {
212- previewImg (index ) {
225+ previewImg (index ) {
213226 // 查看大图预览模式待完
214227 this .base .previewImg (
215228 this .getImgSrc (
@@ -218,25 +231,30 @@ export default {
218231 );
219232 // window.open(this.getImgSrc((this.files.length>0?this.files:this.fileInfo)[index]));
220233 },
221- getSelector () {
234+ getSelector () {
222235 if (this .autoUpload ) {
223236 return " auto-selector" ;
224237 }
225238 return " submit-selector" ;
226239 },
227- getImgSrc (file ) {
240+ getImgSrc (file ) {
228241 if (file .hasOwnProperty (" path" )) {
242+
229243 if (this .base .isUrl (file .path )) {
230244 return file .path ;
231245 }
246+ // 2020.12.27增加base64图片操作
247+ if (file .path .indexOf (" /9j/" ) != - 1 ) {
248+ return " data:image/jpeg;base64," + file .path ;
249+ }
232250 if (file .path .substr (0 , 1 ) == " /" ) {
233251 file .path = file .path .substr (1 );
234252 }
235253 return this .http .ipAddress + file .path ;
236254 }
237255 return window .URL .createObjectURL (file);
238256 },
239- fileOnClick (index , file ) {
257+ fileOnClick (index , file ) {
240258 if (! this .fileClick (index, file, this .files )) {
241259 return ;
242260 }
@@ -257,17 +275,17 @@ export default {
257275 this .http .ipAddress
258276 );
259277 },
260- getText () {
278+ getText () {
261279 if (this .img ) {
262280 return " 只能上传图片," ;
263281 } else if (this .excel ) {
264282 return " 只能上传excel文件," ;
265283 }
266284 },
267- handleClick () {
285+ handleClick () {
268286 this .$refs .input .click ();
269287 },
270- handleChange (e ) {
288+ handleChange (e ) {
271289 this .clearFiles ();
272290 var result = this .checkFile (e .target .files );
273291 if (! result) {
@@ -285,7 +303,7 @@ export default {
285303 this .upload ();
286304 }
287305 },
288- removeFile (index ) {
306+ removeFile (index ) {
289307 // 如果传入了FileInfo需要自行处理移除FileInfo
290308 // t移除文件
291309 let removeFile =
@@ -299,13 +317,13 @@ export default {
299317 return ;
300318 }
301319 },
302- clearFiles () {
320+ clearFiles () {
303321 this .files .splice (0 );
304322 },
305- getFiles () {
323+ getFiles () {
306324 return this .files ;
307325 },
308- upload () {
326+ upload () {
309327 if (! this .checkFile ()) return false ;
310328 if (! this .url ) {
311329 return this .$Message .error ({ duration: 5 , content: " 没有配置好Url" });
@@ -317,19 +335,19 @@ export default {
317335 return ;
318336 }
319337 var forms = new FormData ();
320- this .files .forEach (function (file ) {
338+ this .files .forEach (function (file ) {
321339 forms .append (" fileInput" , file, file .name );
322340 });
323341 // forms.append("fileInput", this.files);
324342 this .loadingStatus = true ;
325- this .loadText = " 上传中.." ;
343+ this .loadText = " 上传中.." ;
326344 this .http
327345 .post (this .url , forms, this .autoUpload ? " 正在上传文件" : " " )
328346 .then (
329347 x => {
330348 // this.$refs.uploadFile.clearFiles();
331349 this .loadingStatus = false ;
332- this .loadText = " 上传文件" ;
350+ this .loadText = " 上传文件" ;
333351 if (! this .uploadAfter (x, this .files )) {
334352 this .changed = false ;
335353 return ;
@@ -353,12 +371,12 @@ export default {
353371 // }
354372 },
355373 error => {
356- this .loadText = " 上传文件" ;
374+ this .loadText = " 上传文件" ;
357375 this .loadingStatus = false ;
358376 }
359377 );
360378 },
361- format (file , checkFileType ) {
379+ format (file , checkFileType ) {
362380 const format =
363381 file .name
364382 .split (" ." )
@@ -431,8 +449,8 @@ export default {
431449
432450 return fileIcon;
433451 },
434- beforeUpload () {},
435- checkFile (files ) {
452+ beforeUpload () { },
453+ checkFile (files ) {
436454 if (! files) {
437455 files = this .files ;
438456 }
@@ -631,7 +649,7 @@ export default {
631649 }
632650 .submit-selector {
633651 .s-btn {
634- line-height : 22px ;
652+ line-height : 22px ;
635653 font-size : 12px ;
636654 top : -7px ;
637655 // padding: 2px;
0 commit comments