|
|
@@ -1,15 +1,16 @@
|
|
|
<template>
|
|
|
<div class="upload-file">
|
|
|
- <el-upload
|
|
|
+ <el-upload
|
|
|
multiple
|
|
|
- drag
|
|
|
- :action="uploadFileUrl"
|
|
|
- :before-upload="handleBeforeUpload"
|
|
|
+ drag
|
|
|
+ :action="uploadFileUrl"
|
|
|
+ :before-upload="handleBeforeUpload"
|
|
|
:on-error="uploadedSuccessfully"
|
|
|
:on-success="handleUploadSuccess"
|
|
|
- :file-list="fileList" :limit="limit"
|
|
|
- :accept="accept"
|
|
|
- :http-request="uploadFile"
|
|
|
+ :file-list="fileList"
|
|
|
+
|
|
|
+ :accept="accept"
|
|
|
+ :http-request="uploadFile"
|
|
|
:show-file-list="true"
|
|
|
:on-remove="handleDelete"
|
|
|
:headers="headers" class="upload-file-uploader" ref="fileUpload">
|
|
|
@@ -150,7 +151,7 @@ export default {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// 校检文件大小
|
|
|
if (this.fileSize) {
|
|
|
@@ -201,10 +202,10 @@ export default {
|
|
|
}
|
|
|
//this.fileValueList.splice(item, 1);
|
|
|
console.log("handleDelete deleted",this.fileValueList)
|
|
|
-
|
|
|
+
|
|
|
this.$emit("input", this.listToTagObj(this.fileValueList));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
// 上传失败结束处理 必须调用,否则失败文件也会显示
|
|
|
uploadedSuccessfully(err,file,fileList) {
|
|
|
@@ -228,20 +229,24 @@ export default {
|
|
|
uploadFile(fileObj) {
|
|
|
let formData = new FormData();
|
|
|
formData.append('file', fileObj.file);
|
|
|
- upload(formData, 'image').then(res => {
|
|
|
- /*上传成功*/
|
|
|
- this.$modal.closeLoading();
|
|
|
- //let imgUrl = process.env.VUE_APP_BASE_API + res.data.url;
|
|
|
- let arr = [];
|
|
|
- arr.push({ name: res.data.realName, url: res.data.url });
|
|
|
- this.fileValueList = this.fileValueList.concat(arr);
|
|
|
- // console.log("uploadFile", this.fileList)
|
|
|
- fileObj.onSuccess();
|
|
|
- }).catch(err => {
|
|
|
- /*上传失败*/
|
|
|
- this.$modal.closeLoading();
|
|
|
- fileObj.onError()
|
|
|
- })
|
|
|
+ console.log("this.fileValueList.length",this.fileValueList.length)
|
|
|
+ if (this.fileValueList.length<=this.limit){
|
|
|
+ upload(formData, 'image').then(res => {
|
|
|
+ /*上传成功*/
|
|
|
+ this.$modal.closeLoading();
|
|
|
+ //let imgUrl = process.env.VUE_APP_BASE_API + res.data.url;
|
|
|
+ let arr = [];
|
|
|
+ arr.push({ name: res.data.realName, url: res.data.url });
|
|
|
+ this.fileValueList = this.fileValueList.concat(arr);
|
|
|
+ // console.log("uploadFile", this.fileList)
|
|
|
+ fileObj.onSuccess();
|
|
|
+ }).catch(err => {
|
|
|
+ /*上传失败*/
|
|
|
+ this.$modal.closeLoading();
|
|
|
+ fileObj.onError()
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
// 对象转成指定字符串分隔
|
|
|
listToString(list, separator) {
|
|
|
@@ -254,14 +259,14 @@ export default {
|
|
|
return strs != '' ? strs.substring(0, strs.length - 1) : '';
|
|
|
},
|
|
|
|
|
|
- listToTagObj(list) {
|
|
|
+ listToTagObj(list) {
|
|
|
let tempArry=[];
|
|
|
- for (let i in list) {
|
|
|
+ for (let i in list) {
|
|
|
// console.log("listToString2 i",i);
|
|
|
tempArry.push(JSON.stringify( {url:list[i].url,name:list[i].name}));
|
|
|
}
|
|
|
console.log("listToString2",tempArry);
|
|
|
- return tempArry;
|
|
|
+ return tempArry;
|
|
|
}
|
|
|
}
|
|
|
};
|