var fileformData = new FormData(); fileformData.append('file1',vm.fileListLeft[0].raw); fileformData.append('file2',vm.fileListRight[0].raw); axios.post(ctx + 'fire/drawing/compare',fileformData,{responseType: 'blob'}).then(function (res) { try{ parent.vm.compareLoading = false; }catch (e){ vm.compareLoading = false; } if (res.status === 200 && res.data) { var disposition = res.headers['content-disposition']; var contentType = res.headers['content-type']; if(contentType.includes('json')){ var data = res.data; var reader = new FileReader(); reader.onload = function () { var errorInfos = JSON.parse(reader.result); var msg = errorInfos.content; try{ parent.vm.comparePdfShow = false; parent.vm.compareLoading = false; }catch (e){ vm.comparePdfShow = false; vm.compareLoading = false; } vm.$message.error(msg||'操作失败,请稍后重试!'); } reader.onerror = function (err) { vm.$message.error('转换失败,请稍后重试!'); } reader.readAsText(data); }else{ try { var fileName = decodeURI(disposition.substring(disposition.indexOf('filename=') + 9, disposition.length)); vm.fileType = vm.getFileType(fileName); var blob = res.data; var objectURL = window.URL.createObjectURL(blob); if(vm.fileType == "pdf"){ try{ parent.vm.fileType = "pdf"; parent.vm.pdfUrl = ctx + 'fire/drawing/viewPdf.html?fileUrl='+objectURL; }catch (e){ vm.fileType = "pdf"; vm.pdfUrl = ctx + 'fire/drawing/viewPdf.html?fileUrl='+objectURL; } }else{ try{ parent.vm.imgUrl = ctx + 'fire/drawing/viewPic.html?objectURL='+objectURL+'&fileName='+fileName; }catch (e){ vm.imgUrl = ctx + 'fire/drawing/viewPic.html?objectURL='+objectURL+'&fileName='+fileName; } } } catch (e) { try{ parent.vm.comparePdfShow = false; parent.vm.compareLoading = false; }catch (e){ vm.comparePdfShow = false; vm.compareLoading = false; } vm.$message.error(res.data.content||'操作失败,请稍后重试!'); } } } else {// 其它情况 try{ parent.vm.comparePdfShow = false; parent.vm.compareLoading = false; }catch (e){} vm.$message.error(res.data.content||'操作失败,请稍后重试!'); } }).catch(function (error) { try{ parent.vm.comparePdfShow = false; parent.vm.compareLoading = false; }catch (e){} vm.$message.error('对比出错,请稍后重试!'); });