<el-button class="el-button-reset" @click='downLoad' >下载</el-button>
// 下载 浮层点击 确定 回调
downLoad : function(min,max){
const self = this;
let param = {//校验接口需要传的参数
fileType : this.fileType,
uniqTag : this.docData.uniqTag,
begin : min,
end : max,
bookFileCode:this.fileCode
};
this.ifDownloadOver(()=>{
this.xiazaiDialogVis = false;
this.iframeDownLoad(`/upload/download?uniqTag=${self.docData.uniqTag}&begin=${min}&end=${max}`);
/*window.open(`/upload/download?uniqTag=${self.docData.uniqTag}&begin=${min}&end=${max}`);*/
},param);
},
// 判断是否超出下载量
ifDownloadOver(callback,param){
const self = this;
ajax({//请求校验的接口
url : '/user/judgeUserDownloads',
data : param,
success : (res) => {
if(res.success){
callback && callback();//通过校验开始下载
}else{
self.$message.warning(res.errorMsg);//没有通过校验返回错误提示
}
}
});
},
iframeDownLoad : function(url){
let _this = this;
let name = 'J_iframe' + (+ new Date());
let iframe = $(`<iframe name="${name}" src="${url}" class="J_iframe hide" width="0" height="0"></iframe>`);
iframe.on('load',function(){
let body = window.frames[name].document;
let html = body.body.innerHTML;
// 解决如果成功下载文件流 iframe会重定向到error页面 从而读取error页面的innrHTML , 通过---------- 判断是否后台给入的参数
if(html.indexOf('----------') !== -1){
let message = html.split('----------')[1];
_this.$message.error(message);
}
});
$('body').append(iframe);
},

