feat: change report button to preview in new window
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useParams, useNavigate } from 'react-router-dom';
|
import { useParams, useNavigate } from 'react-router-dom';
|
||||||
import { Card, Button, Space } from 'antd';
|
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 StudentProfileContent from '../../components/StudentProfileContent';
|
||||||
import PermissionButton from '../../components/PermissionButton';
|
import PermissionButton from '../../components/PermissionButton';
|
||||||
|
import api from '../../api';
|
||||||
|
|
||||||
const StudentProfilePage: React.FC = () => {
|
const StudentProfilePage: React.FC = () => {
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
@@ -13,9 +14,17 @@ const StudentProfilePage: React.FC = () => {
|
|||||||
|
|
||||||
const studentId = Number(id);
|
const studentId = Number(id);
|
||||||
|
|
||||||
const handleDownloadReport = () => {
|
const handlePreviewReport = async () => {
|
||||||
const token = localStorage.getItem('token');
|
try {
|
||||||
window.open(`/api/archive/${studentId}/report?token=${token}`, '_blank');
|
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 (
|
return (
|
||||||
@@ -30,10 +39,10 @@ const StudentProfilePage: React.FC = () => {
|
|||||||
<PermissionButton
|
<PermissionButton
|
||||||
permission="student:view"
|
permission="student:view"
|
||||||
type="primary"
|
type="primary"
|
||||||
icon={<DownloadOutlined />}
|
icon={<EyeOutlined />}
|
||||||
onClick={handleDownloadReport}
|
onClick={handlePreviewReport}
|
||||||
>
|
>
|
||||||
生成档案报表
|
预览报告
|
||||||
</PermissionButton>
|
</PermissionButton>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user