From 950507e37658542200585cbc0278748e3590038d Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Mon, 21 Mar 2022 22:20:36 +0800 Subject: [PATCH 1/3] fix --- .../attestation/components/AutoSelector.tsx | 11 ++-- .../normal/components/AutoSelector.tsx | 59 ++++++++++++++----- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx b/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx index 3e3704d..77e37b2 100644 --- a/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx +++ b/admin/src/pages/examinationrules/attestation/components/AutoSelector.tsx @@ -3,7 +3,7 @@ */ //import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; -import { Button, Col, InputNumber, message, Row } from 'antd'; +import { Button, Col, Input, InputNumber, message, Row } from 'antd'; //import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; //import { useRequest } from 'umi'; //import { queryFakeList } from './service'; @@ -16,11 +16,13 @@ import { forwardRef, ReactText, useEffect, useImperativeHandle, useRef, useState //import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons'; import { useParams, useRequest, history, useRouteMatch } from 'umi'; import { queryCourseView } from '@/pages/course/option/service'; -import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; +//import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; + //import ProForm, { ProFormSelect } from '@ant-design/pro-form'; import type { ActionType, ProColumns } from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table'; import { manualPaper } from '../service'; +import { queryQuestionWithoutList } from '../../service'; export type TableListItem = { id: string; @@ -58,7 +60,7 @@ const AutoSelector = (props: any, ref: any) => { /** 获取常规题库试题数量 */ const { data: normalSum } = useRequest(()=>{ - return queryQuestionList({subject_id: params?.id, page_number: 1, page_size: 1, type: 0}) + return queryQuestionWithoutList({subject_id: params?.id, page_number: 1, page_size: 1, type: 0}) },{ formatResult: (result) => { return result.totalRow; @@ -67,7 +69,7 @@ const AutoSelector = (props: any, ref: any) => { /** 获取资质考试题库试题数量 */ const { data: attestationSum } = useRequest(()=>{ - return queryQuestionList({subject_id: params?.id, page_number: 1, page_size: 1, type: 1}) + return queryQuestionWithoutList({subject_id: params?.id, page_number: 1, page_size: 1, type: 1}) },{ formatResult: (result) => { return result.totalRow; @@ -89,6 +91,7 @@ const AutoSelector = (props: any, ref: any) => { return ( <> + 生成试卷数量:试卷数量与学生重复考试次数一致 题库选择 {`常规题库 ( ${normalQuestionSum} 道题)`} diff --git a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx index 529d902..ed5730c 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, Form, InputNumber, message } from 'antd'; +import { Button, Form, Input, InputNumber, message } from 'antd'; //import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; //import { useRequest } from 'umi'; //import { queryFakeList } from './service'; @@ -50,12 +50,13 @@ type DataSourceType = { // 需要处理 // React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。 const AutoSelector = (props: any, ref: any) => { + const formRef = useRef() /** 获取章节数据 */ // 获取主题id console.log('props subject_id', props) const { subjectId, questionType } = props; console.log('questionType', questionType) - const [typeScore, setTypeScore] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}] + const [typeChapterCount, setTypeChapterCount] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}] //const [dataSource, setDataSource] = useState(() => defaultData); @@ -72,22 +73,41 @@ const AutoSelector = (props: any, ref: any) => { ]; /* 动态设置题型列 */ - questionType?.forEach((item)=>{ + questionType?.forEach((item, idx)=>{ columns.push({ - title: <>{item?.name} , + title: <>{item?.name} { + + }} + onChange={(e)=>{ + const val = e.currentTarget.value; + console.log('onchange==', val) + const values = formRef?.current.getFieldsValue() + console.log('values', values) + const {questionType} = values; + const avg = val / questionType[idx].length // 平均数 + const rem = val % questionType[idx].length // 余数 + const _questionType = questionType[idx].map((item, key)=>{return key < rem ? Math.ceil(avg) : Math.floor(avg)}) + console.log('questionTypeData', _questionType) + questionType[idx] = _questionType; + //[[10]] + formRef?.current.setFieldsValue({questionType: questionType}) + }} + />, //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)}) + console.log('record', record) + //{chapter_id: record?.chapter_id, count:0} + /* + console.log('typeChapterCount',typeChapterCount) + const data = typeChapterCount?.map((item, key)=>{ + data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)}) }) - setTypeScore(_data) - console.log('setTypeScore',typeScore) + setTypeChapterCount(data) + console.log('setTypeChapterCount---',typeChapterCount) + */ }} />; }, @@ -105,13 +125,18 @@ const AutoSelector = (props: any, ref: any) => { return ( <> - { console.log('formRef',formRef.current.getFieldsValue()); formRef.current.setFieldsValue({questionType:[['10']]})}}>show +
+ { const { data } = await queryListChapterBySubject({ @@ -120,13 +145,14 @@ const AutoSelector = (props: any, ref: any) => { page_size: 1000, }); console.log('data--',data) + /* const _data = []; data?.list.forEach((item)=>{ _data.push({ id: item?.chapter_id, chapter_name: item?.chapter_name, }) - }) + })*/ //chapter_name return {data: data?.list}; /* @@ -143,6 +169,7 @@ const AutoSelector = (props: any, ref: any) => { }} toolBarRender={false} /> + ); }; From 2589f5f3e2a288e0280a7d2ee24cd3a0b9bb7246 Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Mon, 21 Mar 2022 23:07:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=BB=84=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../normal/components/AutoSelector.tsx | 33 +++++++++---------- .../examinationrules/normal/step/index.tsx | 17 ++++++---- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx index ed5730c..e49a6ca 100644 --- a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx +++ b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx @@ -56,7 +56,7 @@ const AutoSelector = (props: any, ref: any) => { console.log('props subject_id', props) const { subjectId, questionType } = props; console.log('questionType', questionType) - const [typeChapterCount, setTypeChapterCount] = useState([]) ; // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}] + const [rows, setRows] = useState([]) ; // 章节 //const [dataSource, setDataSource] = useState(() => defaultData); @@ -83,7 +83,7 @@ const AutoSelector = (props: any, ref: any) => { console.log('onchange==', val) const values = formRef?.current.getFieldsValue() console.log('values', values) - const {questionType} = values; + const { questionType } = values; const avg = val / questionType[idx].length // 平均数 const rem = val % questionType[idx].length // 余数 const _questionType = questionType[idx].map((item, key)=>{return key < rem ? Math.ceil(avg) : Math.floor(avg)}) @@ -96,20 +96,7 @@ const AutoSelector = (props: any, ref: any) => { //key: 'code', dataIndex: `type${item?.code}`, render: ( _dom, record, index) => { - return { - console.log('record', record) - //{chapter_id: record?.chapter_id, count:0} - /* - console.log('typeChapterCount',typeChapterCount) - const data = typeChapterCount?.map((item, key)=>{ - data.push({...item, score_harf: ((index === key) ? value : item?.score_harf)}) - }) - setTypeChapterCount(data) - console.log('setTypeChapterCount---',typeChapterCount) - */ - }} - />; + return ; }, }) }) @@ -119,7 +106,18 @@ const AutoSelector = (props: any, ref: any) => { useImperativeHandle(ref, () => ({ // 构造ref的获取数据方法 getData: () => { // 组卷数据 - return []; + console.log('useImperativeHandle') + const values = formRef.current.getFieldsValue() + console.log(values) + const data = values?.questionType.map((item, key)=>{ + return { + question_type:key, + chapter_list: item.map((val,idx)=>( + {chapter_id:rows[idx]?.chapter_id, count: val} + )) + } + }) // 题型分数数组 [{"question_type":0,"chapter_list": [{ "chapter_id":3, "count":1 }]}] + return data; }, })); @@ -144,6 +142,7 @@ const AutoSelector = (props: any, ref: any) => { page_number: 1, page_size: 1000, }); + setRows(data?.list) console.log('data--',data) /* const _data = []; diff --git a/admin/src/pages/examinationrules/normal/step/index.tsx b/admin/src/pages/examinationrules/normal/step/index.tsx index 557cc41..0f1e0bc 100644 --- a/admin/src/pages/examinationrules/normal/step/index.tsx +++ b/admin/src/pages/examinationrules/normal/step/index.tsx @@ -663,15 +663,18 @@ export default () => { visible={autoModalVisible} onVisibleChange={handleAutoModalVisible} onFinish={async () => { - // 需要处理 - //console.log('111') - const values = autoRef?.current?.getData() - console.log('values ', values ) + const values = autoRef?.current.getData() + console.log('data-v', values) //const values = [{"question_type":0,"chapter_list": [{ "chapter_id":76, "count":1 },{ "chapter_id":77, "count":1 }]}] - //const {code, data: paper, msg} = await autoPaper({rules_id: Number(params?.id), auto_param: JSON.stringify(values)}) + 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('提交成功'); + setUuidPaper(paper?.paper_uuid) + run({ + paper_uuid: paper?.paper_uuid, + page_size: 1000, + page_number: 1 + }); // 获取当前选题列表 + message.success('提交成功'); handleAutoModalVisible(false) return true; }} From d08f77deb02c7555423662fd955146b3c94fc7f6 Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Tue, 22 Mar 2022 09:51:20 +0800 Subject: [PATCH 3/3] fix --- .../normal/components/AutoSelector.tsx | 3 +-- .../examinationrules/normal/step/index.tsx | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx index e49a6ca..c086427 100644 --- a/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx +++ b/admin/src/pages/examinationrules/normal/components/AutoSelector.tsx @@ -93,7 +93,7 @@ const AutoSelector = (props: any, ref: any) => { formRef?.current.setFieldsValue({questionType: questionType}) }} />
, - //key: 'code', + key: 'code', dataIndex: `type${item?.code}`, render: ( _dom, record, index) => { return ; @@ -123,7 +123,6 @@ const AutoSelector = (props: any, ref: any) => { return ( <> -
{ {/** 一旦录入另一项将禁用,清空组卷后可选另一项 */} - + + {questions ? + { + handleAutoModalVisible(true) + }} + onCancel={()=>{}} + okText="是" + cancelText="否" + > + + + : + + } +