文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit a0a1bc40 by 李严凡

创建任务上传文件

parent 04bbbd2b
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
:on-remove="handleRemoveF" :on-remove="handleRemoveF"
:on-success="uploadSuccessF" :on-success="uploadSuccessF"
multiple multiple
:http-request="uploadFile" :http-request="uploadFileF"
:limit="7" :limit="7"
:data="'3:'+(index)" :data="'3:'+(index)"
:on-exceed="handleExceed" :on-exceed="handleExceed"
...@@ -85,11 +85,11 @@ ...@@ -85,11 +85,11 @@
class="upload-demo" class="upload-demo"
action="https://jsonplaceholder.typicode.com/posts/" action="https://jsonplaceholder.typicode.com/posts/"
:on-preview="handlePreview" :on-preview="handlePreview"
:on-remove="removeSuccess" :on-remove="handleRemoveP"
:before-remove="beforeRemove" :before-remove="beforeRemove"
:on-success="uploadSuccessP" :on-success="uploadSuccessP"
:data="'3:'+(index)" :data="'3:'+(index)"
:http-request="uploadFile" :http-request="uploadFileP"
multiple multiple
:limit="7" :limit="7"
:on-exceed="handleExceed" :on-exceed="handleExceed"
...@@ -135,9 +135,9 @@ ...@@ -135,9 +135,9 @@
class="upload-demo" class="upload-demo"
action="https://jsonplaceholder.typicode.com/posts/" action="https://jsonplaceholder.typicode.com/posts/"
:on-preview="handlePreview" :on-preview="handlePreview"
:on-remove="handleRemove" :on-remove="handleRemoveL"
:on-success="uploadSuccessL" :on-success="uploadSuccessL"
:http-request="uploadFile" :http-request="uploadFileL"
multiple multiple
:data="'3:'+(index)" :data="'3:'+(index)"
:limit="7" :limit="7"
...@@ -356,9 +356,16 @@ ...@@ -356,9 +356,16 @@
} }
}, },
methods: { methods: {
uploadFile(fileObj){ setIndex(index){
// alert(index);
this.Index = index;
},
//上传文件
uploadFileF(fileObj){
let formData = new window.FormData(); let formData = new window.FormData();
formData.set("file",fileObj.file); formData.set("file",fileObj.file);
var file = formData.getAll("file");
// console.log(file[0].name);
this.axios.post("/files/upload",formData,{ this.axios.post("/files/upload",formData,{
headers:{ headers:{
"Content-type":"multipart/form-data" "Content-type":"multipart/form-data"
...@@ -367,44 +374,137 @@ ...@@ -367,44 +374,137 @@
if(res.code == 0) if(res.code == 0)
alert("文件上传失败,请重新上传"); alert("文件上传失败,请重新上传");
else{ else{
console(res.data); this.url = res.data;
this.dynamicValidateForm.domains[this.Index ].fileName.push({name:file[0].name,url:this.url});
} }
}) })
}, },
setIndex(index){ uploadFileP(fileObj){
this.Index = index; let formData = new window.FormData();
}, formData.set("file",fileObj.file);
//上传文件 var file = formData.getAll("file");
uploadSuccessF(response,file,fileList){ this.axios.post("/files/upload",formData,{
this.fName=file.name; headers:{
this.url=file.url; "Content-type":"multipart/form-data"
this.dynamicValidateForm.domains[this.Index ].fileName.push({name:this.fName,url:this.url}); }
//console.log(this.fName); }).then(res=>{
//console.log(this.taskName); if(res.code == 0)
// console.log(this.dynamicValidateForm.domains[this.Index].fileName); alert("文件上传失败,请重新上传");
}, else{
uploadSuccessP(response,file,fileList){ this.url = res.data;
this.fName=file.name; this.dynamicValidateForm.pictureDomains[this.Index ].fileName.push({name:file[0].name,url:this.url});
this.url=file.url; }
this.dynamicValidateForm.pictureDomains[this.Index ].fileName.push({name:this.fName,url:this.url}); })
//console.log(this.fName);
//console.log(this.taskName);
}, },
uploadSuccessL(response,file,fileList){ uploadFileL(fileObj){
this.fName=file.name; let formData = new window.FormData();
this.url=file.url; formData.set("file",fileObj.file);
this.dynamicValidateForm.layerDomains[this.Index ].fileName.push({name:this.fName,url:this.url}); var file = formData.getAll("file");
// console.log(this.fName); this.axios.post("/files/upload",formData,{
// console.log(this.dynamicValidateForm.layerDoamins[this.Index].fileName); headers:{
"Content-type":"multipart/form-data"
}
}).then(res=>{
if(res.code == 0)
alert("文件上传失败,请重新上传");
else{
this.url = res.data;
this.dynamicValidateForm.layerDomains[this.Index ].fileName.push({name:file[0].name,url:this.url});
}
})
}, },
// //上传文件
// uploadSuccessF(response,file,fileList){
// this.fName=file.name;
// this.url=file.url;
// this.dynamicValidateForm.domains[this.Index ].fileName.push({name:this.fName,url:this.url});
// //console.log(this.fName);
// //console.log(this.taskName);
// // console.log(this.dynamicValidateForm.domains[this.Index].fileName);
// },
// uploadSuccessP(response,file,fileList){
// this.fName=file.name;
// this.url=file.url;
// this.dynamicValidateForm.pictureDomains[this.Index ].fileName.push({name:this.fName,url:this.url});
// //console.log(this.fName);
// //console.log(this.taskName);
// },
// uploadSuccessL(response,file,fileList){
// this.fName=file.name;
// this.url=file.url;
// this.dynamicValidateForm.layerDomains[this.Index ].fileName.push({name:this.fName,url:this.url});
// // console.log(this.fName);
// // console.log(this.dynamicValidateForm.layerDoamins[this.Index].fileName);
// },
//删除上传的文件 //删除上传的文件
handleRemoveF(file,fileList){ handleRemoveF(file,fileList){
var flag = 0;
var url ;
for(i = 0 ; i < this.dynamicValidateForm.domains.length && flag == 0;i++){
for(j = 0 ; j < this.dynamicValidateForm.domains[i].fileName.length ; j++){
if(file.name == this.dynamicValidateForm.domains[i].fileName[j].name){
url = this.dynamicValidateForm.domain[i].fileName[j].url;
this.dynamicValidateForm.domains[i].fileName.splice(j,1);
flag = 1;
break;
}
}
}
// this.axios({
// method:'post',
// params:{
// url : url
// },
// url:'/files/del',
// }).then(res=>{
//
// })
}, },
handleRemoveP(file,fileList){ handleRemoveP(file,fileList){
var flag = 0;
var url;
for(i = 0 ; i < this.dynamicValidateForm.pictureDomains.length && flag ==0;i++){
for(j = 0 ; j < this.dynamicValidateForm.pictureDomains[i].fileName.length ; j++){
if(file.name == this.dynamicValidateForm.pictureDomains[i].fileName[j].name){
url = this.dynamicValidateForm.pictureDomains[i].fileName[j].url;
this.dynamicValidateForm.pictureDomains[i].fileName.splice(j,1);
flag = 1;
break;
}
}
}
// this.axios({
// method:'post',
// params:{
// url : url
// },
// url:'/files/del',
// }).then(res=>{
//
// })
}, },
handleRemoveL(file,fileList){ handleRemoveL(file,fileList){
var flag = 0;
var url;
for(i = 0 ; i < this.dynamicValidateForm.layerDomains.length && flag == 0 ;i++){
for(j = 0 ; j < this.dynamicValidateForm.layerDomains[i].fileName.length ; j++){
if(file.name == this.dynamicValidateForm.layerDomains[i].fileName[j].name){
url = this.dynamicValidateForm.layerDomains[i].fileName[j].url;
this.dynamicValidateForm.layerDomains[i].fileName.splice(j,1);
flag = 1;
break;
}
}
}
// this.axios({
// method:'post',
// params:{
// url : url
// },
// url:'/files/del',
// }).then(res=>{
//
// })
}, },
submitForm(formName) { submitForm(formName) {
console.log(this.dynamicValidateForm); console.log(this.dynamicValidateForm);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment