题库管理和试卷管理代码提交

main
hujunpeng 3 months ago
parent e9093ceb57
commit 2a7edb37ee
  1. 107
      packages/examination/src/api/examPaper/index.tsx
  2. 1
      packages/examination/src/api/question/index.tsx
  3. 162
      packages/examination/src/views/examPaper/examPaperAdd.tsx
  4. 303
      packages/examination/src/views/examPaper/examPaperList.tsx
  5. 131
      packages/examination/src/views/examPaper/examPaperView.tsx
  6. 342
      packages/examination/src/views/question/questionAdd.tsx
  7. 21
      packages/examination/src/views/question/questionEdit.tsx
  8. 37
      packages/examination/src/views/question/questionList.tsx

@ -1,111 +1,80 @@
import axios from '../axios';
/*
*
*/
export function getList(num: number, page: number, obj:object){
const rData = {
num:num,
page:page,
industryId:obj['industryId'],
paperName:obj['paperName']
};
/**
*
*/
export function getList(data: any) {
return axios({
url: "/ex/examPaper/list",
url: "/ex/examPaper/getList",
method: 'post',
data: rData
})
}
/*
* ()
*/
export function deleteSingle(id: number) {
return axios({
url: '/ex/examPaper/delete?id=' + id,
method: 'get'
data: data
});
}
/*
*
*/
export function deleteMultiple(ids: any) {
/**
*
*/
export function delExamPaper(ids: any) {
return axios({
url: '/ex/examPaper/deleteList',
url: '/ex/examPaper/delExamPaper',
method: 'post',
data: ids
});
}
/*
*
*/
export function updatePaperStatus(id: number, paperStatus:number) {
/**
*
*/
export function upPaperStatus(ids: any, paperStatus: number) {
const data = {
id: id,
paperStatus:paperStatus
ids: ids,
paperStatus: paperStatus
};
return axios({
url: '/ex/examPaper/updatePaperStatus',
url: '/ex/examPaper/upPaperStatus',
method: 'post',
data: data
});
}
/*
*
*/
export function batchUpdatePaperStatus(data: any) {
/**
*
*/
export function getExamPaperDetail(id: any) {
return axios({
url: '/ex/examPaper/batchUpdatePaperStatus',
method: 'post',
data: data
});
}
/*
*
*/
export function getDetail(id: string|null) {
return axios({
url: '/ex/examPaper/getDetail?id=' + id,
url: '/ex/examPaper/getExamPaperDetail?id=' + id,
method: 'get'
});
}
/*
*
*/
export function getRandomQuestions(industryId: string, questionCount: number){
const data = {
industryId:industryId,
questionCount:questionCount
};
/**
*
*/
export function getRandomQuestions(data: any) {
return axios({
url: "/ex/examPaper/getRandomQuestions",
method: 'post',
data: data
})
});
}
/*
*
*/
export function save(data: object) {
/**
*
*/
export function addExamPaper(data: any) {
return axios({
url: "/ex/examPaper/add",
url: "/ex/examPaper/addExamPaper",
method: 'post',
data: data
});
}
/*
*
*/
export function update(data: object) {
/**
*
*/
export function editExamPaper(data: any) {
return axios({
url: "/ex/examPaper/update",
url: "/ex/examPaper/editExamPaper",
method: 'post',
data: data
});

@ -63,4 +63,3 @@ export function findIndustry() {
method: 'get'
});
}

@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { Form, Input, Button, Radio, Checkbox, Select, message, Modal, Table } from 'antd';
import { getRandomQuestions, save, update, getDetail} from 'api/examPaper';
import { getRandomQuestions, addExamPaper, editExamPaper, getExamPaperDetail} from 'api/examPaper';
import { getList ,findIndustry} from 'api/question';
import { dictionary } from "../../api/dict";
@ -11,7 +11,6 @@ interface optionsState {
label: string;
}
// 定义单个试题的状态接口
interface QuestionState {
id: string;
serviceTypeId: string;
@ -21,21 +20,15 @@ interface QuestionState {
answer: string | null;
}
// 定义组件的状态接口
interface States {
id: string| null;
isEdit: string| null;
num: number;
page: number;
total: number;
listQuery: {
industryId: string | undefined;
serviceTypeId: string | undefined;
questionContent: string | undefined;
};
industryDict: any;
serviceTypeDict: any;
isLoading: boolean;
loading: boolean;
questions: QuestionState[];
isModalVisible: boolean;
selectedParams: any;
@ -57,14 +50,9 @@ class ExamPaperAdd extends Component<any, States> {
num: 10,
page: 1,
total: 0,
listQuery: {
industryId: undefined,
serviceTypeId: undefined,
questionContent: undefined
},
industryDict: undefined,
serviceTypeDict: undefined,
isLoading: false,
loading: false,
questions: [],
isModalVisible: false,
selectedParams: {},
@ -74,41 +62,46 @@ class ExamPaperAdd extends Component<any, States> {
};
}
// 初期
componentDidMount() {
this.handleFindDict();
const id = sessionStorage.getItem('id');
const isEdit= sessionStorage.getItem('isEdit');
this.setState({ id: id ,isEdit: isEdit});
sessionStorage.removeItem('id');
sessionStorage.removeItem('isEdit');
this.findIndustry();
this.findDict();
if(isEdit === 'true'){
this.getDetail(id);
this.handleGetDetail(id);
}
}
// 字典
handleFindDict() {
// 监管行业
findIndustry() {
findIndustry().then((res: any) => {
findIndustry()
.then((res: any) => {
if (res.data) {
this.setState({ industryDict: res.data });
}
})
.catch(() => {
message.error("获取监管行业字典数据失败,请稍后重试");
});
}
// AQ服务类型
findDict() {
dictionary('serviceTypeDict').then((res) => {
dictionary("serviceTypeDict")
.then((res) => {
if (res.data) {
this.setState({ serviceTypeDict: res.data });
}
})
.catch(() => {
message.error("获取AQ服务类型字典数据失败,请稍后重试");
});
}
// 试卷详情
getDetail = (id: string|null) => {
getDetail(id).then((res: any) => {
handleGetDetail = (id: any) => {
getExamPaperDetail(id).then((res: any) => {
if (res.data) {
const newQuestions: QuestionState[] = res.data.data.map((questionData: any) => {
const options = questionData.options.split(',');
@ -128,11 +121,11 @@ class ExamPaperAdd extends Component<any, States> {
this.setState({ questions: newQuestions });
const formValues = {};
formValues['paperName'] = res.data.head.paperName;
formValues['industryId'] = res.data.head.industryId;
formValues['industryId'] = String(res.data.head.industryId);
formValues['questionCount'] = res.data.head.questionCount;
formValues['totalScore'] = res.data.head.totalScore;
formValues['examDuration'] = res.data.head.examDuration;
formValues['durationType'] = res.data.head.durationType;
formValues['durationType'] = String(res.data.head.durationType);
formValues['paperContent'] = res.data.head.paperContent;
this.formRef.current.setFieldsValue(formValues);
}
@ -141,14 +134,15 @@ class ExamPaperAdd extends Component<any, States> {
});
};
// 随机生成题目
handleRandomGenerate = () => {
// 随机生成
handleRandomQuestion = () => {
this.formRef.current.validateFields(['industryId', 'questionCount'])
.then((values: any) => {
const industryId = values.industryId;
const questionCount = values.questionCount;
// 随机获取试题
getRandomQuestions(industryId, questionCount)
const data = {
industryId: values.industryId,
questionCount: values.questionCount
};
getRandomQuestions(data)
.then((res: any) => {
if (res.data) {
if (res.data.length == 0) {
@ -184,10 +178,10 @@ class ExamPaperAdd extends Component<any, States> {
.catch(() => { });
};
// 打开手动选题模态框
handleOpenManualSelectionModal = () => {
// 手动选题
handleOpenModal = () => {
const { questions, selectedQuestionList } = this.state;
this.formRef.current.validateFields(['industryId', 'questionCount'])
this.formRef.current.validateFields(['industryId'])
.then((values: any) => {
const industryId = values.industryId;
const questionCount = values.questionCount;
@ -202,19 +196,14 @@ class ExamPaperAdd extends Component<any, States> {
.catch(() => { });
};
// 关闭手动选题模态框
handleCloseManualSelectionModal = () => {
// 关闭选题
handleCloseModal = () => {
this.setState({
isModalVisible: false,
selectedParams: {},
selectedQuestionList: [],
questionSelectList: [],
selectedRowKeys: [],
listQuery: {
industryId: undefined,
serviceTypeId: undefined,
questionContent: undefined
},
num: 10,
page: 1,
total: 0,
@ -234,17 +223,13 @@ class ExamPaperAdd extends Component<any, States> {
// 处理查询
handleQuery = () => {
this.setState({ loading: true });
const values = this.formRefSub.current.getFieldsValue();
const { num, page, selectedParams } = this.state;
const industryId = selectedParams.industryId;
const { serviceTypeId } = this.formRefSub.current.getFieldsValue(['serviceTypeId']);
const { questionContent } = this.formRefSub.current.getFieldsValue(['questionContent']);
const listQuery = {
industryId,
serviceTypeId,
questionContent
};
const data = {
...listQuery,
...values,
industryId,
num,
page
};
@ -270,12 +255,13 @@ class ExamPaperAdd extends Component<any, States> {
const { selectedQuestionList } = this.state;
const newSelectedRowKeys = selectedQuestionList.map(item => item.id);
this.setState({ questionSelectList: newQuestions, selectedRowKeys: newSelectedRowKeys });
} else {
message.warning('未找到符合条件的试题');
}
})
.catch(() => {
message.error('检索试题失败');
message.error('获取数据失败');
})
.finally(() => {
this.setState({ loading: false });
});
};
@ -289,11 +275,6 @@ class ExamPaperAdd extends Component<any, States> {
selectedQuestionList: [],
questionSelectList: [],
selectedRowKeys: [],
listQuery: {
industryId: undefined,
serviceTypeId: undefined,
questionContent: undefined
},
num: 10,
page: 1,
total: 0,
@ -301,6 +282,7 @@ class ExamPaperAdd extends Component<any, States> {
if (this.formRefSub.current) {
this.formRefSub.current.resetFields();
}
this.formRef.current.setFieldsValue({ questionCount : selectedQuestionList.length });
};
// 保存试卷
@ -310,7 +292,7 @@ class ExamPaperAdd extends Component<any, States> {
.then((values: any) => {
const { questions } = this.state;
if (questions === null || questions.length === 0) {
message.error('请至少选择一道题目');
message.error('请选择题目');
return;
}
const questionIds = questions.map(question => question.id);
@ -319,11 +301,11 @@ class ExamPaperAdd extends Component<any, States> {
id,
questionIds
};
this.setState({ isLoading: true });
if (isEdit === 'true') {
update(data)
editExamPaper(data)
.then((res) => {
if (res.data) {
const success = res["success"];
if (success) {
message.success('试卷更新成功');
this.props.history.push('/examPaperList');
} else {
@ -333,13 +315,11 @@ class ExamPaperAdd extends Component<any, States> {
.catch(() => {
message.error('试卷更新时出错,请稍后重试');
})
.finally(() => {
this.setState({ isLoading: false });
});
} else {
save(data)
addExamPaper(data)
.then((res) => {
if (res.data) {
const success = res["success"];
if (success) {
message.success('试卷保存成功');
this.props.history.push('/examPaperList');
} else {
@ -349,28 +329,27 @@ class ExamPaperAdd extends Component<any, States> {
.catch(() => {
message.error('试卷保存时出错,请稍后重试');
})
.finally(() => {
this.setState({ isLoading: false });
});
}
});
};
render() {
const { industryDict, serviceTypeDict, questions, isLoading, isModalVisible, selectedQuestionList, questionSelectList, selectedRowKeys } = this.state;
// 分页切换
const changePage = (current: number, pageSize?: number) => {
const {
industryDict,
serviceTypeDict,
questions,
loading,
isModalVisible,
selectedQuestionList,
questionSelectList,
selectedRowKeys
} = this.state;
const changePage = (current: number, pageSize: number) => {
setTimeout(() => {
this.setState({ page: current, num: pageSize || 20 });
this.setState({ page: current, num: pageSize });
this.handleQuery();
}, 0);
};
// 多少每页
const selectChange = (page: number, num: number) => {
this.setState({ page, num });
this.handleQuery();
};
// 页面跳转
const handleListQuestion = () => {
this.props.history.push('/examPaperList');
};
@ -403,7 +382,6 @@ class ExamPaperAdd extends Component<any, States> {
}
];
// 移除操作列
const columnsWithoutOperation = columns.filter((column: any) => column.dataIndex!== 'operation');
return (
<div className="container">
@ -486,10 +464,10 @@ class ExamPaperAdd extends Component<any, States> {
<div style={{ display: 'flex' }}>
<h3 style={{ fontWeight: 'bold' }}></h3>
<div>
<Button type="link" onClick={this.handleRandomGenerate}>
<Button type="link" onClick={this.handleRandomQuestion}>
</Button>
<Button type="link" onClick={this.handleOpenManualSelectionModal}>
<Button type="link" onClick={this.handleOpenModal}>
</Button>
</div>
@ -538,7 +516,7 @@ class ExamPaperAdd extends Component<any, States> {
<Button type="default" htmlType="button" onClick={handleListQuestion} style={{ marginRight: 10 }}>
</Button>
<Button type="primary" htmlType="submit" loading={isLoading} onClick={this.handleSaveExamPaper}>
<Button type="primary" htmlType="submit" onClick={this.handleSaveExamPaper}>
</Button>
</div>
@ -547,9 +525,9 @@ class ExamPaperAdd extends Component<any, States> {
title="选择试题"
open={isModalVisible}
maskClosable={false}
onCancel={this.handleCloseManualSelectionModal}
onCancel={this.handleCloseModal}
footer={[
<Button key="cancel" onClick={this.handleCloseManualSelectionModal}>
<Button key="cancel" onClick={this.handleCloseModal}>
</Button>,
<Button key="ok" type="primary" onClick={this.handleConfirmSelection}>
@ -564,9 +542,6 @@ class ExamPaperAdd extends Component<any, States> {
<Table
dataSource={selectedQuestionList}
columns={columns}
pagination={{
pageSize: 5
}}
/>
</div>
<div>
@ -615,6 +590,7 @@ class ExamPaperAdd extends Component<any, States> {
dataSource={questionSelectList}
columns={columnsWithoutOperation}
rowKey="id"
loading={loading}
rowSelection={{
selectedRowKeys: selectedRowKeys,
onChange: (newSelectedRowKeys, selectedRows) => {
@ -650,9 +626,7 @@ class ExamPaperAdd extends Component<any, States> {
showQuickJumper: true,
showSizeChanger: true,
showTotal: (total) => `${total}`,
onShowSizeChange: selectChange,
onChange: changePage,
pageSize: 5
onChange: changePage
}}
/>
</Modal>

@ -1,6 +1,6 @@
import React, { Component } from'react';
import { Form, Input, Button, Table, Select, message, Modal } from 'antd';
import { deleteSingle, deleteMultiple, getList, updatePaperStatus, batchUpdatePaperStatus } from 'api/examPaper';
import { delExamPaper, getList, upPaperStatus } from 'api/examPaper';
import { findIndustry } from 'api/question';
const { Option } = Select;
@ -8,46 +8,42 @@ const { Option } = Select;
interface States {
num: number;
page: number;
listQuery: {
industryId: string | undefined;
paperName: string | undefined;
};
list: any[];
total: number;
list: any[];
loading: boolean;
industryDict: any;
serviceTypeDict: any;
selectedRowKeys: number[];
}
class ExamPaperList extends Component<any, States> {
formRef: any;
constructor(props: any) {
super(props);
this.formRef = React.createRef();
this.state = {
num: 10,
page: 1,
listQuery: {
industryId: undefined,
paperName: undefined
},
list: [],
total: 0,
list: [],
loading: false,
industryDict: undefined,
serviceTypeDict: undefined,
selectedRowKeys: []
industryDict: [],
selectedRowKeys: [],
};
}
componentDidMount() {
this.findIndustry();
this.getList();
this.handleFindIndustry();
const savedFormValues = sessionStorage.getItem('examPaperListFormValues');
if (savedFormValues) {
const values = JSON.parse(savedFormValues);
this.formRef.current.setFieldsValue(values);
}
this.handlegetList();
}
// 监管行业
findIndustry() {
// 字典
handleFindIndustry() {
findIndustry().then((res: any) => {
if (res.data) {
this.setState({ industryDict: res.data });
@ -56,49 +52,49 @@ class ExamPaperList extends Component<any, States> {
}
// 查询
getList() {
handlegetList() {
this.setState({ loading: true });
const { num, page, listQuery } = this.state;
getList(num, page, listQuery).then((res) => {
const values = this.formRef.current.getFieldsValue();
const { num, page } = this.state;
const data = {
...values,
num,
page
};
sessionStorage.setItem('examPaperListFormValues', JSON.stringify(values));
getList(data).then((res) => {
this.setState({
loading: false,
list: res.data.data,
total: res.data.total,
selectedRowKeys: [],
});
this.setState({ loading: false });
}).catch(() => {
})
.catch(() => {
message.error('获取数据失败');
})
.finally(() => {
this.setState({ loading: false });
});
}
// 重置
handleReset = () => {
if (this.formRef.current) {
// 重置表单字段
sessionStorage.removeItem('examPaperListFormValues');
this.formRef.current.resetFields();
// 重置 listQuery 状态
this.setState({
listQuery: {
industryId: undefined,
paperName: undefined
},
selectedRowKeys: [],
});
}
};
// 删除(明细)
deleteSingle = (id: number) => {
// 删除问题
handleDeleteExamPaper = (id: number) => {
Modal.confirm({
title: '确认删除',
content: '你确定要删除这个问题吗?',
content: '你确定要删除这个试卷吗?',
onOk: () => {
deleteSingle(id).then((res) => {
const isSuccess = res.data;
if (isSuccess) {
const idList = [id];
delExamPaper(idList).then((res) => {
const success = res['success'];
if (success) {
message.success('删除成功');
this.getList();
this.handlegetList();
} else {
message.error('删除失败,请稍后重试');
}
@ -111,23 +107,23 @@ class ExamPaperList extends Component<any, States> {
});
};
// 删除
deleteMultiple = () => {
// 批量删除问题
handleBatchDeleteExamPaper = () => {
const { selectedRowKeys } = this.state;
if (selectedRowKeys.length === 0) {
message.warning('请选择要删除的问题');
message.warning('请选择要删除的试卷');
return;
}
Modal.confirm({
title: '确认删除',
content: '你确定要删除这些选中的问题吗?',
content: '你确定要删除这些选中的试卷吗?',
onOk: () => {
deleteMultiple(selectedRowKeys)
delExamPaper(selectedRowKeys)
.then((res) => {
const isSuccess = res.data;
if (isSuccess) {
const success = res['success'];
if (success) {
message.success('删除成功');
this.getList();
this.handlegetList();
} else {
message.error('删除失败,请稍后重试');
}
@ -141,72 +137,66 @@ class ExamPaperList extends Component<any, States> {
});
};
// 多选
onChange = (selectedRowKeys: React.Key[]) => {
// 行选择
handleOnChange = (selectedRowKeys: React.Key[]) => {
this.setState({
selectedRowKeys: selectedRowKeys as number[],
});
};
// 更新试卷状态
updatePaperStatus = (id: number, paperStatus: number) => {
const newStatus = paperStatus === 0? '启用' : '停用';
updatePaperStatus(id, paperStatus).then((res) => {
const isSuccess = res.data;
if (isSuccess) {
message.success(`${newStatus}成功`);
const status = paperStatus === 0? 1 : 0;
handleUpdatePaperStatus = (id: number, paperStatus: number) => {
const newStatus = paperStatus === 0? 1 : 0;
const newStatusText = paperStatus === 0? '启用' : '停用';
const idList = [id];
upPaperStatus(idList, newStatus).then((res) => {
const success = res['success'];
if (success) {
message.success(`${newStatusText}成功`);
this.setState((prevState) => ({
list: prevState.list.map((item) =>
item.id === id? { ...item, paperStatus: status } : item
item.id === id? { ...item, paperStatus: newStatus } : item
)
}));
} else {
message.error(`${newStatus}失败,请稍后重试`);
message.error(`${newStatusText}失败,请稍后重试`);
}
}).catch(() => {
message.error(`${newStatus}时发生错误,请检查`);
message.error(`${newStatusText}时发生错误,请检查`);
});
};
// 批量更新试卷状态
batchUpdatePaperStatus = (paperStatus: number) => {
handleBatchUpdatePaperStatus = (paperStatus: number) => {
const newStatus = paperStatus === 0? 1 : 0;
const newStatusText = paperStatus === 0? '启用' : '停用';
const { selectedRowKeys } = this.state;
if (selectedRowKeys.length === 0) {
message.warning('请选择要操作的试卷');
return;
}
const newStatus = paperStatus === 0? '启用' : '停用';
const { list } = this.state;
const selectedRecords = list.filter(record => selectedRowKeys.includes(record.id));
const invalidRecords = selectedRecords.filter(record => record.paperStatus !== paperStatus);
if (invalidRecords.length > 0) {
message.warning(`部分试卷已经处于${newStatus}状态,请重新选择`);
return;
}
Modal.confirm({
title: `确认${newStatus}`,
content: `你确定要${newStatus}这些选中的试卷吗?`,
title: `确认${newStatusText}`,
content: `你确定要${newStatusText}这些选中的试卷吗?`,
onOk: () => {
batchUpdatePaperStatus(selectedRecords)
upPaperStatus(selectedRowKeys, newStatus)
.then((res) => {
const isSuccess = res.data;
if (isSuccess) {
message.success(`${newStatus}成功`);
const status = paperStatus === 0? 1 : 0;
const success = res['success'];
if (success) {
message.success(`${newStatusText}成功`);
this.setState((prevState) => ({
list: prevState.list.map((item) =>
selectedRowKeys.includes(item.id)
? { ...item, paperStatus: status } : item
? { ...item, paperStatus: newStatus } : item
)
}));
} else {
message.error(`${newStatus}失败,请稍后重试`);
message.error(`${newStatusText}失败,请稍后重试`);
}
})
.catch(() => {
message.error(`${newStatus}时发生错误,请检查`);
message.error(`${newStatusText}时发生错误,请检查`);
});
},
onCancel: () => {
@ -215,41 +205,88 @@ class ExamPaperList extends Component<any, States> {
};
render() {
const onFinish = (values: object) => {
const _listQuery = { ...this.state.listQuery, ...values };
this.setState({ listQuery: _listQuery });
this.getList();
};
const {
industryDict,
selectedRowKeys,
list,
loading,
page,
num
} = this.state;
const { industryDict, selectedRowKeys } = this.state;
const changePage = (current: number, pageSize: number) => {
setTimeout(() => {
this.setState({ page: current, num: pageSize });
this.handlegetList();
}, 0);
};
const columns: any = [
{ title: '序号', dataIndex: 'index', key: 'index', align: 'center', width: 60,
{
title: '序号',
dataIndex: 'index',
key: 'index',
align: 'center',
width: 60,
render: (_: number, __: number, index: number) => {
const { page, num } = this.state;
return (page - 1) * num + index + 1;
}
},
{ title: '试卷名称', dataIndex: 'paperName', key: 'paperName', align: 'center', width: 300 },
{ title: '监管行业', dataIndex: 'industryId', key: 'industryId', align: 'center', width: 150,
render: (industryId:any) => {
const industry = industryDict?.find((item: { industryId: string | number; industryName: string }) => String(item.industryId) === String(industryId));
{
title: '试卷名称',
dataIndex: 'paperName',
key: 'paperName',
align: 'center',
width: 300
},
{
title: '监管行业',
dataIndex: 'industryId',
key: 'industryId',
align: 'center',
width: 150,
render: (industryId: any) => {
const industry = industryDict?.find((item: any) => item.industryId === String(industryId));
return industry? industry.industryName : industryId;
}
},
{ title: '题目数量', dataIndex: 'questionCount', key: 'questionCount', align: 'center', width: 120 },
{ title: '总分值', dataIndex: 'totalScore', key: 'totalScore', align: 'center', width: 90 },
{ title: '考试时长', dataIndex: 'examDuration', key: 'examDuration', align: 'center', width: 120 },
{ title: '状态', dataIndex: 'paperStatus', key: 'paperStatus', align: 'center', width: 60,
render: (paperStatus:any) => {
if (paperStatus === 0) {
return '停用';
} else if (paperStatus === 1) {
return '启用';
{
title: '题目数量',
dataIndex: 'questionCount',
key: 'questionCount',
align: 'center',
width: 120
},
{
title: '总分值',
dataIndex: 'totalScore',
key: 'totalScore',
align: 'center',
width: 90
},
{
title: '考试时长',
dataIndex: 'examDuration',
key: 'examDuration',
align: 'center',
width: 120
},
{
title: '状态',
dataIndex: 'paperStatus',
key: 'paperStatus',
align: 'center',
width: 60,
render: (paperStatus: any) => {
return paperStatus === 0? '停用' : '启用';
}
return paperStatus;}
},
{ title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 200,
{
title: '操作',
key: 'operation',
align: 'center',
fixed: 'right',
width: 200,
render: (record: any) => [
<span className='mr10 link' onClick={() => {
sessionStorage.setItem('id', String(record.id));
@ -261,48 +298,31 @@ class ExamPaperList extends Component<any, States> {
this.props.history.push(`/examPaperView`);
}}></span>,
<span className='mr10 link' onClick={() => {
this.updatePaperStatus(record.id, record.paperStatus); // 调用更新状态的方法
}}>{record.paperStatus === 0? '启用' : '停用'}</span>, // 根
this.handleUpdatePaperStatus(record.id, record.paperStatus);
}}>{record.paperStatus === 0? '启用' : '停用'}</span>,
<span className="mr10 link" onClick={() => {
this.deleteSingle(record.id);
this.handleDeleteExamPaper(record.id);
}}></span>
]
},
];
// 分页切换
const changePage = (current: number, pageSize?: number) => {
setTimeout(() => {
this.setState({page: current, num: pageSize || 20});
this.getList();
}, 0);
};
// 多少每页
const selectChange = (page: number, num: number) => {
this.setState({ page, num });
this.getList();
};
const { list, loading } = this.state;
return (
<div className="container">
<div className="list-filter">
<Form
ref={this.formRef}
className="filter"
layout="inline"
name="basic"
onFinish={onFinish}
>
<Form.Item
label="监管行业:"
name="industryId"
>
<Select placeholder="请选择监管行业"
<Select
placeholder="请选择监管行业"
style={{ width: 240 }}
allowClear>
allowClear
>
{
industryDict && industryDict.length > 0?
(() => {
@ -324,36 +344,33 @@ class ExamPaperList extends Component<any, States> {
label="试卷名称:"
name="paperName"
>
<Input placeholder="请输入试卷名称" style={{ width: 240 }}/>
<Input placeholder="请输入试卷名称" style={{ width: 240 }} />
</Form.Item>
<Form.Item>
<Button type="default" onClick={this.handleReset}></Button>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit"></Button>
<Button type="primary" htmlType="submit" onClick={() => {
this.handlegetList();
}}></Button>
</Form.Item>
</Form>
</div>
<Form
className="filter"
layout="inline"
name="basic"
onFinish={onFinish}
style={{ display: 'flex', justifyContent: 'flex-end' }}
style={{ justifyContent: 'flex-end' }}
>
<Form.Item>
<Button type="default" onClick={this.deleteMultiple}></Button>
<Button type="default" onClick={this.handleBatchDeleteExamPaper}></Button>
</Form.Item>
<Form.Item>
<Button type="default" onClick={() => this.batchUpdatePaperStatus(1)}></Button>
<Button type="default" onClick={() => this.handleBatchUpdatePaperStatus(1)}></Button>
</Form.Item>
<Form.Item>
<Button type="default" onClick={() => this.batchUpdatePaperStatus(0)}></Button>
<Button type="default" onClick={() => this.handleBatchUpdatePaperStatus(0)}></Button>
</Form.Item>
<Form.Item>
<Button type="primary" onClick={() => {
this.props.history.push(`/examPaperAdd`);
}}></Button>
<Button type="primary" onClick={() => { this.props.history.push(`/examPaperAdd`); }}></Button>
</Form.Item>
</Form>
<Table
@ -363,7 +380,7 @@ class ExamPaperList extends Component<any, States> {
loading={loading}
rowSelection={{
selectedRowKeys: selectedRowKeys,
onChange: this.onChange,
onChange: this.handleOnChange,
getCheckboxProps: () => ({
disabled: false
})
@ -374,7 +391,6 @@ class ExamPaperList extends Component<any, States> {
showQuickJumper: true,
showSizeChanger: true,
showTotal: (total) => `${total}`,
onShowSizeChange: selectChange,
onChange: changePage
}}
/>
@ -382,5 +398,4 @@ class ExamPaperList extends Component<any, States> {
);
}
}
export default ExamPaperList;

@ -1,68 +1,64 @@
import React, { Component } from 'react';
import { Form, Input, Button, Radio, Checkbox, Select, message} from 'antd';
import { getDetail} from 'api/examPaper';
import { findIndustry} from 'api/question';
const { Option } = Select;
import { Form, Button, Radio, Checkbox, message } from 'antd';
import { getExamPaperDetail } from 'api/examPaper';
import { findIndustry } from 'api/question';
interface optionsState {
value: string;
label: string;
}
// 定义单个试题的状态接口
interface QuestionState {
id: string;
serviceTypeId: string;
questionTypes: string;
id: number;
serviceTypeId: number;
questionTypes: number;
questionContent: string;
answerOptions: optionsState[];
answer: string | null;
answer: string;
}
// 定义组件的状态接口
interface States {
id: string | undefined;
industryDict: any;
paperName : string | undefined;
industryId : number | undefined;
questionCount : number | undefined;
totalScore : number | undefined;
examDuration : string | undefined;
durationType : number | undefined;
paperContent : string | undefined;
id: string;
paperName: string;
industryId: number | undefined;
questionCount: number | undefined;
totalScore: number | undefined;
examDuration: string;
durationType: number | undefined;
paperContent: string;
questions: QuestionState[];
industryDict: any;
}
class ExamPaperView extends Component<any, States> {
formRef: any;
constructor(props: any) {
super(props);
this.formRef = React.createRef();
this.state = {
id: undefined,
industryDict: undefined,
paperName: undefined,
id: '',
paperName: '',
industryId: undefined,
questionCount: undefined,
totalScore: undefined,
examDuration: undefined,
examDuration: '',
durationType: undefined,
paperContent: undefined,
paperContent: '',
questions: [],
industryDict: undefined
};
}
// 初期
componentDidMount() {
this.handleFindIndustry();
const id = sessionStorage.getItem('id');
sessionStorage.removeItem('id');
this.findIndustry();
this.getDetail(id);
this.handleGetDetail(id);
}
// 监管行业
findIndustry() {
handleFindIndustry() {
findIndustry().then((res: any) => {
if (res.data) {
this.setState({ industryDict: res.data });
@ -71,8 +67,8 @@ class ExamPaperView extends Component<any, States> {
}
// 试卷详情
getDetail = (id: string | null) => {
getDetail(id).then((res: any) => {
handleGetDetail = (id: string | null) => {
getExamPaperDetail(id).then((res: any) => {
if (res.data) {
const newQuestions: QuestionState[] = res.data.data.map((questionData: any) => {
const options = questionData.options.split(',');
@ -81,54 +77,30 @@ class ExamPaperView extends Component<any, States> {
return { value, label };
});
return {
id: String(questionData.id),
serviceTypeId: String(questionData.serviceTypeId),
questionTypes: String(questionData.questionTypes),
id: questionData.id,
serviceTypeId: questionData.serviceTypeId,
questionTypes: questionData.questionTypes,
questionContent: String(questionData.questionContent),
answerOptions: answerOptions,
answer: String(questionData.answer)
};
});
const paperName = res.data.head.paperName;
const industryId = res.data.head.industryId;
const questionCount = res.data.head.questionCount;
const totalScore = res.data.head.totalScore;
const examDuration = res.data.head.examDuration;
const durationType = res.data.head.durationType;
const paperContent = res.data.head.paperContent;
this.setState({
questions: newQuestions,
paperName,
industryId,
questionCount,
totalScore,
examDuration,
durationType,
paperContent,
paperName: res.data.head.paperName,
industryId: res.data.head.industryId,
questionCount: res.data.head.questionCount,
totalScore: res.data.head.totalScore,
examDuration: res.data.head.examDuration,
durationType: res.data.head.durationType,
paperContent: res.data.head.paperContent
});
}
}).catch(() => {
message.error('获取题目详情失败,请重试');
});
};
findDurationTypeName = (durationType:number | undefined) => {
switch (durationType) {
case 1:
return '分(min)';
case 2:
return '时(h)';
default:
return '未知';
}
};
findIndustryName = (industryId:number | undefined) => {
const { industryDict } = this.state;
if (industryDict) {
const industry = industryDict.find((item:any) => item.industryId === String(industryId));
return industry ? industry.industryName : '未知行业';
}
return '未知行业';
};
render() {
const {
questions,
@ -139,11 +111,18 @@ class ExamPaperView extends Component<any, States> {
examDuration,
durationType,
paperContent,
industryDict
} = this.state;
// 页面跳转
const handleListQuestion = () => {
this.props.history.push('/examPaperList');
const handleFindDurationTypeName = (durationType: number | undefined) => {
return durationType === 1? '分(min)' : '时(h)';
};
const handleFindIndustryName = (industryId: number | undefined) => {
const industry = industryDict?.find((item: any) => item.industryId === String(industryId));
return industry? industry.industryName : industryId;
};
return (
<div className="container">
<Form ref={this.formRef}>
@ -153,7 +132,7 @@ class ExamPaperView extends Component<any, States> {
</Form.Item>
<div style={{ display: 'flex', gap: 20 }}>
<Form.Item label="监管行业:">
<span>{this.findIndustryName(industryId)}</span>
<span>{handleFindIndustryName(industryId)}</span>
</Form.Item>
<Form.Item label="题目数量:">
<span>{questionCount}</span>
@ -165,7 +144,7 @@ class ExamPaperView extends Component<any, States> {
<span>{examDuration}</span>
</Form.Item>
<Form.Item label="">
<span>{this.findDurationTypeName(durationType)}</span>
<span>{handleFindDurationTypeName(durationType)}</span>
</Form.Item>
</div>
<Form.Item label="内容描述:">
@ -184,7 +163,7 @@ class ExamPaperView extends Component<any, States> {
>
<span style={{ fontWeight: 'bold' }}>{index + 1}. {question.questionContent}</span>
<Form.Item>
{question.questionTypes === '1'? (
{question.questionTypes === 1? (
<Radio.Group value={question.answer}>
{question.answerOptions.map((option) => (
<Radio value={option.value}>
@ -211,13 +190,12 @@ class ExamPaperView extends Component<any, States> {
bottom: 10,
right: 10,
width: '100%',
backgroundColor: 'white',
zIndex: 1000
}}
>
<Button type="default" htmlType="button" onClick={
handleListQuestion
}>
<Button type="default" htmlType="button" onClick={() => {
this.props.history.push('/examPaperList');
}}>
</Button>
</div>
@ -226,4 +204,5 @@ class ExamPaperView extends Component<any, States> {
);
}
}
export default ExamPaperView;

@ -1,21 +1,23 @@
import React, { Component } from'react';
import { Form, Input, Button, Radio, Checkbox, Select, message } from 'antd';
import React, { Component } from "react";
import { Form, Input, Button, Radio, Checkbox, Select, message } from "antd";
import { dictionary } from "api/dict/index";
import { addQuestion, findIndustry } from 'api/question';
import * as XLSX from 'xlsx';
import { saveAs } from 'file-saver';
import { addQuestion, findIndustry } from "api/question";
import * as XLSX from "xlsx";
import { saveAs } from "file-saver";
const { Option} = Select;
const { Option } = Select;
interface States {
industryDict: any;
serviceTypeDict: any;
formCount: number;
formIds: string[];
questionTypesMap: { [formId: string]: string };
}
class QuestionAdd extends Component<any, States> {
formRef: any;
fileInputRef: any;
constructor(props: any) {
super(props);
this.formRef = React.createRef();
@ -23,12 +25,20 @@ class QuestionAdd extends Component<any, States> {
this.state = {
industryDict: [],
serviceTypeDict: [],
formCount: 1
formIds: ["form_0"],
questionTypesMap: { "form_0": "1" }
};
const formValues = {};
formValues[`questionTypes_form_0`] = '1';
this.componentDidMount = () => {
this.formRef.current?.setFieldsValue(formValues);
this.handleFindDict();
};
}
componentDidMount() {
this.handleFindDict();
}
// 字典
@ -41,83 +51,142 @@ class QuestionAdd extends Component<any, States> {
}
})
.catch(() => {
message.error('获取监管行业字典数据失败,请稍后重试');
message.error("获取监管行业字典数据失败,请稍后重试");
});
// AQ服务类型
dictionary('serviceTypeDict')
dictionary("serviceTypeDict")
.then((res) => {
if (res.data) {
this.setState({ serviceTypeDict: res.data });
}
})
.catch(() => {
message.error('获取AQ服务类型字典数据失败,请稍后重试');
message.error("获取AQ服务类型字典数据失败,请稍后重试");
});
}
// 题型切换
handleQuestionTypeChange = (index: number, value: string) => {
handleQuestionTypeChange = (formId: string, value: string) => {
const { questionTypesMap } = this.state;
const formValues = {};
formValues[`questionTypes_${index}`] = value;
formValues[`answer_${index}`] = '';
formValues[`questionTypes_${formId}`] = value;
this.formRef.current.setFieldsValue(formValues);
this.setState((prevState) => ({
questionTypesMap: {
...prevState.questionTypesMap,
[formId]: value
}
}));
};
// 新增试题
handleAddNewQuestion = () => {
const { formIds } = this.state;
const newId = `form_${formIds.length}`;
const formValues = {
[`questionTypes_${newId}`]: "1"
};
this.formRef.current.setFieldsValue(formValues);
this.setState((prevState) => ({
formCount: prevState.formCount + 1,
formIds: [...prevState.formIds, newId],
questionTypesMap: {
...prevState.questionTypesMap,
[newId]: "1"
}
}));
};
// 删除试题
handleDeleteQuestion = (index: number) => {
handleDeleteQuestion = (formId: string) => {
const formValues = {};
const fields = [
"questionTypes",
"industryId",
"serviceTypeId",
"questionContent",
"optionA",
"optionB",
"optionC",
"optionD",
"answer"
];
fields.forEach((field) => {
formValues[`${field}_${formId}`] = undefined;
});
this.formRef.current.setFieldsValue(formValues);
const { questionTypesMap } = this.state;
const newQuestionTypesMap = { ...questionTypesMap };
delete newQuestionTypesMap[formId];
this.setState((prevState) => ({
formCount: prevState.formCount - 1,
formIds: prevState.formIds.filter((id) => id!== formId),
questionTypesMap: newQuestionTypesMap
}));
};
// 处理表单提交
// 表单提交
handleSubmit = () => {
this.formRef.current.validateFields().then((values: any) => {
const questions = [];
for (let i = 0; i < this.state.formCount; i++) {
const question = {
questionTypes: values[`questionTypes_${i}`],
industryId: values[`industryId_${i}`],
serviceTypeId: values[`serviceTypeId_${i}`],
questionContent: values[`questionContent_${i}`],
optionA: values[`optionA_${i}`],
optionB: values[`optionB_${i}`],
optionC: values[`optionC_${i}`],
optionD: values[`optionD_${i}`],
answer: values[`answer_${i}`],
};
questions.push(question);
const questions: any = [];
const { formIds } = this.state;
formIds.forEach((formId) => {
let answer = values[`answer_${formId}`];
if (Array.isArray(answer)) {
answer.sort();
answer = answer.join(",");
}
questions.push({
questionTypes: values[`questionTypes_${formId}`],
industryId: values[`industryId_${formId}`],
serviceTypeId: values[`serviceTypeId_${formId}`],
questionContent: values[`questionContent_${formId}`],
optionA: values[`optionA_${formId}`],
optionB: values[`optionB_${formId}`],
optionC: values[`optionC_${formId}`],
optionD: values[`optionD_${formId}`],
answer: answer
});
});
addQuestion(questions).then((res) => {
const success = res['success'];
const success = res["success"];
if (success) {
message.success(`新增成功`);
this.props.history.push('/questionList');
this.props.history.push("/questionList");
} else {
message.error('新增试题失败,请稍后重试');
message.error("新增试题失败,请稍后重试");
}
}).catch(() => {
message.error('新增试题时发生错误,请检查');
message.error("新增试题时发生错误,请检查");
});
});
};
// 下载模板
handleDownloadTemplate = () => {
const headers = ['题型', '监管行业', 'AQ服务类型', '题干', '选项A', '选项B', '选项C', '选项D', '答案'];
const headers = [
"题型",
"监管行业",
"AQ服务类型",
"题干",
"选项A",
"选项B",
"选项C",
"选项D",
"答案"
];
const ws = XLSX.utils.aoa_to_sheet([headers]);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, '试题模板');
const wbOut = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
saveAs(new Blob([wbOut], { type: 'application/octet-stream' }), '试题模板.xlsx');
XLSX.utils.book_append_sheet(wb, ws, "试题模板");
const wbOut = XLSX.write(wb, { bookType: "xlsx", type: "array" });
saveAs(new Blob([wbOut], { type: "application/octet-stream" }), "试题模板.xlsx");
};
// 一键导入
@ -127,24 +196,31 @@ class QuestionAdd extends Component<any, States> {
const reader = new FileReader();
reader.onload = (event) => {
const data = new Uint8Array(event.target?.result as ArrayBuffer);
const workbook = XLSX.read(data, { type: 'array' });
const workbook = XLSX.read(data, { type: "array" });
const firstSheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[firstSheetName];
const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
const rows = jsonData.slice(1);
const formValues = {};
const formIds: string[] = [];
const questionTypesMap = {};
rows.forEach((row: any, index) => {
formValues[`questionTypes_${index}`] = String(row[0]);
formValues[`industryId_${index}`] = String(row[1]);
formValues[`serviceTypeId_${index}`] = String(row[2]);
formValues[`questionContent_${index}`] = String(row[3]);
formValues[`optionA_${index}`] = String(row[4]);
formValues[`optionB_${index}`] = String(row[5]);
formValues[`optionC_${index}`] = String(row[6]);
formValues[`optionD_${index}`] = String(row[7]);
formValues[`answer_${index}`] = String(row[8]);
const formId = `form_${index}`;
formIds.push(formId);
formValues[`questionTypes_${formId}`] = String(row[0]);
formValues[`industryId_${formId}`] = String(row[1]);
formValues[`serviceTypeId_${formId}`] = String(row[2]);
formValues[`questionContent_${formId}`] = String(row[3]);
formValues[`optionA_${formId}`] = String(row[4]);
formValues[`optionB_${formId}`] = String(row[5]);
formValues[`optionC_${formId}`] = String(row[6]);
formValues[`optionD_${formId}`] = String(row[7]);
formValues[`answer_${formId}`] = String(row[8]);
questionTypesMap[formId] = String(row[0]);
});
this.setState({ formCount: rows.length }, () => {
this.setState({ formIds, questionTypesMap }, () => {
this.formRef.current.setFieldsValue(formValues);
});
};
@ -157,50 +233,56 @@ class QuestionAdd extends Component<any, States> {
}
};
// 文件
handleImportClick = () => {
this.fileInputRef.current?.click();
};
render() {
const { industryDict, serviceTypeDict, formCount } = this.state;
const { industryDict, serviceTypeDict, formIds, questionTypesMap } = this.state;
const handleListQuestion = () => {
this.props.history.push('/questionList');
this.props.history.push("/questionList");
};
return (
<div className="container">
<div style={{textAlign: 'right'}}>
<Button type="default" style={{marginRight: 10}} onClick={this.handleDownloadTemplate}></Button>
<Button type="default" onClick={this.handleImportClick}></Button>
<div style={{ textAlign: "right" }}>
<Button type="default" style={{ marginRight: 10 }} onClick={this.handleDownloadTemplate}>
</Button>
<Button type="default" onClick={this.handleImportClick}>
</Button>
<input
type="file"
ref={this.fileInputRef}
style={{display: 'none'}}
style={{ display: "none" }}
accept=".xlsx,.xls"
onChange={this.handleFileChange}
/>
</div>
<Form ref={this.formRef} layout="inline">
{Array.from({ length: formCount }, (_, index) => (
<div key={index} style={{marginBottom: 30}}>
<div style={{display: 'flex'}}>
<Form.Item name={`questionTypes_${index}`}>
{formIds.map((formId, index) => (
<div key={formId} style={{ marginBottom: 30 }}>
<div style={{ display: "flex" }}>
<Form.Item name={`questionTypes_${formId}`}>
<Radio.Group
onChange={(e) => this.handleQuestionTypeChange(index, e.target.value)}>
onChange={(e) => this.handleQuestionTypeChange(formId, e.target.value)}
>
<Radio.Button value="1"></Radio.Button>
<Radio.Button value="2"></Radio.Button>
</Radio.Group>
</Form.Item>
<Form.Item
label="监管行业:"
name={`industryId_${index}`}
rules={[{required: true, message: '请选择监管行业'}]}
name={`industryId_${formId}`}
rules={[{ required: true, message: "请选择监管行业" }]}
>
<Select placeholder="请选择监管行业"
style={{width: 240}}
allowClear>
{
industryDict && industryDict.length > 0 ?
<Select
placeholder="请选择监管行业"
style={{ width: 240 }}
allowClear
>
{industryDict && industryDict.length > 0? (
(() => {
let rows = [];
for (let i = 0; i < industryDict.length; i++) {
@ -211,103 +293,123 @@ class QuestionAdd extends Component<any, States> {
}
return rows;
})()
:
) : (
<Option disabled></Option>
}
)}
</Select>
</Form.Item>
<Form.Item
label="AQ服务类型:"
name={`serviceTypeId_${index}`}
rules={[{required: true, message: '请选择AQ服务类型'}]}
name={`serviceTypeId_${formId}`}
rules={[{ required: true, message: "请选择AQ服务类型" }]}
>
<Select
placeholder="请选择AQ服务类型"
style={{ width: 240 }}
allowClear
>
<Select placeholder="请选择AQ服务类型"
style={{width: 240}}
allowClear>
{
serviceTypeDict && serviceTypeDict.length > 0 ?
{serviceTypeDict && serviceTypeDict.length > 0? (
(() => {
let rows = [];
for (let i = 0; i < serviceTypeDict.length; i++) {
const item = serviceTypeDict[i];
rows.push(
<Option
value={String(item.dictKey)}>{item.dictValue}</Option>
<Option value={String(item.dictKey)}>{item.dictValue}</Option>
);
}
return rows;
})()
:
) : (
<Option disabled></Option>
}
)}
</Select>
</Form.Item>
<Form.Item>
{index > 0 && (
<Button type="link" onClick={() => this.handleDeleteQuestion(index)}>X</Button>)}
<Button type="link" onClick={() => this.handleDeleteQuestion(formId)}>
X
</Button>
)}
</Form.Item>
</div>
<div style={{display: 'flex'}}>
<div style={{ display: "flex" }}>
<Form.Item
label="题干:"
name={`questionContent_${index}`}
style={{marginTop: 10}}
rules={[{required: true, message: '请输入题干内容'}]}
name={`questionContent_${formId}`}
style={{ marginTop: 10 }}
rules={[{ required: true, message: "请输入题干内容" }]}
>
<Input.TextArea
placeholder="请输入题干内容"
style={{width: 1100, height: 60}}
style={{ width: 1100, height: 60 }}
/>
</Form.Item>
</div>
<div style={{marginTop: 10, marginLeft: 40}}>
<div style={{display: 'flex'}}>
<div style={{ marginTop: 10, marginLeft: 40 }}>
<div style={{ display: "flex" }}>
<Form.Item
name={`answer_${index}`}
rules={[{ required: true, message: '请选择答案' }]}>
{this.formRef.current && this.formRef.current.getFieldValue(`questionTypes_${index}`) === '1' ? (
name={`answer_${formId}`}
rules={[{ required: true, message: "请选择答案" }]}
>
{questionTypesMap[formId] === "1"? (
<Radio.Group>
<div style={{display: 'flex'}}>
<div style={{ display: "flex" }}>
<Radio value="A">A</Radio>
<Form.Item name={`optionA_${index}`} rules={[{required: true, message: '请输入答案A'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionA_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
<Radio value="B">B</Radio>
<Form.Item name={`optionB_${index}`} rules={[{required: true, message: '请输入答案B'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionB_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
</div>
<div style={{display: 'flex', marginTop: 10}}>
<div style={{ display: "flex", marginTop: 10 }}>
<Radio value="C">C</Radio>
<Form.Item name={`optionC_${index}`} rules={[{required: true, message: '请输入答案C'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionC_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
<Radio value="D">D</Radio>
<Form.Item name={`optionD_${index}`} rules={[{required: true, message: '请输入答案D'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionD_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
</div>
</Radio.Group>
) : (
<Checkbox.Group>
<div style={{display: 'flex'}}>
<div style={{ display: "flex" }}>
<Checkbox value="A">A</Checkbox>
<Form.Item name={`optionA_${index}`} rules={[{required: true, message: '请输入答案A'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionA_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
<Checkbox value="B">B</Checkbox>
<Form.Item name={`optionB_${index}`} rules={[{required: true, message: '请输入答案B'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionB_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
</div>
<div style={{display: 'flex', marginTop: 10}}>
<div style={{ display: "flex", marginTop: 10 }}>
<Checkbox value="C">C</Checkbox>
<Form.Item name={`optionC_${index}`} rules={[{required: true, message: '请输入答案C'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionC_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
<Checkbox value="D">D</Checkbox>
<Form.Item name={`optionD_${index}`} rules={[{required: true, message: '请输入答案D'}]}>
<Input placeholder="请输入答案" style={{width: 500}}/>
<Form.Item name={`optionD_${formId}`}
rules={[{ required: true, message: "请输入答案" }]}
>
<Input placeholder="请输入答案" style={{ width: 500 }} />
</Form.Item>
</div>
</Checkbox.Group>
@ -318,20 +420,20 @@ class QuestionAdd extends Component<any, States> {
</div>
))}
</Form>
<div style={{textAlign: 'right'}}>
<div style={{ textAlign: "right" }}>
<Button type="default" onClick={this.handleAddNewQuestion}>
</Button>
</div>
<div style={{
textAlign: 'right',
position: 'fixed',
textAlign: "right",
position: "fixed",
bottom: 10,
right: 10,
width: '100%',
width: "100%",
zIndex: 1000
}}>
<Button type="default" htmlType="button" onClick={handleListQuestion} style={{marginRight: 10}}>
<Button type="default" htmlType="button" onClick={handleListQuestion} style={{ marginRight: 10 }}>
</Button>
<Button type="primary" htmlType="submit" onClick={this.handleSubmit}>

@ -51,7 +51,7 @@ class QuestionEdit extends Component<any, States> {
sessionStorage.removeItem('id');
getQuestionDetail(id).then((res: any) => {
if (res.data) {
//this.setState({ questionTypes: String(res.data.questionTypes) });
this.setState({ questionTypes: String(res.data.questionTypes) });
const formValues = {};
formValues['id'] = res.data.id;
formValues['questionTypes'] = String(res.data.questionTypes);
@ -78,9 +78,6 @@ class QuestionEdit extends Component<any, States> {
questionTypes: value
};
});
const formValues = {};
formValues['answer'] = '';
this.formRef.current.setFieldsValue(formValues);
};
// 保存修改
@ -199,7 +196,7 @@ class QuestionEdit extends Component<any, States> {
<Radio value="A">A</Radio>
<Form.Item
name={`optionA`}
rules={[{ required: true, message: '请输入答案A' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -209,7 +206,7 @@ class QuestionEdit extends Component<any, States> {
<Radio value="B">B</Radio>
<Form.Item
name={`optionB`}
rules={[{ required: true, message: '请输入答案B' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -221,7 +218,7 @@ class QuestionEdit extends Component<any, States> {
<Radio value="C">C</Radio>
<Form.Item
name={`optionC`}
rules={[{ required: true, message: '请输入答案C' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -231,7 +228,7 @@ class QuestionEdit extends Component<any, States> {
<Radio value="D">D</Radio>
<Form.Item
name={`optionD`}
rules={[{ required: true, message: '请输入答案D' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -246,7 +243,7 @@ class QuestionEdit extends Component<any, States> {
<Checkbox value="A">A</Checkbox>
<Form.Item
name={`optionA`}
rules={[{ required: true, message: '请输入答案A' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -256,7 +253,7 @@ class QuestionEdit extends Component<any, States> {
<Checkbox value="B">B</Checkbox>
<Form.Item
name={`optionB`}
rules={[{ required: true, message: '请输入答案B' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -268,7 +265,7 @@ class QuestionEdit extends Component<any, States> {
<Checkbox value="C">C</Checkbox>
<Form.Item
name={`optionC`}
rules={[{ required: true, message: '请输入答案C' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"
@ -278,7 +275,7 @@ class QuestionEdit extends Component<any, States> {
<Checkbox value="D">D</Checkbox>
<Form.Item
name={`optionD`}
rules={[{ required: true, message: '请输入答案D' }]}
rules={[{ required: true, message: '请输入答案' }]}
>
<Input
placeholder="请输入答案"

@ -35,12 +35,17 @@ class QuestionList extends Component<any, States> {
}
componentDidMount() {
this.findDict();
this.handleFindDict();
const savedFormValues = sessionStorage.getItem('questionListFormValues');
if (savedFormValues) {
const values = JSON.parse(savedFormValues);
this.formRef.current.setFieldsValue(values);
}
this.handlegetList();
}
// 字典
findDict() {
handleFindDict() {
// 监管行业
findIndustry()
.then((res: any) => {
@ -75,7 +80,7 @@ class QuestionList extends Component<any, States> {
num,
page
};
sessionStorage.setItem('questionListFormValues', JSON.stringify(values));
getList(data)
.then((res) => {
this.setState({
@ -94,6 +99,7 @@ class QuestionList extends Component<any, States> {
// 重置
handleReset = () => {
sessionStorage.removeItem('questionListFormValues');
this.formRef.current.resetFields();
};
@ -156,20 +162,13 @@ class QuestionList extends Component<any, States> {
};
// 行选择
onChange = (selectedRowKeys: React.Key[]) => {
handleOnChange = (selectedRowKeys: React.Key[]) => {
this.setState({
selectedRowKeys: selectedRowKeys as number[],
});
};
render() {
const changePage = (current: number, pageSize: number) => {
setTimeout(() => {
this.setState({ page: current, num: pageSize });
this.handlegetList();
}, 0);
};
const {
industryDict,
serviceTypeDict,
@ -180,6 +179,13 @@ class QuestionList extends Component<any, States> {
num
} = this.state;
const changePage = (current: number, pageSize: number) => {
setTimeout(() => {
this.setState({ page: current, num: pageSize });
this.handlegetList();
}, 0);
};
const columns: any = [
{
title: '序号',
@ -288,7 +294,6 @@ class QuestionList extends Component<any, States> {
}
</Select>
</Form.Item>
<Form.Item
label="AQ服务类型:"
name="serviceTypeId"
@ -315,7 +320,6 @@ class QuestionList extends Component<any, States> {
}
</Select>
</Form.Item>
<Form.Item
label="题干条件:"
name="questionContent"
@ -325,18 +329,15 @@ class QuestionList extends Component<any, States> {
style={{ width: 240 }}
/>
</Form.Item>
<Form.Item>
<Button type="default" onClick={this.handleReset}></Button>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" onClick={() => {
this.handlegetList();
}}></Button>
</Form.Item>
</Form>
<Form
className="filter"
layout="inline"
@ -345,14 +346,12 @@ class QuestionList extends Component<any, States> {
<Form.Item>
<Button type="default" onClick={this.handleBatchDeleteQuestions}></Button>
</Form.Item>
<Form.Item>
<Button type="primary" onClick={() => {
this.props.history.push('/questionAdd');
}}></Button>
</Form.Item>
</Form>
<Table
dataSource={list}
columns={columns}
@ -360,7 +359,7 @@ class QuestionList extends Component<any, States> {
loading={loading}
rowSelection={{
selectedRowKeys: selectedRowKeys,
onChange: this.onChange,
onChange: this.handleOnChange,
getCheckboxProps: () => ({
disabled: false
})

Loading…
Cancel
Save