import React from 'react'; import ReactDOM from 'react-dom'; import './index.less'; import { Checkbox } from 'antd'; import Assets from '@src/components/Assets'; import Page from '@src/containers/Page'; 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 { Question } from '../../../stores/question'; import Editor from '../../../components/Editor'; export default class extends Page { initState() { return { showCalculator: false, start: !this.props.core.query.r, reportId: this.props.core.query.r, type: this.props.core.query.type, disorder: false, step: 0, info: {}, reportInfo: {}, questionInfo: {}, answer: {}, modal: null, }; } initData() { const { start } = this.state; Question.getPaper(this.params.id).then(result => { this.setState({ info: result }); }); if (!start) { this.continue(); } } onChangeQuestion(index, value) { const { question = {}, answer = {} } = this.state; answer.questions[index] = { [question.type]: value }; this.setState({ answer }); } onChangeAwa(value) { const { answer = {} } = this.state; answer.awa = value; this.setState({ answer }); } start() { const { type, info, disorder } = this.state; Question.start(type, info.id, disorder).then(result => { this.setState({ reportInfo: result }); this.next(); }); } continue() { const { reportId } = this.state; Question.continue(reportId).then(result => { this.setState({ reportInfo: result }); this.next(); }); } next() { const { reportInfo } = this.state; Question.next(reportInfo.id).then(result => { this.setState({ questionInfo: result, question: result.question, answer: { questions: [], subject: [], predicate: [], object: [], options: [], awa: '' }, }); }); } submit() { const { question, answer } = this.state; if (!this.checkAnswer()) return; Question.submit(question.questionNoId, answer).then(() => { this.next(); }); } finish() { const { reportInfo } = this.state; Question.finish(reportInfo.id).then(() => { this.showToast(null, 'Complete!', () => { goBack(); }); }); } 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, answer } = this.state; let result = null; if (question.type === '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.state; 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) { ReactDOM.render( this.onChangeQuestion(i, v)} />, selectList[i], ); } for (let i = 0; i < tableList.length; i += 1) { ReactDOM.render(, tableList[i]); } }, 1); return text; } renderView() { const { start } = this.state; if (start) return this.renderStart(); return this.renderDetail(); } renderContent() { const { question = { content: {} }, step } = this.state; const { steps = [] } = question.content; return (
{steps.length > 0 && {}} />}
{this.formatStrem(steps.length > 0 ? steps[step].stem : question.stem)}
); } renderAnswer() { const { question = { content: {} } } = this.state; const { questions = [] } = question.content; if (question.type === 'inline') return ''; return (
{question.type === 'awa' && this.onChangeAwa(v)} />} {questions.map((item, index) => { return (
{item.description}
this.onChangeQuestion(index, v)} />
); })}
); } renderDetail() { const { modal, showCalculator, info, question = { content: {} } } = this.state; const { typeset = 'one' } = question.content; return (
Analytical Writing Assessment this.setState({ showCalculator: !showCalculator })} />
{info.title}
Time left 00:02
{question.no} of {info.questionNumer}
{this.renderContent()} {this.renderAnswer()}
Help
this.next()}> Next
{modal ? this.renderModal() : ''}
); } renderStart() { const { info, disorder, modal } = this.state; return (
{info.title}
题目总数
{info.questionNumer}
建议用时
{info.time}
this.setState({ disorder: !disorder })} /> 题目选项乱序显示
{modal ? this.renderModal() : ''}
); } 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
)}
); } }