import React, { useState, useEffect } from 'react'; import { Row, Col, Input, Select, Button, Table, Space } from 'antd'; import { withRouter, RouteComponentProps } from 'react-router-dom'; // 引入 withRouter 和 RouteComponentProps import { getExamPaperAnalysisPageList, getIndustryList, getPaperAnalysisData, getScoreDistribution } from 'api/exam-online/index'; import ESBreadcrumbComponent from "./ESBreadcrumbComponent"; // 假设的接口导入 const { Option } = Select; // 定义表格数据项的类型 export type PaperAnalysisDataItem = { key: string; paperId: string; paperName: string; industry: string; useCount: number; participantCount: number; accuracyRate: string; }; const ExamPaperAnalysisPage: React.FC = ({history}) => { const [paperName, setPaperName] = useState(''); const [industry, setIndustry] = useState(''); const [industryOptions, setIndustryOptions] = useState<{ value: string; label: string }[]>([]); const [tableData, setTableData] = useState([]); const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: tableData.length, }); const [totalCount, setTotalCount] = useState(0); const [usedCount, setUsedCount] = useState(0); const [disabledCount, setDisabledCount] = useState(0); useEffect(() => { const fetchData = async () => { try { const industryResponse = await getIndustryList(); setIndustryOptions(industryResponse.map((item: any) => ({ value: item.industry_id, label: item.industry_name }))); const paperAnalysisResponse = await getPaperAnalysisData(); setTotalCount(paperAnalysisResponse.totalCount); setUsedCount(paperAnalysisResponse.usedCount); setDisabledCount(paperAnalysisResponse.disabledCount); handleSearch(); } catch (error) { console.error('数据获取失败:', error); } }; fetchData(); }, []); const handleReset = () => { setPaperName(''); setIndustry(''); setTableData(tableData); setPagination({ ...pagination, current: 1, }); }; const handleShowScoreDistribution = async (paperId: string) => { try { // const response = await getScoreDistribution(paperId); sessionStorage.setItem("paperId",paperId) history.push("/exam_paper_analysis_detail"); } catch (error) { console.error('获取成绩分布数据失败:', error); } }; const handleSearch = () => { const param = { paperName:paperName, industry:industry, } const fetchData = async () => { try { const resultData = await getExamPaperAnalysisPageList(param) setTableData(resultData); setPagination({ ...pagination, current: 1, total: resultData.length, }); } catch (error) { console.error('数据获取失败:', error); } }; fetchData(); }; const handleTableChange = (newPagination: any) => { setPagination(newPagination); }; const columns = [ { title: '序号', dataIndex: 'key', render: (text: any, record: PaperAnalysisDataItem, index: number) => (pagination.current - 1) * pagination.pageSize + index + 1, }, { title: '试卷名称', dataIndex: 'paperName', }, { title: '监管行业', dataIndex: 'industry', }, { title: '使用次数', dataIndex: 'useCount', }, { title: '参与人数', dataIndex: 'participantCount', }, { title: '准确率', dataIndex: 'accuracyRate', render: (text:any, record: PaperAnalysisDataItem) =>{ if(record.accuracyRate){ return record.accuracyRate+"%"; }else{ return ""; } } }, { title: '查看', dataIndex: 'view', render: (text:any, record: PaperAnalysisDataItem) => {handleShowScoreDistribution(record.paperId)}}>题目正确率分析, }, ]; return (
{/* 检索条件行 */} 试卷名称: setPaperName(e.target.value)} style={{ width: 'calc(100% - 100px)' }} /> 监管行业: {/* 试卷数量行 */}
总计 {totalCount}
已使用 {usedCount}
停用 {disabledCount}
{/* 表格 */}

已使用试卷分析

); }; export default withRouter(ExamPaperAnalysisPage);