diff --git a/src/api/common.js b/src/api/common.js index 2332cd2..b2e2bda 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -25,3 +25,14 @@ data: param }) } + +// 批量导出 +export function batchExportBrand(params) { + return request({ + url: 'brandInfo/listExport', + method: 'post', + timeout: 120000, + data: params, + responseType: 'blob' // 这一步也很关键,一定要加上 responseType 值为 blob + }) +} diff --git a/src/api/common.js b/src/api/common.js index 2332cd2..b2e2bda 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -25,3 +25,14 @@ data: param }) } + +// 批量导出 +export function batchExportBrand(params) { + return request({ + url: 'brandInfo/listExport', + method: 'post', + timeout: 120000, + data: params, + responseType: 'blob' // 这一步也很关键,一定要加上 responseType 值为 blob + }) +} diff --git a/src/views/product/brandList.vue b/src/views/product/brandList.vue index aea433c..a73f2a8 100644 --- a/src/views/product/brandList.vue +++ b/src/views/product/brandList.vue @@ -78,7 +78,6 @@ 详情 编辑 删除 - @@ -86,7 +85,6 @@ - @@ -105,7 +103,8 @@ //逻辑 import { tableRowClassName } from "../../utils/myUtils/changeTableTr"; -import { listPage ,batchDelete,Branddelete } from '../../api/product/brand' +import { listPage, batchDelete, Branddelete } from '@/api/product/brand' +import { batchExportBrand } from '@/api/common' import { listMixin,elDataDialog } from '../../utils/myUtils/mixins/listPage' import { outToExcel } from '../../utils/myUtils/exportToExcel' export default { @@ -210,9 +209,27 @@ }) }, // - exportToExcel(){ - listPage('limit=1000000000&offset=1', {}).then(res => { - outToExcel(res.rows) + exportToExcel() { + // 全屏加载动画 + const loading = this.$loading({ + lock: true, + text: '数据处理中,请稍后...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.7)' + }) + batchExportBrand(this.selectInfo).then(res => { + loading.close() // 关闭加载动画 + const blob = new Blob([res.data]) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) // 创建下载的链接 + downloadElement.href = href + downloadElement.download = `品牌列表.xlsx` // 下载后文件名 + document.body.appendChild(downloadElement) + downloadElement.click() // 点击下载 + document.body.removeChild(downloadElement) // 下载完成移除元素 + window.URL.revokeObjectURL(href) // 释放blob对象 + }).catch((res) => { + loading.close() }) } }