import { useState } from 'react' import { Card, Row, Col, DatePicker, Button, Space, message, Divider, Alert } from 'antd' import { DownloadOutlined, FileExcelOutlined } from '@ant-design/icons' import dayjs from 'dayjs' import { exportApi } from '../services/api' function Export() { const [monthValue, setMonthValue] = useState(dayjs()) const [yearValue, setYearValue] = useState(dayjs()) const [monthlyLoading, setMonthlyLoading] = useState(false) const [yearlyLoading, setYearlyLoading] = useState(false) const [error, setError] = useState(null) // Download file helper const downloadFile = (blob, filename) => { const url = window.URL.createObjectURL(blob) const link = document.createElement('a') link.href = url link.download = filename document.body.appendChild(link) link.click() document.body.removeChild(link) window.URL.revokeObjectURL(url) } // Generate export timestamp for filename (YYMMDDHHmm format) const getExportTimestamp = () => { const now = dayjs() return now.format('YYMMDDHHmm') } // Handle monthly export const handleMonthlyExport = async () => { if (!monthValue) { message.warning('请选择月份') return } setMonthlyLoading(true) setError(null) try { const year = monthValue.year() const month = monthValue.month() + 1 const response = await exportApi.monthly(year, month) const timestamp = getExportTimestamp() const filename = `work_report_${year}-${String(month).padStart(2, '0')}_${timestamp}.xlsx` downloadFile(response.data, filename) message.success('月度报表导出成功') } catch (error) { const errorMsg = '导出失败: ' + (error.message || '未知错误') setError(errorMsg) message.error(errorMsg) } finally { setMonthlyLoading(false) } } // Handle yearly export const handleYearlyExport = async () => { if (!yearValue) { message.warning('请选择年份') return } setYearlyLoading(true) setError(null) try { const year = yearValue.year() const response = await exportApi.yearly(year) const timestamp = getExportTimestamp() const filename = `work_report_${year}_${timestamp}.xlsx` downloadFile(response.data, filename) message.success('年度报表导出成功') } catch (error) { const errorMsg = '导出失败: ' + (error.message || '未知错误') setError(errorMsg) message.error(errorMsg) } finally { setYearlyLoading(false) } } return (
{error && ( setError(null)} /> )} 月度报表导出 } >

导出指定月份的工作记录明细和汇总统计

选择月份:
年度报表导出 } >

导出指定年份的工作记录明细和按月汇总统计

选择年份:

月度报表包含:

  • 明细表: 人员、日期、物品、单价、数量、总价
  • 月度汇总: 每人总金额及合计

年度报表包含:

  • 明细表: 人员、日期、物品、单价、数量、总价
  • 年度汇总: 每人按月统计及年度合计
) } export default Export