From 2a7edb37ee2e7df64d0bdb5adb58a67ba79ab20c Mon Sep 17 00:00:00 2001 From: hujunpeng Date: Fri, 14 Mar 2025 17:50:55 +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 --- .../examination/src/api/examPaper/index.tsx | 109 ++--- .../examination/src/api/question/index.tsx | 3 +- .../src/views/examPaper/examPaperAdd.tsx | 182 ++++---- .../src/views/examPaper/examPaperList.tsx | 385 ++++++++-------- .../src/views/examPaper/examPaperView.tsx | 131 +++--- .../src/views/question/questionAdd.tsx | 410 +++++++++++------- .../src/views/question/questionEdit.tsx | 21 +- .../src/views/question/questionList.tsx | 37 +- 8 files changed, 656 insertions(+), 622 deletions(-) diff --git a/packages/examination/src/api/examPaper/index.tsx b/packages/examination/src/api/examPaper/index.tsx index 65d2f10..2fba733 100644 --- a/packages/examination/src/api/examPaper/index.tsx +++ b/packages/examination/src/api/examPaper/index.tsx @@ -1,112 +1,81 @@ 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', - method: 'post', - data: data - }); -} - -/* -* 批量变更状态 -*/ -export function batchUpdatePaperStatus(data: any) { - return axios({ - url: '/ex/examPaper/batchUpdatePaperStatus', + url: '/ex/examPaper/upPaperStatus', method: 'post', data: data }); } -/* -* 题目详情 -*/ -export function getDetail(id: string|null) { +/** + * 获取试卷详情 + */ +export function getExamPaperDetail(id: any) { 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 }); -} +} \ No newline at end of file diff --git a/packages/examination/src/api/question/index.tsx b/packages/examination/src/api/question/index.tsx index 7fe783c..3f1b033 100644 --- a/packages/examination/src/api/question/index.tsx +++ b/packages/examination/src/api/question/index.tsx @@ -62,5 +62,4 @@ export function findIndustry() { url: '/ex/question/findIndustry', method: 'get' }); -} - +} \ No newline at end of file diff --git a/packages/examination/src/views/examPaper/examPaperAdd.tsx b/packages/examination/src/views/examPaper/examPaperAdd.tsx index 6118261..d3944e9 100644 --- a/packages/examination/src/views/examPaper/examPaperAdd.tsx +++ b/packages/examination/src/views/examPaper/examPaperAdd.tsx @@ -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 { 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 { }; } - // 初期 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); } } - // 监管行业 - findIndustry() { - findIndustry().then((res: any) => { - if (res.data) { - this.setState({ industryDict: res.data }); - } - }); - } + // 字典 + handleFindDict() { + // 监管行业 + findIndustry() + .then((res: any) => { + if (res.data) { + this.setState({ industryDict: res.data }); + } + }) + .catch(() => { + message.error("获取监管行业字典数据失败,请稍后重试"); + }); - // AQ服务类型 - findDict() { - dictionary('serviceTypeDict').then((res) => { - if (res.data) { - this.setState({ serviceTypeDict: res.data }); - } - }); + // AQ服务类型 + 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 { 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 { }); }; - // 随机生成题目 - 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 { .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 { .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 { // 处理查询 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 { 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 { selectedQuestionList: [], questionSelectList: [], selectedRowKeys: [], - listQuery: { - industryId: undefined, - serviceTypeId: undefined, - questionContent: undefined - }, num: 10, page: 1, total: 0, @@ -301,6 +282,7 @@ class ExamPaperAdd extends Component { if (this.formRefSub.current) { this.formRefSub.current.resetFields(); } + this.formRef.current.setFieldsValue({ questionCount : selectedQuestionList.length }); }; // 保存试卷 @@ -310,7 +292,7 @@ class ExamPaperAdd extends Component { .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 { 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 { .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 { .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 { } ]; - // 移除操作列 const columnsWithoutOperation = columns.filter((column: any) => column.dataIndex!== 'operation'); return (
@@ -486,10 +464,10 @@ class ExamPaperAdd extends Component {

试题详情

- -
@@ -538,7 +516,7 @@ class ExamPaperAdd extends Component { -
@@ -547,9 +525,9 @@ class ExamPaperAdd extends Component { title="选择试题" open={isModalVisible} maskClosable={false} - onCancel={this.handleCloseManualSelectionModal} + onCancel={this.handleCloseModal} footer={[ - ,