excel文档导出
This commit is contained in:
@@ -147,7 +147,7 @@ const createOrder = async () => {
|
||||
branchId: restaurantId,
|
||||
orderRemarks: orderRemark.value,
|
||||
orderMoney: totalPrice.value,
|
||||
orderStatus: 0
|
||||
orderStatus: 1
|
||||
},
|
||||
items: orderItems
|
||||
}
|
||||
|
@@ -4,6 +4,14 @@
|
||||
<template #header>
|
||||
<span>花费图表</span>
|
||||
</template>
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="downloadExcel"
|
||||
style="margin-bottom: 20px"
|
||||
>
|
||||
导出订单Excel
|
||||
</el-button>
|
||||
|
||||
<el-select v-model="selectedBranch" placeholder="选择店铺" style="width: 200px; margin-bottom: 20px">
|
||||
<el-option
|
||||
v-for="branch in branchList"
|
||||
@@ -122,6 +130,30 @@ onMounted(async () => {
|
||||
|
||||
// 当选择店铺时重新渲染图表
|
||||
watch(selectedBranch, renderChart)
|
||||
|
||||
const downloadExcel = async () => {
|
||||
try {
|
||||
const response = await axios.get(`/api/user/orders/export/${customerId}`, {
|
||||
responseType: 'blob' // 一定要是 blob,否则文件下载不了
|
||||
})
|
||||
|
||||
const blob = new Blob([response.data], {
|
||||
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
})
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
// 你可以自定义文件名,也可以从后端 header 获取 filename
|
||||
link.setAttribute('download', `订单数据_${new Date().toISOString().slice(0,10)}.xlsx`)
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
window.URL.revokeObjectURL(url)
|
||||
} catch (error) {
|
||||
ElMessage.error('导出失败,请稍后再试')
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
Reference in New Issue
Block a user