import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { Carousel, Tooltip } from 'antd'; import { Link } from 'react-router-dom'; import Fullscreen from 'react-fullscreen-crossbrowser'; import './index.less'; import { formatSeconds, formatPercent, formatDate } from '@src/services/Tools'; import Assets from '@src/components/Assets'; import Navigation from '../../../../components/Navigation'; import Tabs from '../../../../components/Tabs'; import Icon from '../../../../components/Icon'; import Switch from '../../../../components/Switch'; import Select from '../../../../components/Select'; import { Button } from '../../../../components/Button'; import AnswerSelect from '../../../../components/AnswerSelect'; import AnswerList from '../../../../components/AnswerList'; import AnswerButton from '../../../../components/AnswerButton'; import AnswerTable from '../../../../components/AnswerTable'; import OtherAnswer from '../../../../components/OtherAnswer'; import { Textarea } from '../../../../components/Input'; import { QuestionNoteModal } from '../../../../components/OtherModal'; import { AskTarget, QrCodeAssets } from '../../../../../Constant'; import { Question } from '../../../../stores/question'; import { My } from '../../../../stores/my'; import { User } from '../../../../stores/user'; import Sentence from '../../process/sentence'; export default class extends Component { constructor(props) { super(props); this.state = { step: 0, hideAnalysis: true, analysisTab: 'official', showAnswer: false, noteField: AskTarget[0].key, showIds: false, }; } note() { const { userQuestion } = this.props; const { questionNo } = userQuestion; const { note } = this.state; if (note) { this.setState({ noteModal: true }); return; } My.getQuestionNote(questionNo.id) .then(result => { this.setState({ note: result || {}, noteModal: true }); }); } prevQuestion() { const { userQuestion, report } = this.props; if (userQuestion.no === 1) return; Question.getDetailByNo(report.id, userQuestion.no - 1).then(r => { linkTo(`/paper/question/${r.id}`); }); } nextQuestion() { const { userQuestion, report } = this.props; if (userQuestion.questionNumber === userQuestion.no) return; Question.getDetailByNo(report.id, userQuestion.no + 1).then(r => { linkTo(`/paper/question/${r.id}`); }); } changeData(type, field, value) { let { data, empty } = this.state; data = data || {}; empty = empty || {}; data[type] = data[type] || {}; data[type][field] = value; empty[type] = empty[type] || {}; if (value) empty[type][field] = !value; this.setState({ data, empty }); } submitAsk() { const { userQuestion, questionNo = {} } = this.props; const { data = {} } = this.state; const { ask = {} } = data; if (!ask.originContent || !ask.content || !ask.target) { this.setState({ empty: { ask: { originContent: !ask.originContent, content: !ask.content, target: !ask.target } } }); return Promise.reject(); } data.ask = {}; return My.addQuestionAsk(userQuestion.id, ask.target, questionNo.id, ask.originContent, ask.content).then(() => { this.setState({ askModal: false, askOkModal: true, data }); }).catch(err => { this.setState({ askError: err.message, data }); }); } submitFeedbackError() { const { questionNo = {} } = this.props; const { data = {} } = this.state; const { feedback = {} } = data; if (!feedback.originContent || !feedback.content || !feedback.target) { this.setState({ empty: { feedback: { originContent: !feedback.originContent, content: !feedback.content, target: !feedback.target } } }); return Promise.reject(); } data.feedback = {}; return My.addFeedbackErrorQuestion( questionNo.id, questionNo.title, feedback.target, feedback.originContent, feedback.content, ) .then(() => { this.setState({ feedbackModal: false, feedbackOkModal: true, data }); }) .catch(err => { this.setState({ feedbackError: err.message, data }); }); } submitNote(close) { const { questionNo = {} } = this.props; const { note = {} } = this.state; My.updateQuestionNote(questionNo.id, note) .then(() => { if (close) this.setState({ noteModal: false }); }) .catch(err => { this.setState({ noteError: err.message }); }); } toggleFullscreen() { const { isFullscreenEnabled } = this.state; this.setState({ isFullscreenEnabled: !isFullscreenEnabled }); } toggleCollect() { const { userQuestion = {}, questionNo = {}, flow } = this.props; if (!userQuestion.collect) { My.addQuestionCollect(questionNo.id).then(() => { userQuestion.collect = true; flow.setState({ userQuestion }); }); } else { My.delQuestionCollect(questionNo.id).then(() => { userQuestion.collect = false; flow.setState({ userQuestion }); }); } } switchNo(no) { linkTo(`/question/detail/${no.id}`); } formatStem(text) { if (!text) return ''; const { question = { content: {} }, userQuestion } = this.props; const { table = {}, questions = [] } = question.content; const { showAnswer } = this.state; 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( , 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; } formatOtherStem(question) { if (!question.stem) return ''; const { content = {}, stem } = question; const { table = {}, questions = [] } = content; let text = stem.replace(/#select#/g, ``); text = text.replace(/#table#/g, ``); setTimeout(() => { const selectList = document.getElementsByClassName(`#select#${question.id}`); const tableList = document.getElementsByClassName(`#table#${question.id}`); for (let i = 0; i < selectList.length; i += 1) { if (!questions[i]) break; ReactDOM.render( , 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; } render() { return ( this.setState({ isFullscreenEnabled })} > {this.renderDetail()} ); } renderDetail() { const { paper = {} } = this.props; switch (paper.paperModule) { case 'sentence': return ; default: return
{this.renderBase()}
; } } renderHeader() { const { userQuestion = {}, questionNo = {}, paper = {}, report = {}, questionNos = [], question = {}, info, detail, } = this.props; const { showIds } = this.state; return (
{detail && (
{paper.paperModule && paper.paperModule !== 'examination' && (
)} {paper.paperModule && paper.paperModule === 'examination' && (
)}
No.{userQuestion.stageNo || userQuestion.no}
{paper.title}
)}
ID:{questionNo.title} {questionNos && questionNos.length > 0 && ( { this.setState({ showIds: true }); }} /> )} {showIds && (

题源汇总

{(questionNos || []).map(row => (

info && this.switchNo(row)}>ID:{row.title}

))}
)}
); } renderBase() { const { questionStatus, userQuestion = {}, questionNo = {}, paper = {}, detail } = this.props; const { showIds } = this.state; return (
{ if (showIds) this.setState({ showIds: false }); }} > {this.renderHeader()}
{this.renderBody()}
User.needLogin().then(() => this.note())}> 笔记 {questionStatus >= 0 && ( { if (questionStatus > 0) { User.needLogin().then(() => { this.setState({ askModal: true, ask: { target: AskTarget[0].value } }); }); } else { this.setState({ askFailModal: true }); } }} > 提问 )} User.needLogin().then(() => this.setState({ feedbackModal: true, feedback: { position: AskTarget[0].value } }))}> 纠错
{detail && (
{userQuestion.no !== 1 && this.prevQuestion()} />} {userQuestion.questionNumber !== userQuestion.no && ( this.nextQuestion()} /> )}
)}
{this.state.askModal && this.renderAsk()} {this.state.askOkModal && this.renderAskOk()} {this.state.askFailModal && this.renderAskFail()} {this.state.feedbackModal && this.renderFeedbackError()} {this.state.feedbackOkModal && this.renderFeedbackErrorOk()} {/* {this.state.noteModal && this.renderNote()} */} this.setState({ noteModal: false, note: data })} onCancel={() => this.setState({ noteModal: false })} />
); } renderBody() { const { question = { content: {} } } = this.props; const { typeset = 'one' } = question.content; const { hideAnalysis, showAnswer } = this.state; const show = typeset === 'one' ? true : !hideAnalysis; return (
{this.renderContent()} {typeset === 'two' && (
{( { this.setState({ showAnswer: value }); }} > {showAnswer ? '显示答案' : '显示答案'} )} {this.renderAnswer()}
)} {question.questionType === 'awa' && this.renderAWA()}
{question.questionType !== 'awa' && this.renderAnalysis()} {typeset === 'two' && question.questionType !== 'awa' && (
this.setState({ hideAnalysis: !hideAnalysis })}> {show ? '收起解析 >' : '查看解析 <'}
)}
); } renderAnalysis() { const { question = { content: {} } } = this.props; const { typeset = 'one' } = question.content; const { hideAnalysis, analysisTab } = this.state; const show = typeset === 'one' ? true : !hideAnalysis; const { showAnswer } = this.state; return (
{ this.setState({ analysisTab: key }); }} />
{typeset === 'two' && (
{ { this.setState({ showAnswer: value }); }} > {showAnswer ? '显示答案' : '显示答案'} } {this.renderAnswer()}
)} {this.renderText()}
); } renderText() { const { question = {}, userQuestion = {} } = this.props; const { asks = [], associations = [] } = userQuestion; const { analysisTab } = this.state; let content; switch (analysisTab) { case 'official': content = (
); break; case 'qx': content =
; break; case 'association': content = (
{associations.filter(row => row).map(association => { const { questions = [], type } = association.content || {}; return
{questions.map((item, index) => { return (
); })}
; })}
); break; case 'qa': content = (
{asks.map((ask, index) => { return ; })}
); break; default: break; } return content; } renderAnswer() { const { question = { content: {} }, userQuestion = {} } = this.props; const { questions = [], type } = question.content; const { showAnswer } = this.state; return questions.map((item, index) => { return (
); }); } renderContent() { const { question = { content: {} } } = this.props; const { typeset = 'one' } = question.content; const { steps = [] } = question.content; const { showAnswer, step } = this.state; return (
{typeset === 'one' && question.questionType !== 'awa' && ( { this.setState({ showAnswer: value }); }} > {showAnswer ? '显示答案' : '显示答案'} )} {question.questionType === 'awa' &&

Analytical Writing Assessment

} {steps.length > 0 && ( this.setState({ step: v })} /> )}
0 ? steps[step].stem : question.stem) }} /> {typeset === 'one' && question.questionType !== 'awa' && this.renderAnswer()}
); } renderAWA() { const { userQuestion } = this.props; const { showAnswer } = this.state; return (
{ this.setState({ showAnswer: value }); }} > {showAnswer ? '显示答案' : '显示答案'}

Your Response

{showAnswer && (
用时: $1$2', ), }} /> {/* 用时:1m39s */} 单词数:{Number((userQuestion.detail || {}).words || 0)}
)} {!showAnswer &&
选择「显示答案」查看自己的作文
}
); } renderAsk() { const { data = {}, empty = {} } = this.state; const { ask = {} } = data; const emptyAsk = empty.ask || {}; return (
提问
我想对