import React, { useEffect, useRef, useState } from 'react'; import { history, useParams, useRequest } from 'umi'; import type { ProFormInstance } from '@ant-design/pro-form'; import { ModalForm } from '@ant-design/pro-form'; import { ProFormRadio } from '@ant-design/pro-form'; import ProForm, { StepsForm, ProFormText, ProFormSelect, ProFormDateRangePicker } from '@ant-design/pro-form'; import ProCard from '@ant-design/pro-card'; import { Button, Checkbox, Col, Divider, Input, List, Menu, message, Radio, Row, Space, Typography } from 'antd'; 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, autoPaperOfficial, queryPaperQuestionList, updateScore } from '../../service'; import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; import type { ActionType, ProColumns } from '@ant-design/pro-table'; import ProTable, { EditableProTable } from '@ant-design/pro-table'; //import { TableListPagination } from '@/pages/ListTableList2/data'; import { DiffOutlined, ExclamationCircleOutlined, PlusOutlined } from '@ant-design/icons'; //import { TableListItem } from '../../components/QuestionSelector'; import ScoreSetter from '../../components/ScoreSetter'; import AutoSelector from '../components/AutoSelector'; import QuestionSelector from '../../components/QuestionSelector'; import { getSubjectInfo } from '@/pages/course/subject/service'; import { max } from 'lodash'; /** 选项序号 */ const labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']; /** 题型序号 */ const numberType = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十']; export default () => { const questionNumber = [1, 1, 1]; const params = useParams(); const formRef = useRef(); const actionRef = useRef(); const setterRef = useRef(); const autoRef = useRef(); const [currentStep, setCurrentStep] = useState(0); const [questionTypeValues, setQuestionTypeValues] = useState([]); // 题型数据[{count:0, score:0, score_harf:0}] const [questionType, setQuestionType] = useState([]); // 题型 const [passScore, setPassScore] = useState(0) const [rulesId, setRulesId] = useState(0); // 规则id, 保存新建的rules_id const [subjectId, setSubjectId] = useState(0); // 关联主题id /** 自动组卷窗口 */ const [autoModalVisible, handleAutoModalVisible] = useState(false); /** 分值窗口 */ const [scoreModalVisible, handleScoreModalVisible] = useState(false); /** 试卷详情窗口 */ const [paperModalVisible, handlePaperModalVisible] = useState(false); const [paperInfo, setPaperInfo] = useState({}) /** 查看试卷 */ const { data: questions, run } = useRequest(async (params) => { console.log('questions', questions) return queryPaperQuestionList(params); }, { manual: true, formatResult: (result) => { return result?.question_list; } }); // const { data: paperData, run: runPaper } = useRequest(async (params) => { console.log('paperData', paperData) /** * rules_id: params?.id, page_number: value.current, page_size: value.pageSize */ return queryRulesPaper(params); }, { manual: true, formatResult: (result) => { return result?.question_list; } }); useEffect(() => { console.log('paperData2', paperData) if (paperData?.length > 0) { console.log('paperData[0]', paperData[0]) setPaperInfo(paperData[0]) } console.log('PaperInfo', paperInfo) }, [paperData]); /** 列表项定义 */ const columns: ProColumns[] = [ { title: '序号', key: 'index', valueType: 'indexBorder', width: 48, }, { title: '考试名称', dataIndex: 'rules_name', valueType: 'text', hideInTable: false, hideInForm: false, hideInSearch: true, }, { title: '试卷', dataIndex: 'examination_time', valueType: 'text', sorter: false, hideInTable: true, hideInForm: true, hideInSearch: true, renderText: (val: string) => `${val}`, }, { title: '题型设置', dataIndex: 'question_type', valueType: 'text', sorter: false, hideInTable: false, hideInForm: true, hideInSearch: true, render: (dom, record, index) => { return <> {record.question_type_count.map((item) => { return {`${item.type_name} ${item.count} 题`} })} }, }, { title: '关联主题', dataIndex: 'subject_name', valueType: 'text', hideInTable: true, hideInForm: true, hideInSearch: true, }, { title: '题型设置', dataIndex: 'question_type_count', valueType: 'text', hideInTable: true, hideInForm: false, hideInSearch: false, request: async () => { /* const { data: Items } = await querySubjectList({}); // console.log(Items, ')))'); const sinfo = [] for (let i = 0; i < Items.list.length; i++) { // console.log(Items.list[i], ">>>") sinfo.push({ label: Items.list[i].subject_name, value: Items.list[i].subject_id }) } console.log(sinfo, 'sinfo'); */ return []; }, }, { title: '总分', dataIndex: 'sum_score', sorter: false, valueType: 'text', hideInSearch: true, hideInForm: false, renderText: (val: string) => `${val || '0'}`, }, { title: '通过线', dataIndex: 'pass_score', sorter: false, valueType: 'text', hideInSearch: true, hideInForm: false, renderText: (val: string) => `${val || '0'}`, }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 220, render: (_dom: any, record: React.SetStateAction) => { // console.log(record, 'record') return [ , , ] }, }, ]; console.log(params, 'params'); let ruleData = {} if (params?.id) { //console.log(JSON.stringify(params), "878"); const { data } = useRequest(async () => { const { bean } = await queryRulesView(params); return { data: bean } }); ruleData = data } console.log('ruleData',ruleData); /** 获取题型 */ const { data: questionTypeData } = useRequest(() => { return queryQuestionType(); }, { formatResult: (result) => { return result.list; } }); useEffect(() => { setQuestionType(questionTypeData || []); return () => { /** 退出当前页面清空Map */ //parsingMap.clear(); } }, [questionTypeData]); return ( formRef={formRef} onFinish={async () => { message.success('提交成功'); }} formProps={{ layout: "horizontal", labelCol: { span: 8 }, wrapperCol: { span: 12 }, validateMessages: { required: '此项为必填项', }, }} > name="base" title="资质考试基本信息" stepProps={{ description: false, }} onFinish={async (fileds) => { if (params.id) { fileds = { ...fileds, id: params.id } } console.log(fileds, 'fileds', params); // return false const { data } = await saveRules({ ...fileds, b_use: 0, rules_type: 1, start_time: fileds.dateRange[0], end_time: fileds.dateRange[1] }); setRulesId(data?.rules_id) setSubjectId(fileds?.subject_id) // 设置当前关联主题 setCurrentStep(1) return true; }} > {ruleData && ( <> { const val = `${e.currentTarget?.value}`; if (val.length > 50) { e.currentTarget.value = val.slice(0, 50) } } //style:{width: '100%'} }} initialValue={ruleData.rules_name} // tooltip="最长为 6 位汉字,需要与考生身份证一致" placeholder="请输入名称" rules={[{ required: true, message: '请输入考试名称' }]} // value="锦书" // disabled /> {/*主题一旦选择并提交将不支持修改 */} { return querySubjectList().then(({ data }) => { console.log(data, 'querySubjectList') return data.list.map((item) => { return { label: item.subject_name, value: item.subject_id, }; }); }); }} rules={[{ required: true, message: '请选择主题' }]} name="subject_id" label="关联主题" disabled={params?.id} /> 关联主题选择并提交将后将不支持修改。 { const val = `${e.currentTarget?.value}`; console.log('val', val) console.log('val.charAt(0)', val.charAt(0)) if (val.charAt(0) === '') { console.log('vvv', val) e.currentTarget.value = '0' } if (val.length > 3) { e.currentTarget.value = val.slice(0, 3) } }, //style: {marginRight:3} }} // tooltip="限制考试时长的情况下,用户考试中离开,倒计时不会停止。" /> 限制考试时长的情况下,用户考试中离开,倒计时不会停止。 {/* { const val = `${e.currentTarget?.value}`; console.log('val', val) console.log('val.charAt(0)', val.charAt(0)) if (val.charAt(0) === '') { console.log('vvv', val) e.currentTarget.value = '' } if (val.length > 3) { e.currentTarget.value = val.slice(0, 3) } }, //style:{width: '100%'} }} // tooltip="限制考试时长的情况下,用户考试中离开,倒计时不会停止。" /> 试卷数量与学生重复考试次数一致 */} {console.log('###', ruleData)} 试卷有效期指超过试卷有效期重新生成试卷 )} name="object" title="组卷" stepProps={{ description: false, }} onFinish={async () => { console.log(formRef.current?.getFieldsValue()); setCurrentStep(2) runPaper({ rules_id: params?.id || rulesId }) return true; }} >
( )} request={async (value) => { console.log('queryRulesPaper::') /** 获取试卷 */ const _data = await queryRulesPaper( { rules_id: params?.id || rulesId, page_number: value.current, page_size: value.pageSize } ); const _questionType = []; const _questionTypeCountData = []; _data.question_list[0]?.question_type_count.forEach((item) => { _questionTypeCountData.push(item.count) _questionType.push({ typeName: item.type_name, code: item.question_type }) }) console.log('_questionTypeCountData', _questionTypeCountData) console.log('_data.question_type_score', _data.question_type_score) if (_data?.question_type_score.length > 0) { _data.question_type_score?.forEach((item, index) => { _questionType[index] = { ..._questionType[index], count: _questionTypeCountData[index], score: item.score, score_harf: item.score_harf } }) } else { _questionTypeCountData?.forEach((item, index) => { _questionType[index] = { ..._questionType[index], count: _questionTypeCountData[index], score: 0, score_harf: 0 } }) } // question_type_count console.log('_questionType 1', _questionType) setQuestionTypeValues(_questionType) return { current: _data?.pageNumber, data: _data?.question_list, pageSize: _data?.pageSize, total: _data?.totalRow || 0, }; }} // dataSource={list} columns={columns} rowSelection={false} />
{ console.log(formRef.current?.getFieldsValue()); // 跳转到指定路由 history.push('/examinationrules/attestation'); return true; }} > {currentStep === 2 && { const result = await queryRulesView({ id: rulesId }) console.log('queryRulesView', result) const subjectInfo = await getSubjectInfo({ subject_id: result.bean.subject_id }) console.log('subjectInfo', subjectInfo) return { data: { ...result.bean, subject_name: subjectInfo.data.subject_name } }; }} extra={false} > (`${text} 分钟`)} /> { {/** 从试卷中读取 临时卷必须保存后才进入此页 */ } return 共 {paperInfo?.question_type_count?.map(item => item.count)?.reduce((prev, curr) => prev + curr)} 道题, {paperInfo?.sum_score || '-'} 分 {paperInfo?.question_type_count?.map(item => ({`${item?.type_name} ${item?.count} 道题 `}))} 通过线 {paperInfo?.pass_score || '-'} 分 }} /> { return
{entity?.paper_count} 试卷数量是学生重复考试次数
}} /> { return
{/*entity?.start_time.substring(0,10)*/} {entity?.end_time.substring(0, 10)} 超过试卷有效期将重新生成试卷
}} />
}
{ const values = autoRef.current?.getData(); console.log('系统组卷::::', values); const { code, data: paper, msg } = await autoPaperOfficial({ rules_id: Number(params?.id || rulesId), subject_id: subjectId, paper_count: values?.paperCount, question_count: values?.questionCount.toString(), question_type_count: values?.questionTypeCount.toString() }) console.log('paper', paper) // setUuidPaper(paper?.paper_uuid) // message.success('提交成功'); actionRef.current?.reload() handleAutoModalVisible(false) return true; }} > { const values = setterRef.current?.getData() // 获取题型分值数据 const passSocre = setterRef.current?.getValue() // 获取通过分数线 const sumCore = setterRef.current?.getSum() // 获取总分数 console.log('getSum()',sumCore) if(passSocre > sumCore){ message.error('通过分数线不能大于总分,请修改通过分数线'); return false; } console.log('批量设置分值v::::', values); const { code, data: paper, msg } = await saveQuestionTypeScore({ rules_id: Number(params?.id || rulesId), type_score: JSON.stringify(values) }) console.log('paper', paper) // 总分及通过分 let _sumScore = 0; values?.forEach((item: { score: number; }) => { console.log('item--', item) _sumScore += item?.score }) console.log('_sumScore', _sumScore) //return false; console.log('passSocre', passSocre) //console.log('sumScore',sumScore) const { success } = await updateScore({ rules_id: Number(params?.id || rulesId), pass_socre: passSocre, sum_score: _sumScore }) //setSumScore(_sumScore) // setUuidPaper(paper?.paper_uuid) // message.success('提交成功'); actionRef.current?.reloadAndRest?.(); handleScoreModalVisible(false) return true; }} > { //alert(0) //const values = setterRef.current?.getData() //console.log('试卷详情::::', 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) // message.success('提交成功'); handlePaperModalVisible(false) return true; }} > {questionTypeValues && questionTypeValues?.map((typeItem, index) => { console.log('questionType:::', typeItem) return <> {questions?.length === 0 &&
暂无数据
} {/* 题型 */}
{numberType[index]}. {typeItem?.typeName} ({typeItem?.count}题)
{/* 试题列表 */}
{questions && questions.map((item, idx) => ( (typeItem?.code === item?.question_type) &&
{questionNumber[item?.question_type]++}. ({typeItem?.typeName},分值{typeItem?.score}){item?.question_stem} {(item?.question_type === 0) && // 单选题
{item?.answers && item?.answers.map((anster, k) => (
{anster?.is_true === '0' && {labels[k]} } {anster?.is_true === '1' && {labels[k]} } {anster?.answer}
))}
} {(item?.question_type === 1) && // 多选题
{item?.answers && item?.answers.map((anster, k) => (
{anster?.is_true === '0' && {labels[k]} } {anster?.is_true === '1' && {labels[k]} } {anster?.answer}
))}
} {(item?.question_type === 2) && // 判断选题
{item?.answers && item?.answers.map((anster, k) => (
{anster?.is_true === '0' && {labels[k]} } {anster?.is_true === '1' && {labels[k]} } {anster?.answer}
))}
}
))}
})}
); };