Commit 021ae48e by zhanghaozhe

ai测试

parent de4e7b07
......@@ -35,12 +35,6 @@ class Exam extends Component {
this.props.history.replace('/ai-test')
}
this.getQuestions()
this.unlisten = this.props.history.listen((location, action) => {
if (action === 'POP') {
this.store.clearAll()
}
this.unlisten()
})
}
componentWillUnmount() {
......@@ -122,15 +116,19 @@ class Exam extends Component {
selectAnswer = (question, optionId) => {
this.setState(state => {
const answer = state.answer
const activeQuestion = state.activeQuestion + 1
setTimeout(() => {
this.setState({
activeQuestion: activeQuestion >= state.questions.length ? state.questions.length - 1 : activeQuestion,
});
}, 200)
answer[question.id] = optionId
return {
answer,
}
}, () => {
const {answer, questions} = this.state
const keys = Object.keys(answer)
const values = Object.values(answer)
if (keys.length === questions.length && values.every(item => item)) {
const {questions, activeQuestion} = this.state
if (activeQuestion === questions.length - 1) {
this.storeData()
}
})
......
......@@ -172,7 +172,7 @@ class scoreReport extends Component {
<tr>
<td>分数</td>
<td>用时</td>
<td>排名</td>
<td>最终排名</td>
</tr>
</thead>
<tbody>
......
......@@ -189,14 +189,14 @@ class Scores extends Component {
<tr>
<th>分数</th>
<th>用时</th>
<th>最终排名</th>
<th>排名</th>
</tr>
</thead>
<tbody>
<tr>
{
userScore.score === '-' ? '-' :
<td>{userScore.score} <Link to={`/ai-test/parse/${userScore.r_id}`}>解析</Link></td>
<td>{userScore.score} <Link to={`/ai-test/analysis/${userScore.r_id}`}>解析</Link></td>
}
<td>{userScore.cost_time}</td>
{
......
......@@ -24,9 +24,14 @@ class SubmitAnswer extends Component {
}
componentDidMount() {
this.setCounter()
if (isEmpty(this.state.answer) || !this.state.recordId) {
this.props.history.replace('/ai-test')
this.store.remove('submitted')
}
if (this.store.get('submitted')) {
this.getAnalysis()
} else {
this.setCounter()
}
}
......@@ -57,15 +62,14 @@ class SubmitAnswer extends Component {
const {answer, recordId} = this.state
http.post(`${API.home}/sys/submit_answer`, {
answer: JSON.stringify(answer),
cost_time: this.state.elapsed,
cost_time: this.state.elapsed * 1000,
record_id: recordId,
}).then(res => {
const {code, msg, data} = res.data
const {code, msg} = res.data
if (code === 200) {
this.store.clearAll()
this.store.set('submitted', true)
clearInterval(this.timer)
this.getAnalysis()
this.props.history.push('/ai-test/report')
} else {
Toast.fail(msg, 2, null, false)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment