import React, { Component } from 'react'; import './index.less'; import Assets from '@src/components/Assets'; import { formatSecond, formatPercent, formatSeconds } from '@src/services/Tools'; import Icon from '../../../../components/Icon'; import Button from '../../../../components/Button'; import Switch from '../../../../components/Switch'; import Tabs from '../../../../components/Tabs'; import Progress from '../../../../components/Progress'; import HardInput from '../../../../components/HardInput'; import AnswerCheckbox from '../../../../components/AnswerCheckbox'; import { SentenceOption } from '../../../../../Constant'; import { Question } from '../../../../stores/question'; export default class extends Component { constructor(props) { super(props); // 确保可以自身进行答案显示,外部也可以直接显示答案 // 将props转入state this.state = { analysisTab: 'qx', focusKey: 'subject', scene: this.props.scene || 'answer', userQuestion: this.props.userQuestion, question: this.props.question, }; const { question, userQuestion } = this.props; if (this.state.scene === 'answer') { this.state.stem = this.formatStem(question.stem, userQuestion.userAnswer, question.answer); } else { this.state.stem = question.stem; } } showAnswer() { const { userQuestion } = this.state; Question.getDetailById(userQuestion.id).then(result => { const { question } = result; this.setState({ userQuestion: result, question: result.question, scene: 'answer', stem: this.formatStem(question.stem, result.userAnswer, question.answer), }); }); } addTarget(target) { const uuid = target.getAttribute('uuid'); if (!uuid) return; const text = target.innerText; const { focusKey, answer = {}, question } = this.state; if (!answer[focusKey]) answer[focusKey] = []; if (answer[focusKey].filter(row => row.uuid === uuid).length > 0) return; answer[focusKey].push({ text, uuid, }); this.setState({ answer, stem: this.formatStem(question.stem, answer), }); } removeTarget(key, target) { const { answer = {}, question } = this.state; if (!answer[key]) return; answer[key] = answer[key].filter(row => row.uuid !== target.uuid); this.setState({ answer, stem: this.formatStem(question.stem, answer), }); } next() { const { flow } = this.props; const { scene } = this.state; if (scene === 'question') { const { answer } = this.state; flow.submit(answer).then(() => { this.showAnswer(); }); } else if (scene === 'answer') { flow.next(); } } formatStem(stem, userAnswer, answer) { // userAnswer 添加蓝色字, 错误的添加红色背景 // answer 添加绿色背景 const uuidMap = {}; const show = !!answer; answer = answer || {}; userAnswer = userAnswer || {}; Object.keys(userAnswer).forEach(key => { if (key === 'options') return; const u = userAnswer[key]; const a = answer[key] && answer[key].length > 0 ? answer[key][0] : []; const map = {}; a.forEach(row => { if (!uuidMap[row.uuid]) uuidMap[row.uuid] = []; uuidMap[row.uuid].push('true'); map[row.uuid] = row; }); u.forEach(row => { if (!uuidMap[row.uuid]) uuidMap[row.uuid] = []; uuidMap[row.uuid].push('user'); if (show && !map[row.uuid]) uuidMap[row.uuid].push('false'); }); }); Object.keys(uuidMap).forEach(uuid => { stem = stem.replace(`uuid='${uuid}'`, `uuid='${uuid}' class='${uuidMap[uuid].join(' ')}'`); }); return stem; } renderHeader() { const { mode } = this.props; switch (mode) { case 'process': return this.renderProcessHeader(); default: return this.renderQuestionHeader(); } } renderProcessHeader() { const { userQuestion, singleTime, paper, flow } = this.props; return (
{paper.title}
Time cost {formatSecond(userQuestion.userTime || singleTime)}
flow.toggleCollect()} />
); } renderQuestionHeader() { const { userQuestion, questionNo, paper, flow } = this.props; return (
{paper.title}
用时: $1$2'), }} /> {/* 用时:1m39s */} 全站: $1$2', ), }} /> {/* 全站:1m39s */} {formatPercent(questionNo.totalCorrect, questionNo.totalNumber)}% flow.toggleCollect()} />
); } render() { const { flow, paper, userQuestion } = this.props; return (
{this.renderHeader()} {this.renderBody()}
flow.toggleFullscreen()} />
{userQuestion.no}/{paper.questionNumber}
); } renderBody() { const { scene } = this.state; switch (scene) { case 'question': return this.renderQuestion(); case 'answer': return this.renderAnswer(); default: return null; } } renderQuestion() { const { question } = this.props; const { focusKey, answer = {} } = this.state; const { stem } = question; return (
请分别找出句子中的主语,谓语和宾语,并做出逻辑关系判断。
{ this.addTarget(e.target); }} />
主语
{ this.setState({ focusKey: 'subject' }); }} onDelete={item => { this.removeTarget('subject', item); }} />
谓语
{ this.setState({ focusKey: 'predicate' }); }} onDelete={item => { this.removeTarget('predicate', item); }} />
宾语
{ this.setState({ focusKey: 'object' }); }} onDelete={item => { this.removeTarget('object', item); }} />
本句存在以下哪种逻辑关系?(可多选)
{ answer.options = values; this.setState({ answer }); }} />
); } renderAnswer() { const { mode } = this.props; const { analysisTab, userQuestion, question, showAnswer, stem } = this.state; const { userAnswer = {} } = userQuestion; const { answer } = question; return (
{mode === 'question' ? ( { this.setState({ showAnswer: value }); }} > {showAnswer ? '显示答案' : '关闭答案'} ) : (
请分别找出句子中的主语,谓语和宾语,并做出逻辑关系判断。
)}
主语
谓语
宾语
本句存在以下哪种逻辑关系?(可多选)
{showAnswer && (
{ this.setState({ analysisTab: key }); }} /> {this.renderText()}
)}
); } renderText() { const { analysisTab, question = {} } = this.state; let content; switch (analysisTab) { case 'chinese': content = (
); break; case 'qx': content =
; break; default: break; } return content; } }