diff --git a/packages/examination/src/api/exam-online/index.tsx b/packages/examination/src/api/exam-online/index.tsx index 0f5a853..ded6520 100644 --- a/packages/examination/src/api/exam-online/index.tsx +++ b/packages/examination/src/api/exam-online/index.tsx @@ -1,5 +1,5 @@ import axios from '../axios'; - +//查询 export function getList(obj: any) { return axios({ url: '/ex/exam-schedule/select', @@ -7,7 +7,7 @@ export function getList(obj: any) { params: obj }) } - +//新增考试 export function add(obj: any) { return axios.post( '/ex/exam-schedule/insert', obj,{ @@ -16,25 +16,65 @@ export function add(obj: any) { } }) } - -export function edit(obj: any) { +// 编辑的画面初期值检索 +export function getExamDataById(id:any){ return axios({ - url: '/ex/exam-edit', + url: '/ex/exam-schedule/getExamDataById', method: 'get', + params: {id:id} }) } - +// 发布与批量发布 +export function doPublish(ids: string[]) { + debugger + return axios.post('/ex/exam-schedule/publish', ids, { + headers: { + 'Content-Type': 'application/json' + } + }) +} +// 删除与批量删除 +export function doDelete(ids: string[]) { + return axios.post('/ex/exam-schedule/delete', ids, { + headers: { + 'Content-Type': 'application/json' + } + }) +} +// 撤回与批量撤回 +export function doCancel(ids: string[]) { + return axios.post('/ex/exam-schedule/cancel', ids, { + headers: { + 'Content-Type': 'application/json' + } + }) +} +// 答题情况 +export const getDetail = async(id:any) =>{ + const response = await axios({ + url: '/ex/exam-schedule/getDetailById', + method: 'get', + params: {id:id} + }) + return response.data; +} +// 监管行业下拉列表 export const getIndustryList = async () => { const response = await axios.get('/ex/exam-schedule/getIndustry'); return response.data; }; - -export const getPaperList = async (obj:any) => { - const response = await axios.get('/ex/dict/dictionary?code='+obj); +// 试卷名称下拉列表(含考试分数,考试时长) +export const getPaperListWithDetails = async () => { + const response = await axios.get('/ex/exam-schedule/getPaper'); + return response.data; +}; +// 试卷状态check +export const paperStatusCheck = async () => { + const response = await axios.get('/ex/exam-schedule/paperStatusCheck'); return response.data; }; - -export const getRegionList = async (obj:any) => { - const response = await axios.get('/ex/dict/dictionary?code='+obj); +// 试卷删除状态check +export const paperDeleteCheck = async () => { + const response = await axios.get('/ex/exam-schedule/paperDeleteCheck'); return response.data; }; \ No newline at end of file diff --git a/packages/examination/src/components/contentMain/index.js b/packages/examination/src/components/contentMain/index.js index 08bb7e8..ec1481c 100644 --- a/packages/examination/src/components/contentMain/index.js +++ b/packages/examination/src/components/contentMain/index.js @@ -26,6 +26,7 @@ import ExamEdit from "../../views/exam-online/exam-edit"; // demo list import Customer from 'views/statistical/list'; import CustomerDetail from 'views/statistical/detail'; +import ExamDetail from "../../views/exam-online/exam-detail"; class ContentMain extends Component { render() { @@ -46,6 +47,7 @@ class ContentMain extends Component { + diff --git a/packages/examination/src/views/exam-online/compoents/ExamDetailPage.tsx b/packages/examination/src/views/exam-online/compoents/ExamDetailPage.tsx new file mode 100644 index 0000000..fb56035 --- /dev/null +++ b/packages/examination/src/views/exam-online/compoents/ExamDetailPage.tsx @@ -0,0 +1,154 @@ +import React, { useEffect, useState } from 'react'; +import { Table, Button } from 'antd'; +import { withRouter, RouteComponentProps } from 'react-router-dom'; +import { getDetail } from "api/exam-online/index"; +import ESBreadcrumbComponent from "./ESBreadcrumbComponent"; + +// 定义考试参与情况数据类型,移除 serialNumber 字段 +type ExamParticipationItem = { + key: string; + name: string; + phoneNumber: string; + score: number; + wrongQuestionIds: string; +}; + +// 定义考试答题情况数据类型,移除 serialNumber 字段 +type ExamAnswerItem = { + key: string; + questionNumber: string; + wrongPeopleCount: number; + wrongPeopleRatio: string; +}; + +// 定义 API 返回的数据类型 +type DetailResponse = { + examParticipation: ExamParticipationItem[]; + examAnswer: ExamAnswerItem[]; +}; + +// 考试参与情况表格列定义 +const examParticipationColumns: Array<{ + title: string; + dataIndex?: keyof ExamParticipationItem; + key: string; + render?: (text: any, record: ExamParticipationItem, index: number) => React.ReactNode; +}> = [ + { + title: '序号', + key: 'serialNumber', + render: (_, __, index) => index + 1 + }, + { + title: '姓名', + dataIndex: 'name', + key: 'name', + }, + { + title: '手机号', + dataIndex: 'phoneNumber', + key: 'phoneNumber', + }, + { + title: '成绩', + dataIndex: 'score', + key: 'score', + }, + { + title: '错题编号', + dataIndex: 'wrongQuestionIds', + key: 'wrongQuestionIds', + render: (wrongQuestionIds)=>{ + if(!wrongQuestionIds) { + return "-"; + }else{ + return wrongQuestionIds; + } + } + }, +]; + +// 考试答题情况表格列定义 +const examAnswerColumns: Array<{ + title: string; + dataIndex?: keyof ExamAnswerItem; + key: string; + render?: (text: any, record: ExamAnswerItem, index: number) => React.ReactNode; +}> = [ + { + title: '序号', + key: 'serialNumber', + render: (_, __, index) => index + 1 + }, + { + title: '题目号', + dataIndex: 'questionNumber', + key: 'questionNumber', + }, + { + title: '错题人数', + dataIndex: 'wrongPeopleCount', + key: 'wrongPeopleCount', + }, + { + title: '错题人数占比', + dataIndex: 'wrongPeopleRatio', + key: 'wrongPeopleRatio', + render: (wrongPeopleRatio)=>{ + return wrongPeopleRatio+'%' + } + }, +]; + +const ExamStatisticsPage: React.FC = ({ history }) => { + const [examParticipationData, setExamParticipationData] = useState([]); + const [examAnswerData, setExamAnswerData] = useState([]); + + useEffect(() => { + const fetchData = async () => { + try { + const examId = sessionStorage.getItem('examId'); + sessionStorage.removeItem('examId'); + // 调用 getDetail 方法进行初始化检索 + const response = await getDetail(examId); + // 从 AxiosResponse 中提取 data 部分 + const data = response as DetailResponse; + // 假设返回的数据结构包含 examParticipation 和 examAnswer 两个字段 + setExamParticipationData(data.examParticipation); + setExamAnswerData(data.examAnswer); + } catch (error) { + console.error('数据加载失败:', error); + } + }; + + fetchData(); + }, []); + + return ( +
+ + {/* 考试参与情况部分 */} +

考试参与情况

+ + + {/* 考试答题情况部分 */} +

考试答题情况

+
+ + {/* 返回按钮 */} +
+ +
+ + ); +}; + +export default withRouter(ExamStatisticsPage); \ No newline at end of file diff --git a/packages/examination/src/views/exam-online/compoents/ExamEditPage.tsx b/packages/examination/src/views/exam-online/compoents/ExamEditPage.tsx index 67d9e47..5a8193f 100644 --- a/packages/examination/src/views/exam-online/compoents/ExamEditPage.tsx +++ b/packages/examination/src/views/exam-online/compoents/ExamEditPage.tsx @@ -1,26 +1,27 @@ import React, { useRef, useEffect, useState } from 'react'; // @ts-ignore -import {Form, Input, Select, DatePicker, Space, ColProps, Button, Cascader, DefaultOptionType} from 'antd'; +import { Form, Input, Select, DatePicker, Space, ColProps, Button, Cascader, DefaultOptionType, Rule } from 'antd'; import type { FormProps, FormInstance } from 'antd'; import ESBreadcrumbComponent from './ESBreadcrumbComponent'; // 引入面包屑组件 import { withRouter, RouteComponentProps } from 'react-router-dom'; // 引入 withRouter 和 RouteComponentProps -import { getList, add, edit, getIndustryList, getPaperList } from "api/exam-online/index"; -import {provice} from './city.js'; // 引入省市县数据 +import { add, getIndustryList, getPaperListWithDetails } from "api/exam-online/index"; // 修改接口为获取带详情的试卷列表 +import { provice } from './city.js'; // 引入省市县数据 +import moment, { Moment } from 'moment'; // 引入 moment const { Option } = Select; // 定义表单数据的类型 -interface ExamBasicInfo { +export interface ExamBasicInfo { examId: string; examName: string; - regulatoryIndustry: string; - paperName: string; + regulatedIndustry: string | number; + paperId: string; examScore: string; examDuration: string; - examRegion: string[]; // 修改为数组类型,用于存储级联选择的值 - examValidTime: Date | null; - examInvalidTime: Date | null; - contentDescription: string; + examRegion: string | string[]; + validFrom: Moment | null; + validTo: Moment | null; + remark: string; } // 定义组件的 Props 类型 @@ -33,7 +34,11 @@ interface ExamBasicInfoFormProps extends FormProps { interface PropsWithRouter extends ExamBasicInfoFormProps, RouteComponentProps {} export const convertToCascaderData = (): DefaultOptionType[] => { - return provice.map(item => { + const allRegionOption: DefaultOptionType = { + value: '全区域', + label: '全区域' + }; + const provinceOptions = provice.map(item => { const province: DefaultOptionType = { value: item.name, label: item.name, @@ -44,18 +49,58 @@ export const convertToCascaderData = (): DefaultOptionType[] => { }; return province; }); -} + return [allRegionOption, ...provinceOptions]; +}; + +// 日期格式化函数,支持 Moment 类型 +const formatDate = (date: Moment | null | string): string | null => { + if (!date) return null; + if (typeof date === 'string') { + date = moment(date); + if (!date.isValid()) { + return null; + } + } + const year = date.year(); + const month = String(date.month() + 1).padStart(2, '0'); + const day = String(date.date()).padStart(2, '0'); + return `${year}-${month}-${day}`; +}; + +// 将省/市格式的数据转换为数组 +const convertRegionToArr = (region: string) => { + return region ? region.split('/') : []; +}; + +// 将数组转换为省/市格式的字符串 +const convertArrToRegion = (regionArr: string[]) => { + return regionArr.join('/'); +}; const ExamBasicInfoForm: React.FC = (props) => { const { isEdit, initialFormData = {} as ExamBasicInfo, history } = props; const formRef = useRef>(null); - const [industryOptions, setIndustryOptions] = useState<{ value: string; label: string }[]>([]); - const [paperOptions, setPaperOptions] = useState<{ value: string; label: string }[]>([]); + const [industryOptions, setIndustryOptions] = useState<{ value: string | number; label: string }[]>([]); + const [allPaperOptions, setAllPaperOptions] = useState<{ value: string; label: string; examScore: string; examDuration: string; regulatedIndustry: string | number }[]>([]); + const [paperOptions, setPaperOptions] = useState<{ value: string; label: string; examScore: string; examDuration: string }[]>([]); + const [isDataLoaded, setIsDataLoaded] = useState(false); const onFinish = async (values: ExamBasicInfo) => { + const { examRegion, validFrom, validTo, ...otherValues } = values; + // 处理 examRegion 转换为省/市 格式 + const formattedRegion = Array.isArray(examRegion) ? convertArrToRegion(examRegion) : examRegion; + // 格式化日期 + const formattedValidFrom = formatDate(validFrom); + const formattedValidTo = formatDate(validTo); + const formattedValues = { + ...otherValues, + examRegion: formattedRegion, + validFrom: formattedValidFrom, + validTo: formattedValidTo + }; try { // 调用 add 方法将数据发送到后台 - const response = await add(values); + const response = await add(formattedValues); console.log('数据登录成功:', response); // 登录成功后迁移到 /exam-schedule 页面 history.push("/exam-schedule"); @@ -96,9 +141,17 @@ const ExamBasicInfoForm: React.FC = (props) => { const industryResponse = await getIndustryList(); setIndustryOptions(industryResponse.map((item: any) => ({ value: item.industry_id, label: item.industry_name }))); - // 获取试卷列表 - // const paperResponse = await getPaperList(); - // setPaperOptions(paperResponse.map(item => ({ value: item, label: item }))); + // 获取带详情的试卷列表 + const paperResponse = await getPaperListWithDetails(); + setAllPaperOptions(paperResponse.map((item: any) => ({ + value: item.paper_id, + label: item.paper_name, + examScore: item.total_score, + examDuration: item.exam_duration, + regulatedIndustry: item.regulatory_industry // 假设接口返回的试卷数据包含监管行业信息 + }))); + + setIsDataLoaded(true); } catch (error) { console.error('数据加载失败:', error); } @@ -107,6 +160,77 @@ const ExamBasicInfoForm: React.FC = (props) => { fetchData(); }, []); + useEffect(() => { + if (isDataLoaded) { + const initialIndustry = initialFormData.regulatedIndustry; + if (String(initialIndustry) === '') { + setPaperOptions(allPaperOptions); + } else if (initialIndustry) { + const filteredPapers = allPaperOptions.filter(paper => String(paper.regulatedIndustry) === String(initialIndustry)); + setPaperOptions(filteredPapers); + } else { + setPaperOptions(allPaperOptions); + } + + if (formRef.current) { + formRef.current.setFieldsValue({ + examId: initialFormData.examId || '', + examName: initialFormData.examName || '', + examRegion: typeof initialFormData.examRegion === "string" ? convertRegionToArr(initialFormData.examRegion) : initialFormData.examRegion, + validFrom: initialFormData.validFrom || null, + validTo: initialFormData.validTo || null, + remark: initialFormData.remark || '', + }); + + // 设置监管行业的值 + const selectedIndustry = industryOptions.find(option => String(option.value) === String(initialFormData.regulatedIndustry)); + if (selectedIndustry) { + formRef.current.setFieldsValue({ regulatedIndustry: selectedIndustry.value }); + } else { + formRef.current.setFieldsValue({ regulatedIndustry: '' }); + } + + // 设置试卷名称 + formRef.current.setFieldsValue({ paperId: initialFormData.paperId || '' }); + + // 触发 handlePaperChange 函数更新考试分值和考试时长 + handlePaperChange(initialFormData.paperId); + } + } + }, [isDataLoaded, allPaperOptions, initialFormData, industryOptions]); + + const handleIndustryChange = (value: string | number) => { + if (String(value) === '') { + setPaperOptions(allPaperOptions); + } else { + const filteredPapers = allPaperOptions.filter(paper => String(paper.regulatedIndustry) === String(value)); + setPaperOptions(filteredPapers); + } + if (formRef.current) { + formRef.current.setFieldsValue({ paperId: '' }); // 清空试卷选择 + } + }; + + const handlePaperChange = (value: string) => { + const selectedPaper = allPaperOptions.find(paper => String(paper.value) === String(value)); + if (selectedPaper && formRef.current) { + // 更新表单中的考试分值和考试时长 + formRef.current.setFieldsValue({ + examScore: selectedPaper.examScore, + examDuration: selectedPaper.examDuration + }); + } + }; + + // 自定义验证函数:检查考试失效时间不得小于考试有效时间 + const validateValidTo = (rule: Rule, value: Moment | null) => { + const validFrom = formRef.current?.getFieldValue('validFrom'); + if (validFrom && value && value.isBefore(validFrom)) { + return Promise.reject(new Error('考试失效时间不得小于考试有效时间')); + } + return Promise.resolve(); + }; + return (
{/* 添加面包屑组件 */} @@ -117,18 +241,6 @@ const ExamBasicInfoForm: React.FC = (props) => { {...props} name="examBasicInfo" onFinish={onFinish} - initialValues={{ - examId: initialFormData.examId || '', - examName: initialFormData.examName || '', - regulatoryIndustry: initialFormData.regulatoryIndustry || '', - paperName: initialFormData.paperName || '', - examScore: initialFormData.examScore || '', - examDuration: initialFormData.examDuration || '', - examRegion: initialFormData.examRegion || [], // 初始化 examRegion 为数组 - examValidTime: initialFormData.examValidTime || null, - examInvalidTime: initialFormData.examInvalidTime || null, - contentDescription: initialFormData.contentDescription || '', - }} autoComplete="off" labelCol={labelCol} wrapperCol={wrapperCol} @@ -151,15 +263,12 @@ const ExamBasicInfoForm: React.FC = (props) => { - + {industryOptions.map(option => ( = (props) => { }, ]} > - {paperOptions.map(option => ( = (props) => { diff --git a/packages/examination/src/views/exam-online/compoents/ExamListPage.tsx b/packages/examination/src/views/exam-online/compoents/ExamListPage.tsx index b5bf525..43723be 100644 --- a/packages/examination/src/views/exam-online/compoents/ExamListPage.tsx +++ b/packages/examination/src/views/exam-online/compoents/ExamListPage.tsx @@ -1,8 +1,8 @@ -import React, { useState } from 'react'; -import { Table, Input, Button, Select, DatePicker, Modal, Checkbox } from 'antd'; +import React, { useEffect, useState } from 'react'; +import { Table, Input, Button, Select, DatePicker, Modal, Checkbox, message } from 'antd'; import { Link, withRouter } from 'react-router-dom'; import moment, { Moment } from 'moment'; // 引入 moment -import { getList, add, edit } from "api/exam-online/index"; +import { getList, doDelete, doCancel, doPublish, getIndustryList } from "api/exam-online/index"; const { Option } = Select; @@ -27,13 +27,30 @@ const ExamListPage = ({ history }: { history: any }) => { validTime: null as Moment | null, // 修改为 Moment 类型 }); const [selectedRows, setSelectedRows] = useState([]); - const [examList, setExamList] = useState([]); // 初始化为空数组 + const [industryOptions, setIndustryOptions] = useState<{ value: string | number; label: string }[]>([]); + const [allExamList, setAllExamList] = useState([]); // 存储所有数据 + const [currentPageExamList, setCurrentPageExamList] = useState([]); // 存储当前页数据 const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 0, }); + useEffect(() => { + const fetchData = async () => { + try { + // 获取监管行业列表 + const industryResponse = await getIndustryList(); + setIndustryOptions(industryResponse.map((item: any) => ({ value: item.industry_id, label: item.industry_name }))); + } catch (error) { + console.error('数据加载失败:', error); + } + }; + handleReset(); + fetchData(); + }, []); + + // 重置按钮 const handleReset = () => { setSearchForm({ examName: '', @@ -45,6 +62,7 @@ const ExamListPage = ({ history }: { history: any }) => { handleSearch(); }; + // 查询 const handleSearch = async (page = 1) => { try { // 构建请求参数 @@ -52,64 +70,104 @@ const ExamListPage = ({ history }: { history: any }) => { examName: searchForm.examName, paperName: searchForm.paperName, regulatedIndustry: searchForm.regulatedIndustry, - validDate: searchForm.validTime ? searchForm.validTime.format('YYYY-MM-DD') : '', // 使用 moment 的 format 方法 - page: page, - pageSize: pagination.pageSize, + validDate: searchForm.validTime ? searchForm.validTime.format('YYYY-MM-DD') : '' // 使用 moment 的 format 方法 }; // 调用 getList 方法向后端发送请求 const response = await getList(params); // 假设后端返回的数据结构为 { data: Exam[]; total: number } const data = response.data; - setExamList(data.data); + setAllExamList(data.data); + const startIndex = (page - 1) * pagination.pageSize; + const endIndex = startIndex + pagination.pageSize; + setCurrentPageExamList(data.data.slice(startIndex, endIndex)); setPagination({ ...pagination, current: page, total: data.total }); } catch (error) { console.error('查询出错:', error); } }; - const handleDeleteSelected = () => { - // 实现删除选中数据的逻辑 - const newExamList = examList.filter((exam) => !selectedRows.includes(exam.examId)); - setExamList(newExamList); - setSelectedRows([]); + // 批量删除 + const handleDeleteSelected = async () => { + const ids = selectedRows.map((value) => { return String(value) }); + const res = await doDelete(ids); + if (!res) { + return; + } + research(); }; - const handleWithdrawSelected = () => { - // 实现撤回选中数据的逻辑 - const newExamList: Exam[] = examList.map((exam) => { - if (selectedRows.includes(exam.examId) && exam.publishStatus === 1) { - return { ...exam, publishStatus: 2 }; // 修正为 publishStatus + // 批量撤回 + const handleWithdrawSelected = async () => { + const selectedExams = currentPageExamList.filter(exam => selectedRows.includes(exam.examId)); + const hasWithdrawn = selectedExams.some(exam => exam.publishStatus === 0 || exam.publishStatus === 2); + + if (hasWithdrawn) { + const confirm = window.confirm('选中数据当中有无法撤回的数据,是否继续'); + if (!confirm) { + return; } - return exam; - }); - setExamList(newExamList); - setSelectedRows([]); + } + + // 筛选出可以撤回的数据 + const validExams = selectedExams.filter(exam => exam.publishStatus === 1); + const validIds = validExams.map(exam => String(exam.examId)); + + if (validIds.length > 0) { + const res = await doCancel(validIds); + if (!res) { + return; + } + research(); + } }; - const handlePublishSelected = () => { - // 实现发布选中数据的逻辑 - const newExamList: Exam[] = examList.map((exam) => { - if (selectedRows.includes(exam.examId) && exam.publishStatus === 0) { - return { ...exam, publishStatus: 1 }; // 修正为 publishStatus + // 批量发布 + const handlePublishSelected = async () => { + const selectedExams = currentPageExamList.filter(exam => selectedRows.includes(exam.examId)); + const hasPublishedOrWithdrawn = selectedExams.some(exam => exam.publishStatus === 1 || exam.publishStatus === 2); + + if (hasPublishedOrWithdrawn) { + const confirm = window.confirm('选中数据当中有无法发布的数据,是否继续'); + if (!confirm) { + return; } - return exam; - }); - setExamList(newExamList); - setSelectedRows([]); + } + + // 筛选出可以发布的数据 + const validExams = selectedExams.filter(exam => exam.publishStatus === 0); + const validIds = validExams.map(exam => String(exam.examId)); + + if (validIds.length > 0) { + const res = await doPublish(validIds); + if (!res) { + return; + } + research(); + } }; + // 新增考试 const handleAddExam = () => { // 实现新增考试跳转逻辑 history.push('/exam-add'); console.log('跳转到新增考试页面'); }; + // 编辑 const handleEdit = (examId: number) => { + sessionStorage.setItem('examId', String(examId)); + history.push('/exam-edit'); // 实现编辑跳转逻辑 console.log('跳转到编辑页面,examId:', examId); }; + const handleDetail = (examId: number)=>{ + sessionStorage.setItem('examId', String(examId)); + history.push('/exam-detail'); + console.log('跳转到答题情况,examId:', examId); + } + const [qrCodeVisible, setQrCodeVisible] = useState(false); const [qrCodeData, setQrCodeData] = useState(''); @@ -119,45 +177,55 @@ const ExamListPage = ({ history }: { history: any }) => { setQrCodeVisible(true); }; - const handlePublishSingle = (examId: number) => { - // 实现单条数据发布逻辑 - const newExamList: Exam[] = examList.map((exam) => { - if (exam.examId === examId && exam.publishStatus === 0) { - return { ...exam, publishStatus: 1 }; // 修正为 publishStatus - } - return exam; - }); - setExamList(newExamList); + // 发布 + const handlePublishSingle = async (examId: number) => { + const ids = [String(examId)]; + const res = await doPublish(ids); + if (!res) { + return; + } + research(); }; - const handleWithdrawSingle = (examId: number) => { - // 实现单条数据撤回逻辑 - const newExamList: Exam[] = examList.map((exam) => { - if (exam.examId === examId && exam.publishStatus === 1) { - return { ...exam, publishStatus: 2 }; // 修正为 publishStatus - } - return exam; - }); - setExamList(newExamList); + // 撤回 + const handleWithdrawSingle = async (examId: number) => { + const ids = [String(examId)]; + const res = await doCancel(ids); + if (!res) { + return; + } + research(); }; - const handleDeleteSingle = (examId: number) => { - // 实现单条数据删除逻辑 - const newExamList = examList.filter((exam) => exam.examId !== examId); - setExamList(newExamList); + // 删除 + const handleDeleteSingle = async (examId: number) => { + const ids = [String(examId)]; + const res = await doDelete(ids); + if (!res) { + return; + } + research(); }; + // 页面重新查询 + const research = () => { + handleSearch(pagination.current); + } + // 处理全选和取消全选 const handleSelectAll = (checked: boolean) => { if (checked) { - setSelectedRows(examList.map((exam) => exam.examId)); + // 确保 currentPageExamList 有数据 + if (currentPageExamList.length > 0) { + setSelectedRows(currentPageExamList.map((exam) => exam.examId)); + } } else { setSelectedRows([]); } }; // 判断是否全选 - const isAllSelected = examList.length > 0 && selectedRows.length === examList.length; + const isAllSelected = currentPageExamList.length > 0 && selectedRows.length === currentPageExamList.length; const columns = [ { @@ -193,7 +261,7 @@ const ExamListPage = ({ history }: { history: any }) => { dataIndex: 'examName', key: 'examName', render: (text: string, record: Exam) => ( - {text} + handleDetail(record.examId)}>{text} ), }, { @@ -231,7 +299,6 @@ const ExamListPage = ({ history }: { history: any }) => { dataIndex: 'publishStatus', key: 'publishStatus', render: (publishStatus: 0 | 1 | 2) => { - console.log(publishStatus) switch (publishStatus) { case 0: return '待发布'; @@ -281,6 +348,8 @@ const ExamListPage = ({ history }: { history: any }) => { const handleTableChange = (pagination: any) => { setPagination(pagination); + // 清空选中状态 + setSelectedRows([]); handleSearch(pagination.current); }; @@ -311,10 +380,12 @@ const ExamListPage = ({ history }: { history: any }) => { } style={{ width: 150, marginRight: 8 }} > - - - - {/* 可以添加更多选项 */} + + {industryOptions.map(option => ( + + ))} { -
{ + constructor(props: any) { + super(props); + this.state = { + resData: undefined, + visible: false, + title: '', + current: {} + } + } + + componentDidMount() { + // this.getList() + } + + render() { + return ( +
+ +
+ ) + } +} + +export default ExamDetail; \ No newline at end of file diff --git a/packages/examination/src/views/exam-online/exam-edit.tsx b/packages/examination/src/views/exam-online/exam-edit.tsx index 64377bf..a99a0a9 100644 --- a/packages/examination/src/views/exam-online/exam-edit.tsx +++ b/packages/examination/src/views/exam-online/exam-edit.tsx @@ -1,34 +1,107 @@ -import React, { Component } from "react"; +import React, { Component } from 'react'; import ExamEditPage from "./compoents/ExamEditPage"; +import { withRouter, RouteComponentProps } from 'react-router-dom'; +import { getExamDataById } from "api/exam-online/index"; +import { ExamBasicInfo } from './compoents/ExamEditPage'; +import moment, { Moment } from 'moment'; + +// 定义 Params 类型 +interface Params { + examId: string; +} + +// 定义 location.state 的类型 +interface LocationState { + data?: number; +} + +// 定义状态类型,使用 ExamBasicInfo 接口 interface States { - resData: any - visible: boolean - title: string - current: any + initialFormData: ExamBasicInfo; + isLoading: boolean; } -class ExamEdit extends Component { - constructor(props: any) { +// 扩展 RouteComponentProps 以包含自定义的 location.state 类型 +interface CustomRouteComponentProps extends RouteComponentProps { + location: { + state: LocationState; + pathname: string; + search: string; + hash: string; + }; +} + +class ExamEdit extends Component { + constructor(props: CustomRouteComponentProps) { super(props); this.state = { - resData: undefined, - visible: false, - title: '', - current: {} - } + initialFormData: { + examId: '', + examName: '', + regulatedIndustry: '', + paperId: '', + examScore: '', + examDuration: '', + examRegion: '', + validFrom: null, + validTo: null, + remark: '' + }, + isLoading: true + }; } - componentDidMount() { - // this.getList() + async componentDidMount() { + + // 尝试从 sessionStorage 中获取 examId + const storedExamId = sessionStorage.getItem('examId'); + const examId = storedExamId; + if(storedExamId){ + sessionStorage.removeItem('examId'); + } + + try { + const response = await getExamDataById(examId); + const newInitFormData: ExamBasicInfo = { + examId: response.data.examId, + examName: response.data.examName, + regulatedIndustry: response.data.regulatedIndustry, + paperId: response.data.paperId, + examScore: response.data.examScore, + examDuration: response.data.examDuration, + examRegion: response.data.examRegion, + validFrom: response.data.validFrom ? moment(response.data.validFrom) : null, + validTo: response.data.validTo ? moment(response.data.validTo) : null, + remark: response.data.remark + }; + + console.log('Received examId:', examId); + + this.setState({ + initialFormData: newInitFormData, + isLoading: false + }); + } catch (error) { + console.error('获取考试数据失败:', error); + this.setState({ + isLoading: false + }); + } } render() { + const { isLoading, initialFormData } = this.state; + + if (isLoading) { + return
加载中...
; + } + return (
- +
- ) + ); } } -export default ExamEdit; \ No newline at end of file +export default withRouter(ExamEdit); \ No newline at end of file