diff --git a/web/src/pages/dashboard/qualification/examAnswer.tsx b/web/src/pages/dashboard/qualification/examAnswer.tsx index a121325..e4f0e65 100644 --- a/web/src/pages/dashboard/qualification/examAnswer.tsx +++ b/web/src/pages/dashboard/qualification/examAnswer.tsx @@ -2,10 +2,10 @@ import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; import { Switch, Button, Card, Col, List, Menu, Progress, Row, Typography, Space, Divider, Radio, Checkbox, Form } from 'antd'; import { PageContainer } from '@ant-design/pro-layout'; -import { useParams, useRequest, history } from 'umi'; +import { useParams, useRequest,history } from 'umi'; import { useEffect, useRef, useState } from 'react'; const { Text, Link } = Typography; -import { getRulesPaper, getPaperQuestionList, finishExamination, getPersonPaperId } from './examAnser'; +import { getRulesPaper, getPaperQuestionList, finishExamination,getPersonPaperId } from './examAnser'; import type { CardListItemDataType } from '../data'; import styles from './style.less'; import cookie from 'react-cookies'; @@ -101,11 +101,11 @@ const CardList = () => { const params = useParams(); const { loading, data } = useRequest(() => { - return getPersonPaperId({ - examination_id: params.examination_id, - person_id: cookie.load('person_id') - }); - }, + return getPersonPaperId({ + examination_id: params.examination_id, + person_id:cookie.load('person_id') + }); + }, { formatResult: (result) => { return result; @@ -132,27 +132,27 @@ const CardList = () => { // 试题列表 const paperList = result.question_list; - const arr = [[], [], []]; - const question_type_count = [ - { count: 0, question_type: 0, type_name: '单选' }, - { count: 0, question_type: 1, type_name: '多选' }, - { count: 0, question_type: 2, type_name: '填空' }, + let arr=[[],[],[]]; + let question_type_count=[ + {count:0,question_type:0,type_name:'单选'}, + {count:0,question_type:1,type_name:'多选'}, + {count:0,question_type:2,type_name:'填空'}, ]; - if (result.question_list.length !== 0) { + if(result.question_list.length!==0){ setRuleId(result.question_list[0].rules_id) - result.question_list.forEach((item) => { - if (item.question_type === 0) { + result.question_list.forEach((item)=>{ + if(item.question_type===0){ arr[0].push(item) - } else if (item.question_type === 1) { + }else if(item.question_type===1){ arr[1].push(item) - } else { + }else { arr[2].push(item) } }) } - question_type_count[0].count = arr[0].length; - question_type_count[1].count = arr[1].length; - question_type_count[2].count = arr[2].length; + question_type_count[0].count=arr[0].length; + question_type_count[1].count=arr[1].length; + question_type_count[2].count=arr[2].length; const qList = question_type_count const questionList: any[] = [] @@ -179,9 +179,7 @@ const CardList = () => { const questionInfo = [] for (let i = 0; i < questionList.length; i++) { questionList[i].children.map((e, index) => { - questionInfo.push({ ...e, index: [i, index] }) - questionList[i].children[index].index = [i, index] - + questionInfo.push({ ...e, index: index }) }) } @@ -205,9 +203,9 @@ const CardList = () => { return result; }, onSuccess: (result, params) => { - if (result.success) { - const time = new Date(timeData).getTime(); - const timeDiff = params.duration / 1000 - time; + if(result.success){ + const time=new Date(timeData).getTime(); + const timeDiff=params.duration/1000-time; // console.log('timeDiff',timeDiff) history.push(`/dashboard/qualification/result/${result.data.pass_score}/${result.data.score}/${result.data.sum_score}/${params.examination_id}/${params.examination_name}/${timeDiff}`); } @@ -304,38 +302,38 @@ const CardList = () => { questionTypeList.map((e, i) => { - return { - // console.log(item, 'list') - return - }} - style={{ background: '#ffffff', margin: '-25px -24px 24px -24px' }} - /> - } + } + onClick={() => { + // 查看解析关闭 + setParsingShow(false) + + paperInfo.map((e) => { + if (e.id === item.id) { + // 重写单选的label、value,index:保存当前试题的index。 + setQuestionNow({ ...item, index: e.index }) + } + }) + + }} + >{index + 1} + }} + style={{ background: '#ffffff', margin: '-25px -24px 24px -24px' }} + /> + } ) @@ -371,32 +369,32 @@ const CardList = () => { {questionNow?.answers?.map((item, index) => { return { - const qArr = [] - // 默认输出答案0,0,0,0 - questionNow?.answers?.map(() => { - qArr.push("0") - - }) - // 修改用户答案 - qArr[index] = item.is_true - - const questionList = questionTypeList - const questionAnswer = qArr.join(",") - // 修改答题卡状态 写入答案以及修改答题状态 - const qX = questionNow?.question_type; - const qI = questionNow?.index; - questionList[questionNow.index[0]].children[questionNow.index[1]].answerSelect = questionAnswer; - // 答题状态 - questionList[questionNow.index[0]].children[questionNow.index[1]].state = 1 - questionList[questionNow.index[0]].children[questionNow.index[1]].answerId = item.id - // 提交答题卡 - setQuestionTypeList(questionList) - - // console.log('0', questionList, questionNow, item, qX, qI) - }} - value={item.id} - style={{ padding: 5, fontSize: 16 }} + onChange={() => { + const qArr = [] + // 默认输出答案0,0,0,0 + questionNow?.answers?.map(() => { + qArr.push("0") + + }) + // 修改用户答案 + qArr[index] = item.is_true + + const questionList = questionTypeList + const questionAnswer = qArr.join(",") + // 修改答题卡状态 写入答案以及修改答题状态 + const qX = questionNow?.question_type; + const qI = questionNow?.index; + questionList[qX].children[qI].answerSelect = questionAnswer; + // 答题状态 + questionList[qX].children[qI].state = 1 + questionList[qX].children[qI].answerId = item.id + // 提交答题卡 + setQuestionTypeList(questionList) + + // console.log('0', questionList, questionNow, item, qX, qI) + }} + value={item.id} + style={{ padding: 5, fontSize: 16 }} >{tiNum(index)}{item.answer} })} @@ -415,10 +413,10 @@ const CardList = () => { // 修改答题卡状态 写入答案以及修改答题状态 const qX = questionNow?.question_type; const qI = questionNow?.index; - questionList[questionNow.index[0]].children[questionNow.index[1]].answerSelect = questionAnswer; + questionList[qX].children[qI].answerSelect = questionAnswer; // 答题状态 - questionList[questionNow.index[0]].children[questionNow.index[1]].state = 1 - questionList[questionNow.index[0]].children[questionNow.index[1]].answerId = e + questionList[qX].children[qI].state = 1 + questionList[qX].children[qI].answerId = e // 提交答题卡 setQuestionTypeList(questionList) @@ -428,8 +426,8 @@ const CardList = () => { return {tiNum(index)}{item.answer} })} @@ -439,31 +437,31 @@ const CardList = () => { {questionNow?.answers?.map((item, index) => { return { - const qArr = [] - // 默认输出答案0,0,0,0 - questionNow?.answers?.map(() => { - qArr.push("0") - }) - // 修改用户答案 - qArr[index] = item.is_true - - const questionList = questionTypeList - const questionAnswer = qArr.join(",") - // 修改答题卡状态 写入答案以及修改答题状态 - const qX = questionNow?.question_type; - const qI = questionNow?.index; - questionList[questionNow.index[0]].children[questionNow.index[1]].answerSelect = questionAnswer; - // 答题状态 - questionList[questionNow.index[0]].children[questionNow.index[1]].state = 1 - questionList[questionNow.index[0]].children[questionNow.index[1]].answerId = item.id - // 提交答题卡 - setQuestionTypeList(questionList) - - // console.log('0', questionList, questionNow, item, qX, qI) - }} - value={item.id} - style={{ padding: 5, fontSize: 16 }} + onChange={() => { + const qArr = [] + // 默认输出答案0,0,0,0 + questionNow?.answers?.map(() => { + qArr.push("0") + }) + // 修改用户答案 + qArr[index] = item.is_true + + const questionList = questionTypeList + const questionAnswer = qArr.join(",") + // 修改答题卡状态 写入答案以及修改答题状态 + const qX = questionNow?.question_type; + const qI = questionNow?.index; + questionList[qX].children[qI].answerSelect = questionAnswer; + // 答题状态 + questionList[qX].children[qI].state = 1 + questionList[qX].children[qI].answerId = item.id + // 提交答题卡 + setQuestionTypeList(questionList) + + // console.log('0', questionList, questionNow, item, qX, qI) + }} + value={item.id} + style={{ padding: 5, fontSize: 16 }} >{tiNum(index)}{item.answer} })} @@ -505,9 +503,9 @@ const CardList = () => { const nextTemp = paperInfo[i - 1] const questionList = questionTypeList let nextData = {} - questionList[nextTemp.index[0]].children.map((item, index) => { + questionList[nextTemp.question_type].children.map((item, index) => { if (item.id === nextTemp.id) { - nextData = item + nextData = { ...item, index: index } } }) setQuestionNow(nextData) @@ -521,44 +519,56 @@ const CardList = () => { block>上一题 + // console.log(nextQuestionData, "下一题") + }}>下一题 + }} + block>提交答卷