jquery
//文件上传
$.ajaxFileUpload({
url:yxUrl.upFileUrl+"?tableName=K_IM_CHECK_DEAL&aboutRecordId="+data.data.dealDetID, //用于文件上传的服务器端请求地址
secureuri: false, //一般设置为false
fileElementId: 'file-ipt', //文件上传空间的id属性 <input type="file" id="file" name="file" />
dataType: 'json', //返回值类型 一般设置为json
success: function (data, status){ //服务器成功响应处理函数
// console.log(data);
// console.log(status);
},
error: function (data, status, e){//服务器响应失败处理函数
// console.log(e);
}
});
el-upload
1、上传
自动上传:
let formData = new FormData();
formData.append("files",file.file);
formData.append('supTaskNo',this.superviseList.supTaskNo)
formData.append('fedTaskNo',this.fedTaskNo)
this.$http.post(this.$urls.supervise.files("upload"),formData,
{ 'Content-Type':'multipart/form-data' },{
// onUploadProgress: progress =>{
// //上传过程
// for (let i = 0; i < this.newFilesList.length; i++){
// if(this.newFilesList[i].uid === file.uid){
// this.newFilesList[i].percentage = progress.loaded * 100 / progress.total
// break;
// }
// }
// }
}).then(xhr=>{
// 上传完成
if(xhr && xhr.data){
if(xhr.data.code == '10000'){
this.$message.success(xhr.data.msg);
}else{
this.$message.error(xhr.data.msg);
}
}
}).catch(e=>{
// 上传异常
})
非自动上传
_this.noFileUrl = Lvm.$api.upFileUrl + "?tableName=K_AC_WHITE_REC&aboutRecordId=" + str;
setTimeout(function() {
_this.$refs.upload2.submit();
}, 1);
2、下载or 预览
法一:
this.$http.post(this.$urls.supervise.files("download"),
{ id :file.id},null,{responseType:'blob'}).then(xhr=>{
// new Blob([data])用来创建URL的file对象或者blob对象
let url = window.URL.createObjectURL(new Blob([xhr.data]));
// 生成一个a标签
let link = document.createElement("a");
link.style.display = "none";
link.href = url;
// 生成时间戳
link.download = file.fileName
document.body.appendChild(link);
link.click();
})
handlePreview (file) {
var urls = Lvm.$api.upFileUrlDown + '?id=' + file.num;
window.open(urls, '_self');
},
3、删除
调用删除接口
4、查看
直接调用接口