feat: implement order export to Excel with excelize library
This commit is contained in:
@@ -150,7 +150,7 @@ export const adminApi = {
|
||||
|
||||
getOrders: (params?: any) => api.get('/admin/orders', { params }),
|
||||
getOrderById: (id: number) => api.get(`/admin/orders/${id}`),
|
||||
exportOrders: () => api.get('/admin/orders/export'),
|
||||
exportOrders: () => api.get('/admin/orders/export', { responseType: 'blob' }),
|
||||
processRefund: (id: number, data: any) => api.put(`/admin/orders/${id}/refund`, data),
|
||||
updateOrderStatus: (id: number, data: any) => api.put(`/admin/orders/${id}/status`, data),
|
||||
|
||||
|
||||
@@ -254,8 +254,21 @@ async function processRefund(id: number, status: string) {
|
||||
}
|
||||
|
||||
async function exportOrders() {
|
||||
await adminApi.exportOrders()
|
||||
ElMessage.success('导出完成')
|
||||
try {
|
||||
const res = await adminApi.exportOrders()
|
||||
const blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = `orders_${new Date().toISOString().slice(0, 10)}.xlsx`
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
window.URL.revokeObjectURL(url)
|
||||
ElMessage.success('导出完成')
|
||||
} catch {
|
||||
ElMessage.error('导出失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchOrders)
|
||||
|
||||
Reference in New Issue
Block a user