{/* 添加面包屑组件 */}
@@ -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) => {
-
= (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 => (
+
+ ))}
{
-