添加表格导出功能
This commit is contained in:
@@ -3,19 +3,20 @@ import createAxios from '@/utils/request'
|
||||
import { requestPayload } from '@/utils/request'
|
||||
import { Method } from 'axios'
|
||||
import { mainHeight } from '@/utils/layout'
|
||||
import { filtration } from './tableMethod'
|
||||
|
||||
interface TableStoreParams {
|
||||
url: string // 请求地址
|
||||
pk?: string
|
||||
pk?: string
|
||||
column: TableColumn[]
|
||||
params?: anyObj
|
||||
method?: Method // 请求方式
|
||||
params?: anyObj
|
||||
method?: Method // 请求方式
|
||||
isWebPaging?: boolean // 是否前端分页
|
||||
showPage?: boolean //是否需要分页
|
||||
paramsPOST?: boolean // post请求 params传参
|
||||
publicHeight?: number //计算高度
|
||||
resetCallback?: () => void // 重置
|
||||
loadCallback?: () => void // 接口调用后的回调
|
||||
loadCallback?: () => void // 接口调用后的回调
|
||||
beforeSearchFun?: () => void // 接口调用前的回调
|
||||
}
|
||||
|
||||
@@ -31,6 +32,8 @@ export default class TableStore {
|
||||
ref: null,
|
||||
selection: [],
|
||||
data: [],
|
||||
allData: [],
|
||||
allFlag: false,
|
||||
webPagingData: [],
|
||||
total: 0,
|
||||
params: {
|
||||
@@ -78,26 +81,28 @@ export default class TableStore {
|
||||
},
|
||||
requestPayload(this.method, this.table.params, this.paramsPOST)
|
||||
)
|
||||
).then((res: any) => {
|
||||
if (res.data) {
|
||||
this.table.data = res.data.records || res.data
|
||||
this.table.total = res.data?.total || res.data.length || 0
|
||||
} else {
|
||||
this.table.data = []
|
||||
this.table.total = 0
|
||||
}
|
||||
if (Array.isArray(res)) {
|
||||
this.table.data = res
|
||||
}
|
||||
if (this.isWebPaging) {
|
||||
this.table.webPagingData = window.XEUtils.chunk(this.table.data, this.table.params.pageSize)
|
||||
this.table.data = this.table.webPagingData[this.table.params.pageNum - 1]
|
||||
}
|
||||
this.table.loadCallback && this.table.loadCallback()
|
||||
this.table.loading = false
|
||||
}).catch(() => {
|
||||
this.table.loading = false
|
||||
})
|
||||
)
|
||||
.then((res: any) => {
|
||||
if (res.data) {
|
||||
this.table.data = res.data.records || res.data
|
||||
this.table.total = res.data?.total || res.data.length || 0
|
||||
} else {
|
||||
this.table.data = []
|
||||
this.table.total = 0
|
||||
}
|
||||
if (Array.isArray(res)) {
|
||||
this.table.data = res
|
||||
}
|
||||
if (this.isWebPaging) {
|
||||
this.table.webPagingData = window.XEUtils.chunk(this.table.data, this.table.params.pageSize)
|
||||
this.table.data = this.table.webPagingData[this.table.params.pageNum - 1]
|
||||
}
|
||||
this.table.loadCallback && this.table.loadCallback()
|
||||
this.table.loading = false
|
||||
})
|
||||
.catch(() => {
|
||||
this.table.loading = false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,6 +178,25 @@ export default class TableStore {
|
||||
() => {
|
||||
console.warn('No action defined')
|
||||
}
|
||||
],
|
||||
[
|
||||
'export',
|
||||
() => {
|
||||
// this.index()
|
||||
let params = { ...this.table.params, pageNum: 1, pageSize: this.table.total }
|
||||
createAxios(
|
||||
Object.assign(
|
||||
{
|
||||
url: this.url,
|
||||
method: this.method
|
||||
},
|
||||
requestPayload(this.method, params, this.paramsPOST)
|
||||
)
|
||||
).then(res => {
|
||||
this.table.allData = filtration(res.data.records || res.data)
|
||||
this.table.allFlag = data.showAllFlag || true
|
||||
})
|
||||
}
|
||||
]
|
||||
])
|
||||
const action = actionFun.get(event) || actionFun.get('default')
|
||||
|
||||
Reference in New Issue
Block a user