Commit 1299fa3c by zhanghaozhe

ai-test

parent c5323308
......@@ -2,25 +2,31 @@ import React, { Component } from 'react';
import './index.scss'
import { HeaderBar } from "@common/index"
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 { Link } from "react-router-dom";
import { connect } from "react-redux";
import Recommends from "@components/ai-test/common/recommends"
import classnames from 'classnames'
import storage from 'store2'
class Assist extends Component {
store = storage.namespace('aiTestAssist')
state = {
question: null,
answer: {},
question: this.store.session.get('question'),
answer: this.store.session.get('answer'),
result: null,
rightAnswer: '',
userAnswer: '',
}
componentDidMount() {
this.getData()
if (!this.store.session.get('question')) {
this.getData()
}
}
getData = () => {
......@@ -29,8 +35,10 @@ class Assist extends Component {
const {code, msg, data} = res.data
if (code === 200) {
const answer = {
[data.id]: undefined,
[data.id]: 0,
}
this.store.session.set('question', data)
this.store.session.set('answer', answer)
this.setState({
question: data,
answer,
......@@ -52,7 +60,11 @@ class Assist extends Component {
submit = () => {
const {history, user} = this.props
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
}
const {question, answer} = this.state
......@@ -66,11 +78,17 @@ class Assist extends Component {
answer_id: answer[question.id],
}).then(res => {
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)
if (code === 200) {
this.setState({
result: data,
});
this.store.session.clearAll()
} else {
Toast.fail(msg, 2, null, false)
}
......@@ -127,24 +145,26 @@ class Assist extends Component {
{
result && question.commend_course && question.commend_course.length && <>
<Recommends recommends={question.commend_course}/>
<div className={classnames(['status', {
</>
}
<div className="btns">
{
result && <div className={classnames(['status', {
end: result.status === 6,
success: result.status === 1,
error: result.status === 2 || result.status === 3 || result.status === 4 || result.status === 5,
}])}>
{result.desc}
</div>
</>
}
<div className="btns">
}
{
!result && <button className={'submit'} onClick={this.submit}>提交</button>
}
{
result && (result.status === 6
? <Link to={'/'} class={'home'}>返回首页</Link>
: <Link to={'/ai-test/scores'} class={'test'}>我也要测试</Link>)
? <Link to={'/'} className={'home'}>返回首页</Link>
: <Link to={'/ai-test/scores'} className={'test'}>我也要测试</Link>)
}
</div>
</div>
......
......@@ -16,7 +16,7 @@
bottom: 0;
left: 0;
width: 100%;
height: 60px;
//height: 60px;
padding: 10px;
background-color: #fff;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.05);
......@@ -26,7 +26,7 @@
color: #fff;
font-size: 18px;
width: 100%;
height: 100%;
height: 40px;
border: 0;
outline: 0;
-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