import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import './index.less'; import { Checkbox, Icon as AntDIcon, Tooltip } from 'antd'; import Assets from '@src/components/Assets'; import { formatSeconds, formatMinuteSecond, getMap } from '@src/services/Tools'; import Icon from '../../../../components/Icon'; import Button from '../../../../components/Button'; import Navigation from '../../../../components/Navigation'; import Answer from '../../../../components/Answer'; import Calculator from '../../../../components/Calculator'; import AnswerSelect from '../../../../components/AnswerSelect'; import AnswerTable from '../../../../components/AnswerTable'; import Editor from '../../../../components/Editor'; import { QuestionType, ExaminationOrder } from '../../../../../Constant'; const QuestionTypeMap = getMap(QuestionType, 'value'); export default class extends Component { constructor(props) { super(props); this.state = { showCalculator: false, disorder: false, order: [], step: 0, answer: {}, modal: null, }; } onChangeQuestion(index, value) { const { question } = this.props; const { content } = question; const { answer = {} } = this.state; const type = content.type === 'double' ? 'double' : 'single'; if (!answer.questions) { answer.questions = content.questions.map(() => { return {}; }); } answer.questions[index] = { [type]: value }; console.log(answer); this.setState({ answer }); } onChangeAwa(value) { const { answer = {} } = this.state; answer.awa = value; this.setState({ answer }); } showConfirm(title, desc, width, cb) { this.showModal('confirm', title, desc, width, cb); } showToast(title, desc, width, cb) { this.showModal('toast', title, desc, width, cb); } showModal(type, title, desc, width, cb) { this.setState({ modal: { type, title, desc, width, cb } }); } timeOut(cb) { this.showToast('Time Expired', 'Time has expired for this section. \n Click OK to continue.', 440, cb); } checkAnswer() { const { question } = this.props; const { content } = question; const { answer } = this.state; let title = null; let desc = null; let width = null; if (question.questionType === 'awa') { if (!answer.awa) { desc = 'Please answer the question first.'; } } else { let flag = false; if (!answer || !answer.questions) { flag = true; } else if (content.type === 'double') { answer.questions.forEach((row, index) => { if (flag) return; if (!row.double) { flag = true; return; } const { direction } = content.questions[index]; switch (direction) { case 'landscape': flag = row.double.filter(r => (r || []).filter(rr => rr).length > 0).length < row.double.length; break; case 'portrait': flag = [0, 1].map(r => row.double.filter(rr => rr && rr[r]).length > 0) < 2; break; default: } }); } else if (content.type === 'single') { answer.questions.forEach((row) => { if (flag) return; if (!row.single) { flag = true; return; } flag = row.single.filter(r => r).length === 0; }); } if (flag) { title = 'Answer Required'; desc = 'You can not continue with this question unanswered. '; width = 430; } } if (title || desc) return this.showToast(title, desc, width); return true; } hideModal(b) { if (b) { const { modal = {} } = this.state; if (modal.cb) modal.cb(); } this.setState({ modal: null }); } formatStrem(text) { if (!text) return ''; const { question = { content: {} } } = this.props; const { table = {}, questions = [] } = question.content; text = text.replace(/#select#/g, ""); text = text.replace(/#table#/g, ""); setTimeout(() => { const selectList = document.getElementsByClassName('#select#'); const tableList = document.getElementsByClassName('#table#'); for (let i = 0; i < selectList.length; i += 1) { if (!questions[i]) break; ReactDOM.render( this.onChangeQuestion(i, v)} />, selectList[i], ); } if (table.row && table.col && table.header) { const columns = table.header.map((title, index) => { return { title, key: index }; }); for (let i = 0; i < tableList.length; i += 1) { ReactDOM.render(, tableList[i]); } } }, 1); return text; } showHelp() { this.setState({ showHelp: true }); } next() { const { flow } = this.props; const { answer } = this.state; if (this.checkAnswer()) { this.showConfirm('Answer Confirmation', 'Click Yes to confirm your answer and continue to the next \n question. ', 560, () => { flow.submit(answer).then(() => { return flow.next(); }); }); } } stage() { const { flow } = this.props; flow.relaxToNextStage(); } render() { const { modal, showHelp } = this.state; const { scene, paper } = this.props; let content = null; switch (scene) { case 'start': content = paper.paperModule === 'examination' ? this.renderExaminationStart() : this.renderExerciseStart(); break; case 'relax': content = this.renderRelax(); break; default: content = this.renderDetail(); break; } return (
{content} {modal ? this.renderModal() : ''} {showHelp ? this.renderHelp() : ''}
); } renderContent() { const { question = { content: {} } } = this.props; const { step } = this.state; const { steps = [], typeset = 'one', type } = question.content; return (
{steps.length > 0 && ( this.setState({ step: v })} /> )}
0 ? steps[step].stem : question.stem) }} />
); } renderAnswer() { const { question = { content: {} } } = this.props; const { questions = [], type } = question.content; if (type === 'inline') return ''; return (
{question.questionType === 'awa' && this.onChangeAwa(v)} />} {questions.map((item, index) => { return (
this.onChangeQuestion(index, v)} />
); })}
); } renderDetail() { const { paper, userQuestion, question = { content: {} }, totalTime, stageTime, totalNumber, flow, showTime, showNo } = this.props; if (!userQuestion.id) return null; const { showCalculator } = this.state; const { typeset = 'one' } = question.content; return (
{QuestionTypeMap[question.questionType].long} {question.questionType === 'ir' && ( this.setState({ showCalculator: !showCalculator })} /> )} {/* { flow.toggleCollect(); }} /> */}
flow.toggleCollect()} />
{paper.title}
{ flow.switchTime(); }} > {showTime && stageTime && `Time left ${formatMinuteSecond(stageTime)}`} {showTime && !stageTime && totalTime && `Time cost ${formatMinuteSecond(totalTime)}`}
{ flow.switchNo(); }} > {showNo && `${userQuestion.stageNo} of ${totalNumber}`}
{this.renderContent()} {this.renderAnswer()}
this.showHelp()}> Help
flow.toggleFullscreen()} />
this.next()}> Next
); } renderExaminationStart() { // const { paper, userQuestion, singleTime, stageTime, flow } = this.props; const { paper, flow, startTime, setting, showTime } = this.props; const { disorder = true, order } = setting; return (
{paper.title}
{ flow.switchTime(); }} > {showTime && startTime && `Time left ${formatMinuteSecond(startTime)}`}
{/*
{ this.setState({ showNo: !showNo }); }} > {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
*/}
{paper.isAdapt > 1 ? this.renderExaminationStartCAT() : this.renderExaminationStartDefault()}
this.showHelp()}> Help
flow.toggleFullscreen()} />
flow.start({ disorder: paper.finishTimes > 0 ? disorder : false, order: order.filter(row => row) })}> Next
); } renderExerciseStart() { const { paper, flow, setting } = this.props; const { disorder = true } = setting; return (
{paper.title}
题目总数
{paper.questionNumber}
建议用时
{formatSeconds(paper.time)}
{paper.finishTimes > 0 &&
flow.setSetting({ disorder: !disorder })} /> 题目选项乱序显示
}
); } renderExaminationStartCAT() { const { paper, flow, setting } = this.props; const { disorder = true, order = [], orderIndex } = setting; return (
Section Ordering
Select the order in which the exam sections are to be administered.
NOTE: You have 1 minute to make your selection. If you do not make your selection within 1 minute, the first option listed will be selected and you will view the exam in the following order: Analytical Writing Assessment, Integrated Reasoning, Quantitative, Verbal.
Once you select your section order, you must view ALL questions in each section, in the order you have selected, before moving on to the next section. You will NOT be able to return to this screen.
{ExaminationOrder.map((row, index) => { return
{ flow.setSetting({ order: row.value, orderIndex: index }); }}>
{orderIndex === index && } {row.label}
{row.list.map((r, i) => { return
{i + 1}.{r.label}
; })}
; })}
{paper.finishTimes > 0 &&
flow.setSetting({ disorder: !disorder })} /> 题目选项乱序显示
}
Click{' '}
flow.start({ disorder: paper.finishTimes > 0 ? disorder : false, order: order.filter(row => row) })}> Next
{' '} button to start the exam. You will begin the GMAT exam on the next screen.{' '}
); } renderExaminationStartDefault() { const { paper, flow, setting } = this.props; const { disorder = true, order = [], orderIndex } = setting; const tmp = order.filter(row => row); return (
Section Ordering
{ExaminationOrder.map((row, index) => { return
{ flow.setSetting({ order: row.value, orderIndex: index }); }}>
{orderIndex === index && } {row.list.map((r, i) => { return
{ if (order.indexOf(r.value) >= 0) { // 取消 if (tmp.length > 1) { order[i] = ''; } } else { // 选中 order[i] = r.value; } console.log(order); flow.setSetting({ order }); }}> = 0 : false} /> {r.label}{' '}
; })}
; })}
{paper.finishTimes > 0 &&
flow.setSetting({ disorder: !disorder })} /> 题目选项乱序显示
}
Click{' '}
flow.start({ disorder: paper.finishTimes > 0 ? disorder : false, order: order.filter(row => row) })}> Next
{' '} button to start the exam. You will begin the GMAT exam on the next screen.{' '}
*实战可选择考试顺序但无法选择考试内容。
); } renderRelax() { const { paper, stageTime, flow, showTime } = this.props; return (
{paper.title}
{ flow.switchTime(); }} > {showTime && stageTime && `Time left ${formatMinuteSecond(stageTime)}`} {/* {showTime && singleTime && `Time cost ${formatMinuteSecond(singleTime)}`} */}
{/*
{ this.setState({ showNo: !showNo }); }} > {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
*/}
Optional Break
row.replace(/([0-9])/g, '
$1
')).join('
:
') }} />
this.showHelp()}> Help
flow.toggleFullscreen()} />
this.stage()}> Next
); } renderModal() { const { modal } = this.state; return (
{modal.title}
{modal.desc}
{modal.type === 'confirm' && (
this.hideModal(true)}> Yes
this.hideModal(false)}> No
)} {modal.type === 'toast' && (
this.hideModal(true)}> Ok
)}
); } renderHelp() { return (
Help
this.setState({ showHelp: false })} />
  • 点击右上角的时钟图标
    可以打开和关闭计时器(与实战一致);
  • 点击右上角的进度条
    可以打开和关闭当前进度(与实战一致);
  • 点击右下角
    Next
    进入下一题(与实战一致);
  • 点击右上角的
    可以收藏本题,可至“个人中心-收藏” 查看。
); } }