From cb6471b8d8115931d8856e6bbc070c39f2834c3d Mon Sep 17 00:00:00 2001 From: gituib Date: Thu, 30 Apr 2026 15:55:46 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=86=E6=9E=90=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: traeagent --- frontend/src/pages/RackManagement.jsx | 31 ++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/RackManagement.jsx b/frontend/src/pages/RackManagement.jsx index ed9cd93..f5b7f0b 100644 --- a/frontend/src/pages/RackManagement.jsx +++ b/frontend/src/pages/RackManagement.jsx @@ -466,9 +466,34 @@ function RackManagement() { setDrawerVisible(true); }; - const handleDownloadTemplate = useCallback(() => { - window.open('/api/racks/import-template', '_blank'); - message.success('模板下载成功'); + const handleDownloadTemplate = useCallback(async () => { + try { + message.loading('正在下载模板...', 0); + + const response = await api.get('/racks/import-template', { + responseType: 'blob', + }); + + // 创建下载链接 + const blob = new Blob([response], { + type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + }); + const url = window.URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', '机柜导入模板.xlsx'); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + + message.destroy(); + message.success('模板下载成功'); + } catch (error) { + message.destroy(); + message.error('模板下载失败'); + console.error('模板下载失败:', error); + } }, []); // 导出租机柜数据