From 69fdf2849db8a0663ff596d549b74868fa9dda55 Mon Sep 17 00:00:00 2001 From: hujunpeng Date: Wed, 26 Mar 2025 16:10:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E4=BF=AE=E6=94=B9=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E6=95=B0=E9=87=8F=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../examination/src/api/examPaper/index.tsx | 11 ++++++ .../src/views/examPaper/examPaperAdd.tsx | 35 +++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/packages/examination/src/api/examPaper/index.tsx b/packages/examination/src/api/examPaper/index.tsx index 2fba733..1d247e3 100644 --- a/packages/examination/src/api/examPaper/index.tsx +++ b/packages/examination/src/api/examPaper/index.tsx @@ -58,6 +58,17 @@ export function getRandomQuestions(data: any) { }); } +/** + * 获取监管行业下的所有试题 + */ +export function geIndustryQuestions(data: any) { + return axios({ + url: "/ex/examPaper/geIndustryQuestions", + method: 'post', + data: data + }); +} + /** * 添加试卷 */ diff --git a/packages/examination/src/views/examPaper/examPaperAdd.tsx b/packages/examination/src/views/examPaper/examPaperAdd.tsx index 46beb53..5b0c06f 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, addExamPaper, editExamPaper, getExamPaperDetail} from 'api/examPaper'; +import { getRandomQuestions, addExamPaper, editExamPaper, getExamPaperDetail, geIndustryQuestions} from 'api/examPaper'; import { getList ,findIndustry} from 'api/question'; import { dictionary } from "../../api/dict"; import TextArea from "antd/es/input/TextArea"; @@ -339,6 +339,22 @@ class ExamPaperAdd extends Component { }); }; + // 题目数量 + compareQuestionCount = async (industryId: string, questionCount: number) => { + if (industryId === null || industryId === undefined || questionCount === null || questionCount === undefined) { + return true; + } + const data = { + industryId: industryId + }; + const res = await geIndustryQuestions(data); + if (res.data) { + const dbCount = res.data; + return questionCount <= dbCount; + } + return true; + }; + render() { const { industryDict, @@ -428,9 +444,22 @@ class ExamPaperAdd extends Component { label="题目数量:" name="questionCount" style={{ width: 240 }} - rules={[{ required: true, message: '请输入题目数量' }]} + rules={[ + { required: true, message: '请输入题目数量' }, + { + message: '输入的题目数量大于该监管行业可获取的题目数量', + validator: async (_, value) => { + const { industryId } = this.formRef.current.getFieldsValue(); + const isValid= await this.compareQuestionCount(industryId, value); + if (!isValid) { + return Promise.reject(new Error('输入的题目数量大于该监管行业可获取的题目数量')); + } + return Promise.resolve(); + } + } + ]} > - +