修改导出接口

UI_2022-02-10
e 3 years ago
parent e26e401bdf
commit 67756e57ac
  1. 20
      src/libs/util.js
  2. 30
      src/pages/record/details/index.vue

@ -111,17 +111,17 @@ const util = {
},
// 传入文件名和数据,下载文件
downloadFileDirect(fileName,data) {
if ("download" in document.createElement("a")) { // 非IE下载
const elink = document.createElement("a");
elink.download = fileName;
elink.style.display = "none";
elink.href = URL.createObjectURL(data);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(data)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(data, fileName);
navigator.msSaveBlob(data, fileName)
}
},
// 成功提示

@ -54,6 +54,10 @@
</template>
<script>
import { mapState, mapActions } from "vuex";
import axios from 'axios'
import Setting from "@/setting";
import util from "@/libs/util";
export default {
data() {
return {
@ -64,6 +68,7 @@ export default {
page: 1,
pageSize: 10,
multipleSelection: [],
token:util.local.get(Setting.tokenKey),
}
},
mounted() {
@ -88,11 +93,30 @@ export default {
},
exportData() { //
if (this.multipleSelection.length) {
let ids = this.multipleSelection.map(i => i.reportId);
location.href = `${this.api.exportPracticeByStudentDetail}?ids=${ids.toString()}`;
let ids = this.multipleSelection.map(item => {
return item.reportId;
});
axios.get(`${this.api.exportPracticeByStudentDetail}?projectId=${this.projectId}&ids=${ids.toString()}`,{
headers: {
token: this.token
},
responseType: 'blob'
}).then((res) => {
util.downloadFileDirect(`按数据库统计使用概况导出.xls`,new Blob([res.data]))
}).catch(res => {})
// location.href = this.$get(`${this.api.exportPracticeByStudentDetail}?projectId=${this.projectId}&token=${this.token}&ids=${ids.toString()}`);
} else {
location.href = `${this.api.exportPracticeByStudentDetail}?ids=`;
axios.get(`${this.api.exportPracticeByStudentDetail}?projectId=${this.projectId}&ids=`,{
headers: {
token: this.token
},
responseType: 'blob'
}).then((res) => {
util.downloadFileDirect(`按数据库统计使用概况导出.xls`,new Blob([res.data]))
}).catch(res => {})
// location.href = `${this.api.exportPracticeByStudentDetail}?projectId=${this.projectId}&token=${this.token}&ids=`;
}
},
tableRowStyle({ row, column, rowIndex, columnIndex }) {
if (rowIndex % 2 === 0) {

Loading…
Cancel
Save