From 7ac4da701e184337c598564808704184fc219daf Mon Sep 17 00:00:00 2001 From: hujunpeng Date: Thu, 6 Mar 2025 18:02:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=AE=A1=E7=90=86=E5=92=8C?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=AE=A1=E7=90=86=E4=BB=A3=E7=A0=81=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/examPaper/examPaperAdd.tsx | 223 ++++++++++++++++++ .../src/views/examPaper/examPaperList.tsx | 38 ++- 2 files changed, 238 insertions(+), 23 deletions(-) create mode 100644 packages/examination/src/views/examPaper/examPaperAdd.tsx diff --git a/packages/examination/src/views/examPaper/examPaperAdd.tsx b/packages/examination/src/views/examPaper/examPaperAdd.tsx new file mode 100644 index 0000000..7e344bc --- /dev/null +++ b/packages/examination/src/views/examPaper/examPaperAdd.tsx @@ -0,0 +1,223 @@ +import React, { Component } from'react'; +import { Form, Input, Button, Radio, Checkbox, Select, message } from 'antd'; +import { findIndustry, getRandomQuestions } from 'api/examPaper'; + +const { Option } = Select; + +interface optionsState { + value: string; + label: string; +} + +// 定义单个试题的状态接口 +interface QuestionState { + id: string; + questionTypes: string; + questionContent: string; + answerOptions: optionsState[]; + answer: string | null; +} + +// 定义组件的状态接口 +interface States { + industryDict: any; + isLoading: boolean; + questions: QuestionState[]; +} + +class ExamPaperAdd extends Component { + formRef: any; + + constructor(props: any) { + super(props); + this.formRef = React.createRef(); + this.state = { + industryDict: undefined, + isLoading: false, + questions: [] + }; + } + + // 初期 + componentDidMount() { + this.findIndustry(); + } + + // 监管行业 + findIndustry() { + findIndustry().then((res: any) => { + if (res.data) { + this.setState({ industryDict: res.data }); + } + }); + } + + // 随机生成题目 + handleRandomGenerate = () => { + this.formRef.current.validateFields(['industryId', 'questionCount']) + .then((values:any) => { + const industryId = values.industryId; + const questionCount = values.questionCount; + // 随机获取试题 + getRandomQuestions(industryId, questionCount) + .then((res: any) => { + if (res.data) { + if(res.data.length == 0){ + message.warning('题库没题了'); + this.setState({ questions: [] }); + return; + } + const newQuestions: QuestionState[] = res.data.map((questionData: any) => { + const options = questionData.options.split(','); + const answerOptions = options.map((option: any) => { + const [value, label] = option.split(':'); + return { value, label };}); + return { + id: String(questionData.id), + questionTypes: String(questionData.questionTypes), + questionContent: String(questionData.questionContent), + answerOptions: answerOptions, + answer: String(questionData.answer) + }; + }); + this.setState({ questions: newQuestions }); + message.success('成功获取题目'); + } else { + message.error('未获取到随机题目'); + } + }).catch(() => { + message.error('获取随机题目失败'); + }); + }).catch(() => {}); + }; + + render() { + const { industryDict, questions, isLoading } = this.state; + const handleListQuestion = () => { + this.props.history.push('/examPaperList'); + }; + return ( +
+
+

基本信息

+ + + +
+ + + + + + + + + + + + +
+ + + +
+

试题详情

+
+ + +
+
+ {questions.map((question, index) => ( +
+ {index + 1}. {question.questionContent} + + {question.questionTypes === '1' ? ( + + {question.answerOptions.map((option) => ( + + {option.value}. {option.label} + + ))} + + ) : ( + + {question.answerOptions.map((option) => ( + + {option.value}. {option.label} + + ))} + + )} + +
+ ))} +
+ + +
+
+
+ ); + } +} + +export default ExamPaperAdd; \ No newline at end of file diff --git a/packages/examination/src/views/examPaper/examPaperList.tsx b/packages/examination/src/views/examPaper/examPaperList.tsx index 18d1571..8034004 100644 --- a/packages/examination/src/views/examPaper/examPaperList.tsx +++ b/packages/examination/src/views/examPaper/examPaperList.tsx @@ -184,29 +184,21 @@ class ExamPaperList extends Component { // 更新试卷状态 updatePaperStatus = (id: number, paperStatus: number) => { const newStatus = paperStatus === 0? '启用' : '停用'; - Modal.confirm({ - title: `确认${newStatus}`, - content: `你确定要${newStatus}这张试卷吗?`, - onOk: () => { - updatePaperStatus(id, paperStatus).then((res) => { - const isSuccess = res.data; - if (isSuccess) { - message.success(`${newStatus}成功`); - const status = paperStatus === 0? 1 : 0; - this.setState((prevState) => ({ - list: prevState.list.map((item) => - item.id === id? { ...item, paperStatus: status } : item - ) - })); - } else { - message.error(`${newStatus}失败,请稍后重试`); - } - }).catch(() => { - message.error(`${newStatus}时发生错误,请检查`); - }); - }, - onCancel: () => { - }, + updatePaperStatus(id, paperStatus).then((res) => { + const isSuccess = res.data; + if (isSuccess) { + message.success(`${newStatus}成功`); + const status = paperStatus === 0? 1 : 0; + this.setState((prevState) => ({ + list: prevState.list.map((item) => + item.id === id? { ...item, paperStatus: status } : item + ) + })); + } else { + message.error(`${newStatus}失败,请稍后重试`); + } + }).catch(() => { + message.error(`${newStatus}时发生错误,请检查`); }); };