import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import './index.less'; import { Checkbox, Icon as AntDIcon } 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 = { showTime: true, showNo: true, 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, cb) { this.showModal('confirm', title, desc, cb); } showToast(title, desc, cb) { this.showModal('toast', title, desc, cb); } showModal(type, title, desc, cb) { this.setState({ modal: { type, title, desc, cb } }); } checkAnswer() { const { question } = this.props; const { answer } = this.state; let result = null; if (question.questionType === 'awa' && !answer.awa) result = 'Please answer the question first.'; if (result) return this.showToast(null, result); 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; } next() { const { flow } = this.props; const { answer } = this.state; if (this.checkAnswer()) { flow.submit(answer).then(() => { flow.next(); }); } } render() { const { modal } = 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() : ''}
); } renderContent() { const { question = { content: {} } } = this.props; const { step } = this.state; const { steps = [] } = 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: {} }, singleTime, stageTime, flow } = this.props; if (!userQuestion.id) return null; const { showCalculator, showTime, showNo } = 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}
{ this.setState({ showTime: !showTime }); }} > {showTime && stageTime && `Time left ${formatMinuteSecond(stageTime)}`} {showTime && !stageTime && singleTime && `Time cost ${formatMinuteSecond(singleTime)}`}
{ this.setState({ showNo: !showNo }); }} > {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
{this.renderContent()} {this.renderAnswer()}
Help
flow.toggleFullscreen()} />
this.next()}> Next
); } renderExaminationStart() { // const { paper, userQuestion, singleTime, stageTime, flow } = this.props; const { showTime } = this.state; const { paper, flow, startTime } = this.props; return (
{paper.title}
{ this.setState({ showTime: !showTime }); }} > {showTime && startTime && `Time left ${formatMinuteSecond(startTime)}`}
{/*
{ this.setState({ showNo: !showNo }); }} > {showNo && `${userQuestion.no} of ${paper.questionNumber}`}
*/}
{paper.isAdapt > 1 ? this.renderExaminationStartCAT() : this.renderExaminationStartDefault()}
Help
flow.toggleFullscreen()} />
this.next()}> Next
); } renderExerciseStart() { const { paper, flow, setting } = this.props; const { disorder } = 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, order, orderIndex } = setting; return (
Section Ordering
Select the order in which the exam sections are to be administered.
NOTE: You have 1 minutes to make your selection. If you do not make your selection within 1 minutes, 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 })}> 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, order, orderIndex } = setting; return (
Section Ordering
{ExaminationOrder.map((row, index) => { return
{ this.setState({ order: row.value, orderIndex: index }); }}>
{orderIndex === index && } {row.list.map((r, i) => { return
{ if (order.indexOf(r.value) > 0) { // 取消 order[i] = ''; } else { // 选中 order[i] = r.value; } 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 } = this.props; const { showTime } = this.state; return (
{paper.title}
{ this.setState({ showTime: !showTime }); }} > {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('
:
') }} />
Help
flow.toggleFullscreen()} />
this.next()}> Next
); } renderModal() { const { modal } = this.state; return (
{modal.title}
{modal.desc}
{modal.type === 'confirm' ? (
this.hideModal(true)}> Yes
this.hideModal(false)}> No
) : (
this.hideModal(true)}> Ok
)}
); } }