Commit 86fb6fdb by zhanghaozhe

Merge branch 'ai-test' into pre

parents 8aac73a5 1299fa3c
...@@ -2,25 +2,31 @@ import React, { Component } from 'react'; ...@@ -2,25 +2,31 @@ import React, { Component } from 'react';
import './index.scss' import './index.scss'
import { HeaderBar } from "@common/index" import { HeaderBar } from "@common/index"
import Question from "@components/ai-test/common/question" import Question from "@components/ai-test/common/question"
import { html, http } from "@/utils" import { html, http, browser } from "@/utils"
import { Toast } from "antd-mobile"; import { Toast } from "antd-mobile";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { connect } from "react-redux"; import { connect } from "react-redux";
import Recommends from "@components/ai-test/common/recommends" import Recommends from "@components/ai-test/common/recommends"
import classnames from 'classnames' import classnames from 'classnames'
import storage from 'store2'
class Assist extends Component { class Assist extends Component {
store = storage.namespace('aiTestAssist')
state = { state = {
question: null, question: this.store.session.get('question'),
answer: {}, answer: this.store.session.get('answer'),
result: null, result: null,
rightAnswer: '', rightAnswer: '',
userAnswer: '', userAnswer: '',
} }
componentDidMount() { componentDidMount() {
this.getData() if (!this.store.session.get('question')) {
this.getData()
}
} }
getData = () => { getData = () => {
...@@ -29,8 +35,10 @@ class Assist extends Component { ...@@ -29,8 +35,10 @@ class Assist extends Component {
const {code, msg, data} = res.data const {code, msg, data} = res.data
if (code === 200) { if (code === 200) {
const answer = { const answer = {
[data.id]: undefined, [data.id]: 0,
} }
this.store.session.set('question', data)
this.store.session.set('answer', answer)
this.setState({ this.setState({
question: data, question: data,
answer, answer,
...@@ -52,7 +60,11 @@ class Assist extends Component { ...@@ -52,7 +60,11 @@ class Assist extends Component {
submit = () => { submit = () => {
const {history, user} = this.props const {history, user} = this.props
if (user.hasError) { if (user.hasError) {
history.push('/passport') if (browser.isWeixin) {
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx23dac6775ac82877&redirect_uri=${encodeURIComponent(`${window.location.origin}${location.pathname}?aa=bb`)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
} else {
history.push('/passport')
}
return return
} }
const {question, answer} = this.state const {question, answer} = this.state
...@@ -66,11 +78,17 @@ class Assist extends Component { ...@@ -66,11 +78,17 @@ class Assist extends Component {
answer_id: answer[question.id], answer_id: answer[question.id],
}).then(res => { }).then(res => {
const {code, msg, data} = res.data const {code, msg, data} = res.data
if (answer[question.id] === data.correct_answer) {
Toast.info('回答正确', 2, null, false)
} else {
Toast.info('回答错误', 2, null, false)
}
this.setAnswer(data.correct_answer) this.setAnswer(data.correct_answer)
if (code === 200) { if (code === 200) {
this.setState({ this.setState({
result: data, result: data,
}); });
this.store.session.clearAll()
} else { } else {
Toast.fail(msg, 2, null, false) Toast.fail(msg, 2, null, false)
} }
...@@ -127,24 +145,26 @@ class Assist extends Component { ...@@ -127,24 +145,26 @@ class Assist extends Component {
{ {
result && question.commend_course && question.commend_course.length && <> result && question.commend_course && question.commend_course.length && <>
<Recommends recommends={question.commend_course}/> <Recommends recommends={question.commend_course}/>
<div className={classnames(['status', { </>
}
<div className="btns">
{
result && <div className={classnames(['status', {
end: result.status === 6, end: result.status === 6,
success: result.status === 1, success: result.status === 1,
error: result.status === 2 || result.status === 3 || result.status === 4 || result.status === 5, error: result.status === 2 || result.status === 3 || result.status === 4 || result.status === 5,
}])}> }])}>
{result.desc} {result.desc}
</div> </div>
</> }
}
<div className="btns">
{ {
!result && <button className={'submit'} onClick={this.submit}>提交</button> !result && <button className={'submit'} onClick={this.submit}>提交</button>
} }
{ {
result && (result.status === 6 result && (result.status === 6
? <Link to={'/'} class={'home'}>返回首页</Link> ? <Link to={'/'} className={'home'}>返回首页</Link>
: <Link to={'/ai-test/scores'} class={'test'}>我也要测试</Link>) : <Link to={'/ai-test/scores'} className={'test'}>我也要测试</Link>)
} }
</div> </div>
</div> </div>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
bottom: 0; bottom: 0;
left: 0; left: 0;
width: 100%; width: 100%;
height: 60px; //height: 60px;
padding: 10px; padding: 10px;
background-color: #fff; background-color: #fff;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05); box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
color: #fff; color: #fff;
font-size: 18px; font-size: 18px;
width: 100%; width: 100%;
height: 100%; height: 40px;
border: 0; border: 0;
outline: 0; outline: 0;
-webkit-appearance: none; -webkit-appearance: none;
......
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