新增后端带条件导出功能(示例见用户管理控制器)
This commit is contained in:
@@ -7,6 +7,13 @@ export function add(data) {
|
||||
data
|
||||
})
|
||||
}
|
||||
export function downloadUser() {
|
||||
return request({
|
||||
url: 'api/users/download',
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
export function del(id) {
|
||||
return request({
|
||||
|
||||
@@ -147,3 +147,15 @@ export function removeClass(ele, cls) {
|
||||
ele.className = ele.className.replace(reg, ' ')
|
||||
}
|
||||
}
|
||||
|
||||
export function downloadFile(obj, name, suffix) {
|
||||
const url = window.URL.createObjectURL(new Blob([obj]))
|
||||
const link = document.createElement('a')
|
||||
link.style.display = 'none'
|
||||
link.href = url
|
||||
const fileName = parseTime(new Date()) + '-' + name + '.' + suffix
|
||||
link.setAttribute('download', fileName)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<!-- 导出 -->
|
||||
<div style="display: inline-block;">
|
||||
<el-button
|
||||
v-permission="['ADMIN']"
|
||||
v-permission="['ADMIN','USER_ALL','USER_SELECT']"
|
||||
:loading="downloadLoading"
|
||||
size="mini"
|
||||
class="filter-item"
|
||||
@@ -98,9 +98,9 @@
|
||||
import checkPermission from '@/utils/permission'
|
||||
import initData from '@/mixins/initData'
|
||||
import initDict from '@/mixins/initDict'
|
||||
import { del } from '@/api/user'
|
||||
import { del, downloadUser } from '@/api/user'
|
||||
import { getDepts } from '@/api/dept'
|
||||
import { parseTime } from '@/utils/index'
|
||||
import { parseTime, downloadFile } from '@/utils/index'
|
||||
import eForm from './form'
|
||||
export default {
|
||||
components: { eForm },
|
||||
@@ -192,15 +192,10 @@ export default {
|
||||
// 导出
|
||||
download() {
|
||||
this.downloadLoading = true
|
||||
import('@/utils/export2Excel').then(excel => {
|
||||
const tHeader = ['ID', '用户名', '邮箱', '头像地址', '状态', '注册日期', '最后修改密码日期']
|
||||
const filterVal = ['id', 'username', 'email', 'avatar', 'enabled', 'createTime', 'lastPasswordResetTime']
|
||||
const data = this.formatJson(filterVal, this.data)
|
||||
excel.export_json_to_excel({
|
||||
header: tHeader,
|
||||
data,
|
||||
filename: 'table-list'
|
||||
})
|
||||
downloadUser().then(result => {
|
||||
downloadFile(result, '用户列表', 'xls')
|
||||
this.downloadLoading = false
|
||||
}).catch(() => {
|
||||
this.downloadLoading = false
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user