试卷修改题目数量校验

main
hujunpeng 3 months ago
parent f32019c4af
commit 69fdf2849d
  1. 11
      packages/examination/src/api/examPaper/index.tsx
  2. 33
      packages/examination/src/views/examPaper/examPaperAdd.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
});
}
/**
*
*/

@ -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<any, States> {
});
};
// 题目数量
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,7 +444,20 @@ class ExamPaperAdd extends Component<any, States> {
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();
}
}
]}
>
<Input type="number" style={{ textAlign: 'right' }} placeholder="请输入题目数量" min={1} />
</Form.Item>

Loading…
Cancel
Save