diff --git a/queryEnergy.html b/queryEnergy.html index bf78d9a..b086a6c 100644 --- a/queryEnergy.html +++ b/queryEnergy.html @@ -185,6 +185,7 @@ 查询 + 导出 @@ -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(")/", "");