excel文档导出

This commit is contained in:
zzz
2025-06-21 11:59:21 +08:00
parent cfa65ea872
commit dd6888376d
2 changed files with 33 additions and 1 deletions

View File

@@ -147,7 +147,7 @@ const createOrder = async () => {
branchId: restaurantId,
orderRemarks: orderRemark.value,
orderMoney: totalPrice.value,
orderStatus: 0
orderStatus: 1
},
items: orderItems
}

View File

@@ -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>