feat:修改导出模板走后台接口
This commit is contained in:
@@ -177,48 +177,37 @@
|
|||||||
},
|
},
|
||||||
downloadTemplate:function(){
|
downloadTemplate:function(){
|
||||||
let language=localStorage.getItem('nz-language-' + localStorage.getItem('nz-username')) || 'en'; //初始未选择默认 en 英文
|
let language=localStorage.getItem('nz-language-' + localStorage.getItem('nz-username')) || 'en'; //初始未选择默认 en 英文
|
||||||
let fileName=this.exportFileName+'-'+'template'+'.xlsx';
|
let fileName=this.exportFileName+'-'+'template-'+this.getTimeString()+'.xlsx';
|
||||||
let xmlHttp = new XMLHttpRequest();
|
|
||||||
xmlHttp.responseType = "blob";
|
let url=null;
|
||||||
xmlHttp.onload=function(){
|
if (this.importUrl.indexOf("asset") > -1) {
|
||||||
if(this.status === 200){
|
url = "/asset/template";
|
||||||
let blob=this.response;
|
} /*else if (this.importUrl.indexOf("endpoint") > -1) {
|
||||||
let reader = new FileReader();
|
url = "/endpoint/template";
|
||||||
reader.readAsDataURL(blob); // 转换为base64,可以直接放入a标签href
|
}*/
|
||||||
reader.onload = function(e) {
|
|
||||||
// 转换完成后创建a标签下载
|
let param={language:language}
|
||||||
let a = document.createElement('a');
|
if(!url){
|
||||||
a.download = fileName;
|
console.error('no interface support')
|
||||||
a.href = e.target.result;
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
a.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
xmlHttp.open("GET",'/static/template/'+language+'/'+fileName,true);
|
this.exportExcel(url,param,fileName)
|
||||||
xmlHttp.send();
|
|
||||||
},
|
},
|
||||||
formatJson(filterVal, jsonData) {
|
formatJson(filterVal, jsonData) {
|
||||||
return jsonData.map(v => filterVal.map(j => v[j]))
|
return jsonData.map(v => filterVal.map(j => v[j]))
|
||||||
},
|
},
|
||||||
exportCur:function(){
|
exportCur:function(){
|
||||||
this.exportExcel();
|
this.exportExcel(this.exportUrl,this.params,this.exportFileName+'-'+this.getTimeString()+'.xlsx');
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
},
|
},
|
||||||
exportAll:function(){
|
exportAll:function(){
|
||||||
let params=JSON.parse(JSON.stringify(this.params));
|
let params=JSON.parse(JSON.stringify(this.params));
|
||||||
params.pageSize=-1;
|
params.pageSize=-1;
|
||||||
this.exportExcel(params);
|
this.exportExcel(this.exportUrl,params,this.exportFileName+'-'+this.getTimeString()+'.xlsx');
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
},
|
},
|
||||||
exportExcel:function(params){
|
exportExcel:function(url,params,fileName){
|
||||||
let temp=this;
|
let temp=this;
|
||||||
if(!params){
|
axios.get(url,{responseType:'blob',params:params}).then(res=>{
|
||||||
params=temp.params;
|
|
||||||
}
|
|
||||||
axios.get(this.exportUrl,{responseType:'blob',params:params}).then(res=>{
|
|
||||||
let fileName=temp.exportFileName+'-'+temp.getTimeString()+'.xlsx';
|
|
||||||
if(window.navigator.msSaveOrOpenBlob){
|
if(window.navigator.msSaveOrOpenBlob){
|
||||||
// 兼容ie11
|
// 兼容ie11
|
||||||
let blobObject = new Blob([res.data]);
|
let blobObject = new Blob([res.data]);
|
||||||
@@ -255,7 +244,6 @@
|
|||||||
let hours=this.formatNum(date.getHours());
|
let hours=this.formatNum(date.getHours());
|
||||||
let minutes=this.formatNum(date.getMinutes());
|
let minutes=this.formatNum(date.getMinutes());
|
||||||
let seconds=this.formatNum(date.getSeconds());
|
let seconds=this.formatNum(date.getSeconds());
|
||||||
console.log(day)
|
|
||||||
return year + split + month + split + day + ' ' + hours + split + minutes + split + seconds;
|
return year + split + month + split + day + ' ' + hours + split + minutes + split + seconds;
|
||||||
},
|
},
|
||||||
formatNum:function(num){
|
formatNum:function(num){
|
||||||
|
|||||||
Reference in New Issue
Block a user