import html2canvas from 'html2canvas'; import { ElMessage } from 'element-plus'; /** * 打印图表 * @param chartElement 图表DOM元素 */ export const printChart = async (chartElement: HTMLElement) => { if (!chartElement) { ElMessage.warning('图表未加载'); return; } try { const canvas = await html2canvas(chartElement); const dataUrl = canvas.toDataURL('image/png'); // 创建打印窗口 const printWindow = window.open('', '_blank'); if (!printWindow) { ElMessage.error('请允许打开新窗口'); return; } printWindow.document.write(`