代码提交_6_3

This commit is contained in:
lixiaobang 2024-06-06 08:59:04 +08:00
parent 8f7aaf109b
commit c511d67954
1 changed files with 31 additions and 0 deletions

View File

@ -185,6 +185,7 @@
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">查询</el-button>
<el-button type="success" @click="onExport" style="background: #57c7d4;border:#57c7d4">导出</el-button>
</el-form-item>
</el-form>
</div>
@ -290,6 +291,36 @@
}
this.getTabel(timeData)
},
//导出列表
onExport() {
let timeData = {
start_date: moment(this.addForm.date_range_start).format("YYYY-MM-DD"),
end_date: moment(this.addForm.date_range_end).format("YYYY-MM-DD")
}
this.downloadFile('http://172.16.1.253:8087/Vue/ExportEnergy.ashx?start_date=' + timeData.start_date + '&end_date=' + timeData.end_date)
},
downloadFile(url) {
fetch(url)
.then(response => {
var disposition = response.headers.get('Content-Disposition');
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
var filename = matches != null && matches[1] ? matches[1].replace(/['"]/g, '') : 'download';
return response.blob().then(blob => {
var a = document.createElement('a');
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = decodeURIComponent(filename);
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
});
})
.catch(error => console.error('下载文件时出错:', error));
},
//时间戳转化方法
formatStringDate(jsondate) {
jsondate = jsondate.replace("/Date(", "").replace(")/", "");