From 557845bddce82b8c573025c5e0125f9534876254 Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Mon, 28 Feb 2022 00:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attestation/components/AutoSelector.tsx | 112 +++++------------- .../attestation/step/index.tsx | 15 ++- .../components/ScoreSetter.tsx | 2 +- .../normal/components/AutoSelector.tsx | 23 +++- .../pages/examinationrules/normal/service.ts | 17 +++ .../examinationrules/normal/step/index.tsx | 21 ++-- admin/src/pages/examinationrules/service.ts | 12 +- 7 files changed, 98 insertions(+), 104 deletions(-) diff --git a/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx b/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx index b218b66..1e68b1b 100644 --- a/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx +++ b/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx @@ -38,84 +38,27 @@ export type TableListItem = { // 资质考试自动组卷 // React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。 const AutoSelector = (props: any, ref: any) => { + const { questionType } = props; - const actionRef = useRef(); - /** 列表项定义 */ - const columns: ProColumns[] | ProColumns[] = [ - { - title: '序号', - key: 'index', - valueType: 'indexBorder', - render: (text: React.ReactNode, _: any, index: number) => { - if (actionRef && actionRef?.current && actionRef?.current?.pageInfo) { - return `${(actionRef?.current?.pageInfo?.current - 1) * actionRef.current.pageInfo?.pageSize + (index + 1) - }`; - } else { - return ''; - } - }, - width: 48, - }, - { - title: '类型', - dataIndex: 'question_type', - valueType: 'select', - hideInTable: false, - hideInForm: true, - hideInSearch: false, - width: 100, - request: async () => { - const { list: Items } = await queryQuestionType(); - const types = [] - for (let i = 0; i < Items.length; i++) { - types.push({text: Items[i]?.name, label: Items[i]?.name, value: Items[i]?.code }) - } - return types; - }, - render: (text: React.ReactNode, _: any, index: number) => { - return text; - }, - - }, - { - title: '题干', - dataIndex: 'question_stem', - valueType: 'text', - hideInTable: false, - hideInForm: true, - hideInSearch: false, - }, - ]; +// const actionRef = useRef(); + const [questionCount, setQuestionCount] = useState([0,0]) // 题库抽取数量 + const [questionTypeCount, setQuestionTypeCount] = useState(questionType.map(()=>(0))) // 题型抽取数量 + const match = useRouteMatch(); console.log('match', match); - const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型 - const [questionType, setQuestionType] = useState([]); - const [selectedRowsState, setSelectedRows] = useState([]); - const [addType, setAddType] = useState({name: '', value: 0}); - - const labels = ['A','B','C','D','E'] + //const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型 + //const [questionType, setQuestionType] = useState([]); + //const [selectedRowsState, setSelectedRows] = useState([]); + //const [addType, setAddType] = useState({name: '', value: 0}); - /** 获取题型 */ - const { data } = useRequest(() => { - return queryQuestionType(); - },{ - formatResult: (result) => { - return result.list; - } - }); - useEffect(() => { - setQuestionType(data || []); - return ()=>{ - } - }, [data]); // 暴露组件的方法 接受外部获取的ref useImperativeHandle(ref, () => ({ // 构造ref的获取数据方法 - getSelectedRows: () => { - return selectedRowsState; + getData: () => { // 组卷 + return {questionCount, questionTypeCount}; }, })); return ( @@ -123,26 +66,31 @@ const AutoSelector = (props: any, ref: any) => { 题库选择 {`常规题库 ( ${0} 道题)`} - 抽取比例: % + 抽取比例: { + setQuestionCount([value,questionCount[1]]) + }} /> % {`资质考试题库 ( ${0} 道题)`} - 抽取比例: % + 抽取比例: { + setQuestionCount([questionCount[0], value]) + }} /> % 题型选择 - - {`单选`} - 题 - - - {`多选`} - 题 - - - {`判断`} - 题 - + { questionType && questionType.map((item, index)=>{ + return + {`${item?.name}`} + { + const _data = []; + questionTypeCount.forEach((val, key) => { + _data.push(index === key ? value : val) + }); + setQuestionTypeCount(_data) + }} /> 题 + + } + )} ); }; diff --git a/admin/src/pages/examinationrules/attestation/step/index.tsx b/admin/src/pages/examinationrules/attestation/step/index.tsx index 895056e..58da570 100644 --- a/admin/src/pages/examinationrules/attestation/step/index.tsx +++ b/admin/src/pages/examinationrules/attestation/step/index.tsx @@ -16,7 +16,7 @@ import { Button, Checkbox, Col, Divider, Input, List, Menu, message, Radio, Row, import { PageContainer } from '@ant-design/pro-layout'; import ProDescriptions from '@ant-design/pro-descriptions'; import styles from './index.less' -import { saveRules, querySubjectList, queryRulesView, queryRulesList, queryRulesPaper, saveQuestionTypeScore } from '../../service'; +import { saveRules, querySubjectList, queryRulesView, queryRulesList, queryRulesPaper, saveQuestionTypeScore, autoPaperOfficial } from '../../service'; import { queryQuestionType } from '@/pages/questionbank/service'; import ProTable, { ActionType, EditableProTable, ProColumns } from '@ant-design/pro-table'; import { TableListPagination } from '@/pages/ListTableList2/data'; @@ -400,8 +400,18 @@ export default () => { title="系统组卷" visible={autoModalVisible} onVisibleChange={handleAutoModalVisible} + onFinish={async () => { + const values = autoRef.current?.getData(); + console.log('系统组卷::::', values); + const {code, data: paper, msg} = await autoPaperOfficial({rules_id:Number(params?.id), question_count: values?.questionCount.toString(), question_type_count: values?.questionTypeCount.toString()}) + console.log('paper', paper) + // setUuidPaper(paper?.paper_uuid) + // message.success('提交成功'); + handleAutoModalVisible(false) + return true; + }} > - + { onFinish={async () => { const values = setterRef.current?.getData() console.log('批量设置分值v::::', values); - const {code, data: paper, msg} = await saveQuestionTypeScore({rules_id:Number(params?.id), type_score: JSON.stringify(values)}) console.log('paper', paper) // setUuidPaper(paper?.paper_uuid) diff --git a/admin/src/pages/examinationrules/components/ScoreSetter.tsx b/admin/src/pages/examinationrules/components/ScoreSetter.tsx index d5b76e4..89b2796 100644 --- a/admin/src/pages/examinationrules/components/ScoreSetter.tsx +++ b/admin/src/pages/examinationrules/components/ScoreSetter.tsx @@ -47,7 +47,7 @@ const ScoreSetter = (props: any, ref: any) => { const formRef = useRef(); - const formEntityRef = useRef(); + //const actionRef = useRef(); diff --git a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx index 22e38e3..f82dca2 100644 --- a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx +++ b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx @@ -3,7 +3,7 @@ */ //import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; -import { Button, InputNumber, message } from 'antd'; +import { Button, Form, InputNumber, message } from 'antd'; //import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; //import { useRequest } from 'umi'; //import { queryFakeList } from './service'; @@ -63,9 +63,7 @@ const AutoSelector = (props: any, ref: any) => { console.log('props subject_id', props) const { subjectId, questionType } = props; console.log('questionType', questionType) - const [editableKeys, setEditableRowKeys] = useState(() => - defaultData.map((item) => item.id), - ); + const [typeScore, setTypeScore] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}] //const [dataSource, setDataSource] = useState(() => defaultData); @@ -84,11 +82,21 @@ const AutoSelector = (props: any, ref: any) => { /* 动态设置题型列 */ questionType?.forEach((item)=>{ columns.push({ - title: <>{item?.name} , + title: <>{item?.name} , //key: 'code', dataIndex: `type${item?.code}`, render: ( item, { defaultRender, ...rest }, form) => { - return ; + return { + // + const _data = []; + console.log('typeScore',typeScore) + typeScore?.forEach((item, key)=>{ + _data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)}) + }) + setTypeScore(_data) + }} + />; }, }) }) @@ -140,6 +148,7 @@ const AutoSelector = (props: any, ref: any) => { // setDataSource }} toolBarRender={false} + /* editable={{ type: 'multiple', editableKeys, @@ -147,10 +156,12 @@ const AutoSelector = (props: any, ref: any) => { return [defaultDoms.delete]; }, onValuesChange: (record, recordList) => { + console.log('rrrr',record, recordList) // setDataSource(recordList); }, onChange: setEditableRowKeys, }} + */ /> ); diff --git a/admin/src/pages/examinationrules/normal/service.ts b/admin/src/pages/examinationrules/normal/service.ts index bdbf12f..6f61013 100644 --- a/admin/src/pages/examinationrules/normal/service.ts +++ b/admin/src/pages/examinationrules/normal/service.ts @@ -139,3 +139,20 @@ export async function manualPaper( }, }); } + +/** + * 25 模拟组卷,自动组卷 + * @param params + * @returns + */ + export async function autoPaper( + params: ParamsType, +): Promise<{ data: { list: BasicListItemDataType[] } }> { + return request('/dsideal_yy/zygh/training/rules/autoPaper', { + method: 'POST', + requestType: 'form', + data: { + ...params, + }, + }); +} diff --git a/admin/src/pages/examinationrules/normal/step/index.tsx b/admin/src/pages/examinationrules/normal/step/index.tsx index 0735a59..4139f4f 100644 --- a/admin/src/pages/examinationrules/normal/step/index.tsx +++ b/admin/src/pages/examinationrules/normal/step/index.tsx @@ -22,7 +22,7 @@ import { queryQuestionList, queryQuestionById, queryQuestionType } from '@/pages import { PlusOutlined, DownOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EyeInvisibleOutlined, EyeOutlined, EditOutlined } from '@ant-design/icons'; import ProList from '@ant-design/pro-list'; -import { manualPaper, updatePaper } from '../service'; +import { autoPaper, manualPaper, updatePaper } from '../service'; import ProTable, { EditableProTable } from '@ant-design/pro-table'; import QuestionSelector from '../../components/QuestionSelector'; @@ -326,12 +326,13 @@ export default () => {
试卷信息与设置 - 共 { } 题 { } 分 + 共 { 0 } 题 { 0 } 分 - 单选题 共 { } 题 { } 分 - 多选题 共 { } 题 { } 分 - 判断题 共 { } 题 { } 分 + { questionType.map((item)=>{ + return {item?.name} 共 { 0 } 题 { 0 } 分 + } + )} @@ -437,12 +438,10 @@ export default () => { visible={autoModalVisible} onVisibleChange={ handleAutoModalVisible } footer={null} - onFinish={async (values) => { - console.log('v::::', values.name); - //const rows = selectorRef?.current?.getSelectedRows() - //console.log('rows::::', rows); - //const {code, data: paper, msg} = await handleAppend(Number(params?.id), rows) - //console.log('paper', paper) + onFinish={async () => { + const values = autoRef?.current?.getData() + const {code, data: paper, msg} = await autoPaper({rules_id: Number(params?.id), auto_param: JSON.stringify(values)}) + console.log('paper', paper) //setUuidPaper(paper?.paper_uuid) // message.success('提交成功'); handleAutoModalVisible(false) diff --git a/admin/src/pages/examinationrules/service.ts b/admin/src/pages/examinationrules/service.ts index a4a0dc8..f485591 100644 --- a/admin/src/pages/examinationrules/service.ts +++ b/admin/src/pages/examinationrules/service.ts @@ -199,4 +199,14 @@ export async function saveQuestionTypeScore(data: Record, options?: requestType: "form", ...(options || {}), }); -} \ No newline at end of file +} + +/** 22 组卷,资质考试组卷 */ +export async function autoPaperOfficial(data: Record, options?: Record) { + return request('/dsideal_yy/zygh/training/rules/autoPaperOfficial', { + data, + method: 'POST', + requestType: "form", + ...(options || {}), + }); +}