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