From daf10d71339351c52997197f65a0dc83fc2ed8c7 Mon Sep 17 00:00:00 2001 From: hujunpeng Date: Wed, 5 Mar 2025 14:56:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=AE=A1=E7=90=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../examination/src/api/question/index.tsx | 82 +++ .../src/components/contentMain/index.js | 10 + .../src/views/question/questionAdd.tsx | 505 ++++++++++++++++++ .../src/views/question/questionList.tsx | 393 ++++++++++++++ .../src/views/question/questionUp.tsx | 403 ++++++++++++++ .../examination/src/views/slider/menu.tsx | 22 + 6 files changed, 1415 insertions(+) create mode 100644 packages/examination/src/api/question/index.tsx create mode 100644 packages/examination/src/views/question/questionAdd.tsx create mode 100644 packages/examination/src/views/question/questionList.tsx create mode 100644 packages/examination/src/views/question/questionUp.tsx diff --git a/packages/examination/src/api/question/index.tsx b/packages/examination/src/api/question/index.tsx new file mode 100644 index 0000000..39bff3a --- /dev/null +++ b/packages/examination/src/api/question/index.tsx @@ -0,0 +1,82 @@ +import axios from '../axios'; + +/* +* 查询 +*/ +export function getList(num: number, page: number, obj:object){ + const rData = { + num:num, + page:page, + industryId:obj['industryId'], + serviceTypeId:obj['serviceTypeId'], + questionContent:obj['questionContent'] + }; + return axios({ + url: "/ex/question/list", + method: 'post', + data: rData + }) +} + +/* +* 删除(明细) +*/ +export function deleteQuestion(id: number) { + return axios({ + url: '/ex/question/delete?id=' + id, + method: 'get' + }); +} + +/* +* 删除 +*/ +export function deleteQuestionList(ids: any) { + return axios({ + url: '/ex/question/deleteList', + method: 'post', + data: ids + }); +} + +/* +* 新增题目 +*/ +export function add(questionData: object) { + return axios({ + url: "/ex/question/add", + method: 'post', + data: questionData + }); +} + +/* +* 修改题目 +*/ +export function update(questionData: object) { + return axios({ + url: "/ex/question/update", + method: 'post', + data: questionData + }); +} + +/* +* 行业 +*/ +export function findIndustry() { + return axios({ + url: '/ex/question/findIndustry', + method: 'get' + }) +} + +/* +* 题目详情 +*/ +export function getDetail(id: string|null) { + return axios({ + url: '/ex/question/getDetail?id=' + id, + method: 'get' + }); +} diff --git a/packages/examination/src/components/contentMain/index.js b/packages/examination/src/components/contentMain/index.js index ec1481c..ab9b87a 100644 --- a/packages/examination/src/components/contentMain/index.js +++ b/packages/examination/src/components/contentMain/index.js @@ -28,6 +28,12 @@ import Customer from 'views/statistical/list'; import CustomerDetail from 'views/statistical/detail'; import ExamDetail from "../../views/exam-online/exam-detail"; +import QuestionList from 'views/question/questionList'; +import QuestionAdd from 'views/question/questionAdd'; +import QuestionUp from 'views/question/questionUp'; +import ExamPaperList from 'views/examPaper/examPaperList'; + + class ContentMain extends Component { render() { return ( @@ -48,6 +54,10 @@ class ContentMain extends Component { + + + + diff --git a/packages/examination/src/views/question/questionAdd.tsx b/packages/examination/src/views/question/questionAdd.tsx new file mode 100644 index 0000000..c7794ce --- /dev/null +++ b/packages/examination/src/views/question/questionAdd.tsx @@ -0,0 +1,505 @@ +import React, { Component } from'react'; +import { Form, Input, Button, Radio, Checkbox, Select, message } from 'antd'; +import { dictionary } from "api/dict/index"; +import { add, findIndustry } from 'api/question'; +import * as XLSX from 'xlsx'; +import { saveAs } from 'file-saver'; + +const { Option } = Select; + +// 定义单个试题的状态接口 +interface QuestionState { + questionTypes: string; + industryId: string | null; + serviceTypeId: string | null; + questionContent: string; + answerOptions: { [key: string]: string }; + answer: string | null; +} + +// 定义组件的状态接口 +interface States { + industryDict: any; + serviceTypeDict: any; + isLoading: boolean; + questions: QuestionState[]; +} + +class QuestionAdd extends Component { + formRef: any; + fileInputRef: any; + + constructor(props: any) { + super(props); + this.formRef = React.createRef(); + this.fileInputRef = React.createRef(); + this.state = { + industryDict: undefined, + serviceTypeDict: undefined, + isLoading: false, + questions: [ + { + questionTypes: '1', + questionContent: '', + answerOptions: { A: '', B: '', C: '', D: ''}, + answer: null, + industryId: null, + serviceTypeId: null + } + ] + }; + } + + // 初期 + componentDidMount() { + this.getDict(); + this.findIndustry(); + } + + // 字典 + getDict() { + // 服务类型 + dictionary('serviceTypeDict').then((res) => { + if (res.data) { + this.setState({ serviceTypeDict: res.data }); + } + }); + } + + // 行业 + findIndustry() { + // 监管行业 + findIndustry().then((res) => { + if (res.data) { + this.setState({ industryDict: res.data }); + } + }); + } + + // 题型 + handleQuestionTypeChange = (index: number, value: string) => { + this.setState((prevState) => { + const questions = [...prevState.questions]; + questions[index].questionTypes = value; + questions[index].answer = null; + return { + questions + }; + }); + }; + + // 单选框 + handleRadioChange = (index: number, value: string) => { + this.setState((prevState) => { + const questions = [...prevState.questions]; + questions[index].answer = value; + return { + questions + }; + }); + }; + + // 多选框 + handleCheckboxChange = (index: number, type: string, values: (string | number | boolean)[] | null) => { + this.setState((prevState) => { + const questions = [...prevState.questions]; + const currentAnswer = questions[index].answer || ''; + const currentSelectedArray = currentAnswer? currentAnswer.split(',') : []; + if (!values || values.length === 0) { + const newSelectedArray = currentSelectedArray.filter(val => val!== type); + newSelectedArray.sort(); + questions[index].answer = newSelectedArray.join(','); + } else { + const stringValues = values.map((val) => String(val)); + const newSelectedArray = Array.from(new Set([...currentSelectedArray, ...stringValues])); + newSelectedArray.sort(); + questions[index].answer = newSelectedArray.join(','); + } + return { + questions + }; + }); + }; + + // 答案 + handleAnswerOptionChange = (index: number, option: string, value: string) => { + this.setState((prevState) => { + const questions = [...prevState.questions]; + questions[index].answerOptions[option] = value; + return { + questions + }; + }); + }; + + // 新增试题 + addNewQuestion = () => { + this.setState((prevState) => ({ + questions: [ + ...prevState.questions, + { + questionTypes: '1', + questionContent: '', + answerOptions: { A: '', B: '', C: '', D: ''}, + answerDisabled: false, + answer: null, + industryId: null, + serviceTypeId: null + } + ] + })); + }; + + // 删除试题 + deleteQuestion = (index: number) => { + this.setState((prevState) => { + const questions = [...prevState.questions]; + questions.splice(index, 1); + return { + questions + }; + }); + }; + + // 处理表单提交 + handleSubmit = () => { + this.setState({ isLoading: true }); + this.formRef.current.validateFields().then((values: Record) => { + const questions = this.state.questions.map((question, index) => { + const industryId = values[`industryId_${index}`]; + const serviceTypeId = values[`serviceTypeId_${index}`]; + const questionContent = values[`questionContent_${index}`]; + return { + ...question, + industryId, + serviceTypeId, + questionContent + }; + }); + + add(questions).then((res) => { + const count = res.data; + if (count>0) { + message.success(`成功新增 ${count} 条试题`); + this.setState({ isLoading: false }); + this.props.history.push('/questionList'); + } else { + message.error('新增试题失败,请稍后重试'); + this.setState({ isLoading: false }); + } + }).catch(() => { + message.error('新增试题时发生错误,请检查'); + this.setState({ isLoading: false }); + }); + }).catch(() => { + this.setState({ isLoading: false }); + }); + }; + + // 下载模板 + downloadTemplate = () => { + 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'); + }; + + // 一键导入 + handleFileChange = (e: React.ChangeEvent) => { + const file = e.target.files?.[0]; + if (file) { + const reader = new FileReader(); + reader.onload = (event) => { + const data = new Uint8Array(event.target?.result as ArrayBuffer); + 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 newQuestions = rows.map((row: any) => { + const question: QuestionState = { + questionTypes: String(row[0]), + industryId: String(row[1]), + serviceTypeId: String(row[2]).trim().toLowerCase(), + questionContent: String(row[3]), + answerOptions: { + A: String(row[4]), + B: String(row[5]), + C: String(row[6]), + D: String(row[7]) + }, + answer: String(row[8]) + }; + return question; + }); + this.setState({ questions: newQuestions }, () => { + const formValues = {}; + newQuestions.forEach((question, index) => { + formValues[`questionContent_${index}`] = question.questionContent; + formValues[`industryId_${index}`] = question.industryId; + formValues[`serviceTypeId_${index}`] = question.serviceTypeId; + formValues[`answer_${index}`] = question.answer; + formValues[`answerOption_A_${index}`] = question.answerOptions.A; + formValues[`answerOption_B_${index}`] = question.answerOptions.B; + formValues[`answerOption_C_${index}`] = question.answerOptions.C; + formValues[`answerOption_D_${index}`] = question.answerOptions.D; + }); + this.formRef.current.setFieldsValue(formValues); + }); + }; + reader.readAsArrayBuffer(file); + } + }; + + // 文件 + handleImportClick = () => { + this.fileInputRef.current?.click(); + }; + + render() { + const { industryDict, serviceTypeDict, questions, isLoading } = this.state; + // 使用 this.props.history 进行页面跳转 + const handleListQuestion = () => { + this.props.history.push('/questionList'); + }; + return ( +
+
+ + + +
+
+ {questions.map((question, index) => ( +
+
+ + this.handleQuestionTypeChange(index, e.target.value)}> + 单选题 + 多选题 + + + + + + + + + + {index > 0 && ()} + +
+ + + + +
+
+ {question.questionTypes === '1'? ( + this.handleRadioChange(index, e.target.value)} + > + A + this.handleAnswerOptionChange(index, 'A', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange(index,'A', values,)}> + A + this.handleAnswerOptionChange(index, 'A', e.target.value)} + /> + + )} + {question.questionTypes === '1'? ( + this.handleRadioChange(index, e.target.value)} + style={{ marginLeft: 20 }} + > + B + this.handleAnswerOptionChange(index, 'B', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange(index,'B',values)}> + B + this.handleAnswerOptionChange(index, 'B', e.target.value)} + /> + + )} +
+
+ {question.questionTypes === '1'? ( + this.handleRadioChange(index, e.target.value)} + > + C + this.handleAnswerOptionChange(index, 'C', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange(index,'C', values)}> + C + this.handleAnswerOptionChange(index, 'C', e.target.value)} + /> + + )} + {question.questionTypes === '1'? ( + this.handleRadioChange(index, e.target.value)} + style={{ marginLeft: 20 }} + > + D + this.handleAnswerOptionChange(index, 'D', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange(index,'D',values)}> + D + this.handleAnswerOptionChange(index, 'D', e.target.value)} + /> + + )} +
+
+
+
+ ))} +
+
+ +
+
+ + +
+
+ ); + } +} +export default QuestionAdd; \ No newline at end of file diff --git a/packages/examination/src/views/question/questionList.tsx b/packages/examination/src/views/question/questionList.tsx new file mode 100644 index 0000000..c3cca8d --- /dev/null +++ b/packages/examination/src/views/question/questionList.tsx @@ -0,0 +1,393 @@ +import React, { Component } from'react'; +import {Form, Input, Button, Table, Select, message, Modal} from 'antd'; +import { TableRowSelection } from 'antd/lib/table/interface'; +import {deleteQuestion, deleteQuestionList, findIndustry, getList} from 'api/question'; +import { dictionary } from "api/dict/index"; + +const { Option } = Select; + +interface States { + num: number; + page: number; + listQuery: { + industryId: string | undefined; + serviceTypeId: string | undefined; + questionContent: string | undefined; + }; + list: any[]; + total: number; + loading: boolean; + currentRow: object; + title: string; + modalText: string; + modalWidth: number | string; + industryDict: any; + serviceTypeDict: any; + selectedRowKeys: number[]; + isAllSelected: boolean; +} + +class QuestionList extends Component { + formRef: any; + constructor(props: any) { + super(props); + this.formRef = React.createRef(); + this.state = { + num: 10, + page: 1, + listQuery: { + industryId: undefined, + serviceTypeId: undefined, + questionContent: undefined + }, + list: [], + total: 0, + loading: false, + currentRow: { + id: 0, + status: 0 + }, + title: '', + modalText: '', + modalWidth: 0, + industryDict: undefined, + serviceTypeDict: undefined, + selectedRowKeys: [], + isAllSelected: false, + }; + } + + componentDidMount() { + this.findDict(); + this.findIndustry(); + this.getList(); + } + + // 监管行业 + findIndustry() { + findIndustry().then((res: any) => { + if (res.data) { + this.setState({ industryDict: res.data }); + } + }); + } + + // AQ服务类型 + findDict() { + dictionary('serviceTypeDict').then((res) => { + if (res.data) { + this.setState({ serviceTypeDict: res.data }); + } + }); + } + + // 查询 + getList() { + this.setState({ loading: true }); + const { num, page, listQuery } = this.state; + getList(num, page, listQuery).then((res) => { + this.setState({ + loading: false, + list: res.data.data, + total: res.data.total, + selectedRowKeys: [], + isAllSelected: false, + }); + this.setState({ loading: false }); + }).catch(() => { + this.setState({ loading: false }); + }); + } + + // 重置 + handleReset = () => { + if (this.formRef.current) { + // 重置表单字段 + this.formRef.current.resetFields(); + // 重置 listQuery 状态 + this.setState({ + listQuery: { + industryId: undefined, + serviceTypeId: undefined, + questionContent: undefined + }, + selectedRowKeys: [], + isAllSelected: false, + }); + } + }; + + // 删除(明细) + deleteSingle = (id: number) => { + Modal.confirm({ + title: '确认删除', + content: '你确定要删除这个问题吗?', + onOk: () => { + deleteQuestion(id).then((res) => { + const isSuccess = res.data; + if (isSuccess) { + message.success('删除成功'); + this.getList(); + } else { + message.error('删除失败,请稍后重试'); + } + }).catch(() => { + message.error('删除时发生错误,请检查'); + }); + }, + onCancel: () => { + }, + }); + }; + + // 删除 + deleteMultiple = () => { + const { selectedRowKeys } = this.state; + if (selectedRowKeys.length === 0) { + message.warning('请选择要删除的问题'); + return; + } + Modal.confirm({ + title: '确认删除', + content: '你确定要删除这些选中的问题吗?', + onOk: () => { + deleteQuestionList(selectedRowKeys) + .then((res) => { + const isSuccess = res.data; + if (isSuccess) { + message.success('删除成功'); + this.getList(); + } else { + message.error('删除失败,请稍后重试'); + } + }) + .catch(() => { + message.error('删除时发生错误,请检查'); + }); + }, + onCancel: () => { + }, + }); + }; + + // 多选 + onSelectChange = (selectedRowKeys: React.Key[]) => { + this.setState({ + selectedRowKeys: selectedRowKeys as number[], + isAllSelected: selectedRowKeys.length === this.state.list.length + }); + }; + + // 单选 + onSelect = (record: any, selected: boolean) => { + if (selected) { + // 单选时只保留当前选中行 + this.setState({ + selectedRowKeys: [record.id], + isAllSelected: false + }); + } else { + // 取消选中时清空选中行 + this.setState({ + selectedRowKeys: [], + isAllSelected: false + }); + } + }; + + render() { + const onFinish = (values: object) => { + const _listQuery = { ...this.state.listQuery, ...values }; + this.setState({ listQuery: _listQuery }); + this.getList(); + }; + + const { industryDict, serviceTypeDict, selectedRowKeys } = this.state; + + // 行选择 + const rowSelection: TableRowSelection = { + selectedRowKeys, + onChange: this.onSelectChange, + onSelect: this.onSelect, + getCheckboxProps: (record) => ({ + checked: selectedRowKeys.includes(record.id), + indeterminate: selectedRowKeys.includes(record.id), + }) + }; + + // 页面跳转 + const handleAddQuestion = () => { + this.props.history.push('/questionAdd'); + }; + + const columns: any = [ + { 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: '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)); + return industry? industry.industryName : industryId; + } + }, + { title: 'AQ服务类型', dataIndex: 'serviceTypeId', key: 'serviceTypeId', align: 'center', width: 150, + render: (serviceTypeId:any) => { + const serviceType = serviceTypeDict?.find((item: { dictKey: string | number; dictValue: string }) => String(item.dictKey) === String(serviceTypeId)); + return serviceType? serviceType.dictValue : serviceTypeId; + } + }, + { title: '题型', dataIndex: 'questionTypes', key: 'questionTypes', align: 'center', width: 80, + render: (questionTypes:any) => { + if (questionTypes === 1) { + return '单选题'; + } else if (questionTypes === 2) { + return '多选题'; + } + return questionTypes;} + }, + { title: '题干', dataIndex: 'questionContent', key: 'questionContent', align: 'center', width: 450 }, + { title: '答案', dataIndex: 'answer', key: 'answer', align: 'center', width: 120 }, + { title: '题目ID', dataIndex: 'id', key: 'id', width: 120}, + { title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 120, + render: (record: any) => [ + { + this.setState({title: '删除', modalWidth: '85%'}) + this.deleteSingle(record.id); + }}>删除, + { + this.setState({title: '修正', modalWidth: '85%'}) + sessionStorage.setItem('id', String(record.id)); + this.props.history.push(`/questionUp`); + }}>修正 + ] + }, + ]; + + // 分页切换 + 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 ( +
+
+
+ + + + + + + + + + + + + + + +
+
+
+ + + + + + +
+ `共 ${total} 条`, + onShowSizeChange: selectChange, + onChange: changePage + }} + rowSelection={rowSelection} + /> + + ); + } +} + +export default QuestionList; \ No newline at end of file diff --git a/packages/examination/src/views/question/questionUp.tsx b/packages/examination/src/views/question/questionUp.tsx new file mode 100644 index 0000000..09b9e2f --- /dev/null +++ b/packages/examination/src/views/question/questionUp.tsx @@ -0,0 +1,403 @@ +import React, { Component } from'react'; +import { Form, Input, Button, Radio, Checkbox, Select, message } from 'antd'; +import { dictionary } from "api/dict/index"; +import {findIndustry, getDetail, update} from 'api/question'; + +const { Option } = Select; + +interface QuestionState { + id: string|null; + questionTypes: string; + industryId: string; + serviceTypeId: string; + questionContent: string; + answerOptions: {[ + key: string]: string + }; + answer: string; +} + +interface States { + industryDict: any; + serviceTypeDict: any; + isLoading: boolean; + question: QuestionState; +} + +class QuestionUp extends Component { + formRef: any; + constructor(props: any) { + super(props); + this.formRef = React.createRef(); + this.state = { + industryDict: undefined, + serviceTypeDict: undefined, + isLoading: false, + question: { + id: '', + questionTypes: '1', + industryId: '', + serviceTypeId: '', + questionContent: '', + answerOptions: { A: '', B: '', C: '', D: '' }, + answer: '' + }, + }; + } + + componentDidMount() { + this.findIndustry() + this.findDict(); + this.getDetail(); + } + + // 监管行业 + findIndustry() { + findIndustry().then((res: any) => { + if (res.data) { + this.setState({ industryDict: res.data }); + } + }); + } + + // AQ服务类型 + findDict() { + dictionary('serviceTypeDict').then((res) => { + if (res.data) { + this.setState({ serviceTypeDict: res.data }); + } + }); + } + + // 题目详情 + getDetail = () => { + const id = sessionStorage.getItem('id'); + sessionStorage.removeItem('id'); + getDetail(id).then((res: any) => { + if (res.data) { + let answerOptions = {}; + const options = res.data.options.split(';'); + options.forEach((option: any) => { + const [key, value] = option.split(':'); + answerOptions[key] = value; + }); + const question: QuestionState = { + id:id, + questionTypes: String(res.data.questionTypes), + industryId: String(res.data.industryId), + serviceTypeId: String(res.data.serviceTypeId), + questionContent: String(res.data.questionContent), + answerOptions: answerOptions, + answer: res.data.answer + }; + this.setState({ question: question }, () => { + const formValues = {}; + formValues['questionTypes'] = question.questionTypes; + formValues['industryId'] = question.industryId; + formValues['serviceTypeId'] = question.serviceTypeId; + formValues['questionContent'] = question.questionContent; + formValues['answer'] = question.answer; + formValues['answerOption_A'] = question.answerOptions.A; + formValues['answerOption_B'] = question.answerOptions.B; + formValues['answerOption_C'] = question.answerOptions.C; + formValues['answerOption_D'] = question.answerOptions.D; + this.formRef.current.setFieldsValue(formValues); + }); + } + }).catch(() => { + message.error('获取题目详情失败,请重试'); + }); + }; + + // 题型 + handleQuestionTypeChange = (value: string) => { + this.setState((prevState) => { + prevState.question.questionTypes = value; + prevState.question.answer = ''; + return { + question: prevState.question + }; + }); + }; + + // 单选框 + handleRadioChange = (value: string) => { + this.setState((prevState) => { + prevState.question.answer = value; + return { + question: prevState.question + }; + }); + }; + + // 多选框 + handleCheckboxChange = (type: string, values: (string | number | boolean)[] | null) => { + const currentAnswer = this.state.question.answer; + const currentSelectedArray = currentAnswer? currentAnswer.split(',') : []; + if (!values || values.length === 0) { + const newSelectedArray = currentSelectedArray.filter(val => val!== type); + newSelectedArray.sort(); + this.setState((prevState) => { + prevState.question.answer = newSelectedArray.join(','); + return { + question: prevState.question + }; + }); + } else { + const stringValues = values.map((val) => String(val)); + const newSelectedArray = Array.from(new Set([...currentSelectedArray, ...stringValues])); + newSelectedArray.sort(); + this.setState((prevState) => { + prevState.question.answer = newSelectedArray.join(','); + return { + question: prevState.question + }; + }); + } + }; + + // 答案 + handleAnswerOptionChange = (option: string, value: string) => { + this.setState((prevState) => { + prevState.question.answerOptions[option] = value; + return { + question: prevState.question + }; + }); + }; + + // 保存修改 + update = () => { + this.setState({ isLoading: true }); + this.formRef.current.validateFields().then((values: Record) => { + const { question } = this.state; + const updatedQuestion = { + ...question, + industryId: values['industryId'], + serviceTypeId: values['serviceTypeId'], + questionContent: values['questionContent'] + }; + this.setState({ question: updatedQuestion }); + update(updatedQuestion).then((res) => { + const isSuccess = res.data; + if (isSuccess) { + message.success('修改成功'); + this.setState({ isLoading: false }); + this.props.history.push('/questionList'); + } else { + message.error('修改失败,请稍后重试'); + this.setState({ isLoading: false }); + } + }).catch(() => { + message.error('修改时发生错误,请检查'); + this.setState({ isLoading: false }); + }); + }); + }; + render() { + const { industryDict, serviceTypeDict, question, isLoading } = this.state; + const handleListQuestion = () => { + this.props.history.push('/questionList'); + }; + return ( +
+
+
+ + this.handleQuestionTypeChange(e.target.value)}> + 单选题 + 多选题 + + + + + + + + +
+ + + + +
+
+ {question.questionTypes === '1'? ( + this.handleRadioChange(e.target.value)} + > + A + this.handleAnswerOptionChange('A', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange('A', values,)}> + A + this.handleAnswerOptionChange('A', e.target.value)} + /> + + )} + {question.questionTypes === '1' ? ( + this.handleRadioChange( e.target.value)} + style={{ marginLeft: 20 }} + > + B + this.handleAnswerOptionChange('B', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange('B',values)}> + B + this.handleAnswerOptionChange( 'B', e.target.value)} + /> + + )} +
+
+ {question.questionTypes === '1'? ( + this.handleRadioChange( e.target.value)} + > + C + this.handleAnswerOptionChange('C', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange('C', values)}> + C + this.handleAnswerOptionChange( 'C', e.target.value)} + /> + + )} + {question.questionTypes === '1'? ( + this.handleRadioChange( e.target.value)} + style={{ marginLeft: 20 }} + > + D + this.handleAnswerOptionChange('D', e.target.value)} + /> + + ) : ( + this.handleCheckboxChange('D',values)}> + D + this.handleAnswerOptionChange('D', e.target.value)} + /> + + )} +
+
+
+ +
+ + +
+
+ ); + } +} + +export default QuestionUp; \ No newline at end of file diff --git a/packages/examination/src/views/slider/menu.tsx b/packages/examination/src/views/slider/menu.tsx index 85094c7..32d7428 100644 --- a/packages/examination/src/views/slider/menu.tsx +++ b/packages/examination/src/views/slider/menu.tsx @@ -34,6 +34,28 @@ const menuList = [ } ] }, + { + title: '题库管理', + key: 'question', + icon: 'icon-peizhi', + subs: [ + { + title: '题库管理', + key: 'questionList', + } + ] + }, + { + title: '试卷管理', + key: 'question', + icon: 'icon-peizhi', + subs: [ + { + title: '试卷管理', + key: 'examPaperList', + } + ] + } // { // title: 'demo', // key: 'demo',