修改导出接口

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

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

@ -54,6 +54,10 @@
</template> </template>
<script> <script>
import { mapState, mapActions } from "vuex";
import axios from 'axios'
import Setting from "@/setting";
import util from "@/libs/util";
export default { export default {
data() { data() {
return { return {
@ -64,6 +68,7 @@ export default {
page: 1, page: 1,
pageSize: 10, pageSize: 10,
multipleSelection: [], multipleSelection: [],
token:util.local.get(Setting.tokenKey),
} }
}, },
mounted() { mounted() {
@ -88,11 +93,30 @@ export default {
}, },
exportData() { // exportData() { //
if (this.multipleSelection.length) { if (this.multipleSelection.length) {
let ids = this.multipleSelection.map(i => i.reportId); let ids = this.multipleSelection.map(item => {
location.href = `${this.api.exportPracticeByStudentDetail}?ids=${ids.toString()}`; 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 { } 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 }) { tableRowStyle({ row, column, rowIndex, columnIndex }) {
if (rowIndex % 2 === 0) { if (rowIndex % 2 === 0) {

Loading…
Cancel
Save