Commit faaa7322 by zhanghaozhe

Merge branch 'ai-test-merge' into dev

parents 68d80bd2 021ae48e
...@@ -35,12 +35,6 @@ class Exam extends Component { ...@@ -35,12 +35,6 @@ class Exam extends Component {
this.props.history.replace('/ai-test') this.props.history.replace('/ai-test')
} }
this.getQuestions() this.getQuestions()
this.unlisten = this.props.history.listen((location, action) => {
if (action === 'POP') {
this.store.clearAll()
}
this.unlisten()
})
} }
componentWillUnmount() { componentWillUnmount() {
...@@ -122,15 +116,19 @@ class Exam extends Component { ...@@ -122,15 +116,19 @@ class Exam extends Component {
selectAnswer = (question, optionId) => { selectAnswer = (question, optionId) => {
this.setState(state => { this.setState(state => {
const answer = state.answer 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 answer[question.id] = optionId
return { return {
answer, answer,
} }
}, () => { }, () => {
const {answer, questions} = this.state const {questions, activeQuestion} = this.state
const keys = Object.keys(answer) if (activeQuestion === questions.length - 1) {
const values = Object.values(answer)
if (keys.length === questions.length && values.every(item => item)) {
this.storeData() this.storeData()
} }
}) })
......
...@@ -172,7 +172,7 @@ class scoreReport extends Component { ...@@ -172,7 +172,7 @@ class scoreReport extends Component {
<tr> <tr>
<td>分数</td> <td>分数</td>
<td>用时</td> <td>用时</td>
<td>排名</td> <td>最终排名</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
......
...@@ -189,14 +189,14 @@ class Scores extends Component { ...@@ -189,14 +189,14 @@ class Scores extends Component {
<tr> <tr>
<th>分数</th> <th>分数</th>
<th>用时</th> <th>用时</th>
<th>最终排名</th> <th>排名</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
{ {
userScore.score === '-' ? '-' : 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> <td>{userScore.cost_time}</td>
{ {
......
...@@ -24,9 +24,14 @@ class SubmitAnswer extends Component { ...@@ -24,9 +24,14 @@ class SubmitAnswer extends Component {
} }
componentDidMount() { componentDidMount() {
this.setCounter()
if (isEmpty(this.state.answer) || !this.state.recordId) { if (isEmpty(this.state.answer) || !this.state.recordId) {
this.props.history.replace('/ai-test') 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 { ...@@ -57,15 +62,14 @@ class SubmitAnswer extends Component {
const {answer, recordId} = this.state const {answer, recordId} = this.state
http.post(`${API.home}/sys/submit_answer`, { http.post(`${API.home}/sys/submit_answer`, {
answer: JSON.stringify(answer), answer: JSON.stringify(answer),
cost_time: this.state.elapsed, cost_time: this.state.elapsed * 1000,
record_id: recordId, record_id: recordId,
}).then(res => { }).then(res => {
const {code, msg, data} = res.data const {code, msg} = res.data
if (code === 200) { if (code === 200) {
this.store.clearAll()
this.store.set('submitted', true) this.store.set('submitted', true)
clearInterval(this.timer) clearInterval(this.timer)
this.getAnalysis() this.props.history.push('/ai-test/report')
} else { } else {
Toast.fail(msg, 2, null, false) 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