feat: change report button to preview in new window

This commit is contained in:
2026-07-07 09:53:39 +08:00
parent 36978813cf
commit 6e6dd25dc1

View File

@@ -1,9 +1,10 @@
import React from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Card, Button, Space } from 'antd';
import { ArrowLeftOutlined, DownloadOutlined } from '@ant-design/icons';
import { ArrowLeftOutlined, EyeOutlined } from '@ant-design/icons';
import StudentProfileContent from '../../components/StudentProfileContent';
import PermissionButton from '../../components/PermissionButton';
import api from '../../api';
const StudentProfilePage: React.FC = () => {
const { id } = useParams<{ id: string }>();
@@ -13,9 +14,17 @@ const StudentProfilePage: React.FC = () => {
const studentId = Number(id);
const handleDownloadReport = () => {
const token = localStorage.getItem('token');
window.open(`/api/archive/${studentId}/report?token=${token}`, '_blank');
const handlePreviewReport = async () => {
try {
const { html } = await api.get<{ html: string }>(`/archive/${studentId}/report-html`);
const w = window.open('', '_blank');
if (w) {
w.document.write(html);
w.document.close();
}
} catch (err) {
console.error('Failed to load report HTML:', err);
}
};
return (
@@ -30,10 +39,10 @@ const StudentProfilePage: React.FC = () => {
<PermissionButton
permission="student:view"
type="primary"
icon={<DownloadOutlined />}
onClick={handleDownloadReport}
icon={<EyeOutlined />}
onClick={handlePreviewReport}
>
</PermissionButton>
}
>