Commit 67805b6b by zhanghaozhe

ai测试

parent d1908c5b
......@@ -6282,7 +6282,8 @@
},
"ansi-regex": {
"version": "2.1.1",
"bundled": true
"bundled": true,
"optional": true
},
"aproba": {
"version": "1.2.0",
......@@ -6300,11 +6301,13 @@
},
"balanced-match": {
"version": "1.0.0",
"bundled": true
"bundled": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -6317,15 +6320,18 @@
},
"code-point-at": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true
"bundled": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
......@@ -6428,7 +6434,8 @@
},
"inherits": {
"version": "2.0.3",
"bundled": true
"bundled": true,
"optional": true
},
"ini": {
"version": "1.3.5",
......@@ -6438,6 +6445,7 @@
"is-fullwidth-code-point": {
"version": "1.0.0",
"bundled": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -6450,17 +6458,20 @@
"minimatch": {
"version": "3.0.4",
"bundled": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"bundled": true
"bundled": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
......@@ -6477,6 +6488,7 @@
"mkdirp": {
"version": "0.5.1",
"bundled": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -6549,7 +6561,8 @@
},
"number-is-nan": {
"version": "1.0.1",
"bundled": true
"bundled": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
......@@ -6559,6 +6572,7 @@
"once": {
"version": "1.4.0",
"bundled": true,
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -6634,7 +6648,8 @@
},
"safe-buffer": {
"version": "5.1.2",
"bundled": true
"bundled": true,
"optional": true
},
"safer-buffer": {
"version": "2.1.2",
......@@ -6664,6 +6679,7 @@
"string-width": {
"version": "1.0.2",
"bundled": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -6681,6 +6697,7 @@
"strip-ansi": {
"version": "3.0.1",
"bundled": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
......@@ -6719,11 +6736,13 @@
},
"wrappy": {
"version": "1.0.2",
"bundled": true
"bundled": true,
"optional": true
},
"yallist": {
"version": "3.0.3",
"bundled": true
"bundled": true,
"optional": true
}
}
},
......
......@@ -3,7 +3,6 @@ import './index.scss'
import { HeaderBar } from "@common/index"
import Question from "@components/ai-test/common/question"
import Navigation from "@components/ai-test/common/navigation"
import { withRouter, Link } from "react-router-dom";
import { html, http } from "@/utils"
import { Toast } from "antd-mobile";
import Recommends from '@/components/ai-test/common/recommends'
......@@ -16,7 +15,7 @@ class Analysis extends Component {
activeIndex: 0,
userSelect: '',
rightAnswer: '',
recommends: [],
userUnselect: false,
}
componentDidMount() {
......@@ -29,14 +28,11 @@ class Analysis extends Component {
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.getRecommends(data[0].type_id)
this.setState({
questions: data,
}, () => {
this.getAnswerInfo()
});
} else {
Toast.fail(msg, 2, null, false)
}
......@@ -51,6 +47,7 @@ class Analysis extends Component {
this.setState({
userSelect: String.fromCharCode(65 + userAnswerIndex),
rightAnswer: String.fromCharCode(65 + rightAnswerIndex),
userUnselect: userAnswerIndex < 0,
});
}
......@@ -60,24 +57,8 @@ class Analysis extends Component {
}
}
getRecommends = (typeId) => {
http.post(`${API.home}/sys/get_commend_course`, {
type_id: typeId,
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.setState({
recommends: data,
})
} else {
Toast.fail(msg, 2, null, msg)
}
})
}
render() {
const {questions, activeIndex, userSelect, rightAnswer, recommends} = this.state
const {questions, activeIndex, userSelect, rightAnswer, userUnselect} = this.state
return (
<div className={'analysis-container'}>
<HeaderBar title={'AI水平测试'} arrow={true}/>
......@@ -85,13 +66,14 @@ class Analysis extends Component {
!!questions.length && <Question activeIndex={activeIndex} question={questions[activeIndex]}/>
}
<div style={{height: '8px', backgroundColor: '#f5f5f5'}}></div>
<Navigation questions={questions} isAnalysis={true} handleClick={(index) => {
this.setState({
activeIndex: index,
});
}}/>
<div className="analysis">
<div className="info">您选择的是{userSelect},正确答案是{rightAnswer} 回答{userSelect === rightAnswer ? '正确' : '错误'}</div>
{
userUnselect
? <div className={'info'}>您未作答</div>
: <div className="info">
您选择的是{userSelect},正确答案是{rightAnswer} 回答{userSelect === rightAnswer ? '正确' : '错误'}
</div>
}
<div className="content">
<div className="head">
<i className="icon"></i>
......@@ -106,9 +88,14 @@ class Analysis extends Component {
{
!!questions.length && questions[activeIndex].type_id && <Recommends typeId={questions[activeIndex].type_id}/>
}
<Navigation questions={questions} isAnalysis={true} handleClick={(index) => {
this.setState({
activeIndex: index,
});
}}/>
</div>
);
}
}
export default withRouter(Analysis);
\ No newline at end of file
export default Analysis;
\ No newline at end of file
......@@ -4,9 +4,8 @@ import { HeaderBar } from "@common/index"
import Question from "@components/ai-test/common/question"
import { html, http } from "@/utils"
import { Toast } from "antd-mobile";
import { withRouter, Link } from "react-router-dom";
import { Link } from "react-router-dom";
import { connect } from "react-redux";
import { compose } from "redux";
import Recommends from "@components/ai-test/common/recommends"
import classnames from 'classnames'
......@@ -147,10 +146,7 @@ class Assist extends Component {
}
}
export default compose(
connect(
export default connect(
state => state.user,
null,
),
withRouter,
)(Assist);
\ No newline at end of file
)(Assist)
\ No newline at end of file
......@@ -8,11 +8,14 @@ const Navigation = ({questions, answer, handleClick, isAnalysis}) => {
<ul>
{
!!questions.length && questions.map((item, index) => {
const userSelectIndex = item.options.findIndex(item => item.user_select)
const rightAnswerIndex = item.options.findIndex(item => item.is_ans)
return <li key={index} onClick={handleClick.bind(this, index)}
className={classnames({
active: answer && answer[item.id],
correct: isAnalysis && item.options.some(item => item.is_ans && item.user_select),
error: isAnalysis && item.options.some(item => item.user_select && !item.is_ans),
correct: isAnalysis && userSelectIndex === rightAnswerIndex,
error: isAnalysis && userSelectIndex >= 0 && userSelectIndex !== rightAnswerIndex,
unselect: isAnalysis && userSelectIndex < 0,
})}>{index + 1}</li>
})
}
......
......@@ -40,8 +40,13 @@
&.error {
border-color: #E64949;
color: #fff;
background-color: #E64949;
}
&.unselect {
border: 1px solid #E64949;
color: #E64949;
//background-color: #E64949;
}
}
}
import React, { Component } from 'react';
import './index.scss'
import Question from '../common/question'
import { HeaderBar } from "@common/index"
import { browser, getParam, http } from "@/utils"
import { Toast } from 'antd-mobile'
import { withRouter } from 'react-router-dom'
import storage from 'store2'
import Navigation from "@components/ai-test/common/navigation"
import { differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays, lightFormat } from "date-fns";
import { isEmpty } from 'lodash'
class Exam extends Component {
......@@ -18,42 +19,47 @@ class Exam extends Component {
questions: [],
activeQuestion: 0,
time: {
d: 0,
h: 0,
m: 0,
s: 0,
},
elapsed: 0,
answer: {},
recordId: undefined,
}
componentDidMount() {
if (this.store.get('submitted')) {
this.store.remove('submitted')
this.props.history.replace('/ai-test')
}
this.getQuestions()
this.unlisten = this.props.history.listen((location, action) => {
if (action === 'POP' && location.pathname === '/ai-test/scores') {
this.unlisten()
if (action === 'POP') {
this.store.clearAll()
}
this.unlisten()
})
}
componentWillUnmount() {
clearInterval(this.timer)
}
setCounter = () => {
this.timer = setInterval(() => {
this.setState(state => {
const time = state.time
if (time.s + 1 >= 60) {
time.s = 0
if (time.m + 1 >= 60) {
time.h = time.h + 1
time.m = 0
} else {
time.m = time.m + 1
}
} else {
time.s = time.s + 1
}
const s = state.elapsed + 1
return {
time,
time: {
d: Math.floor(s / (60 * 60 * 24)),
h: Math.floor(s / (60 * 60)) % 24,
m: Math.floor(s / 60) % 60,
s: s % 60,
},
elapsed: s,
}
})
}, 1000)
......@@ -78,23 +84,18 @@ class Exam extends Component {
.then(res => {
const {code, msg, data} = res.data
if (code === 200) {
let answer = this.store.get('answer') || {}, time = this.store.get('time')
if (!answer) {
let answer = this.store.get('answer') || {}
if (isEmpty(answer)) {
data.forEach(item => {
answer[item.id] = undefined
answer[item.id] = 0
})
}
if (!time) {
time = {h: 0, m: 0, s: 0}
}
this.setState({
questions: data,
answer,
time,
recordId: data[0].record_id,
})
this.getStartTime(data[0].create_time)
this.setCounter()
} else if (code === 23007) {
this.props.history.replace('/ai-test/scores')
......@@ -104,6 +105,20 @@ class Exam extends Component {
})
}
getStartTime = (timestamp) => {
const now = new Date()
const createTime = new Date(timestamp * 1000)
this.setState({
time: {
d: differenceInDays(now, createTime),
h: differenceInHours(now, createTime) % 24,
m: differenceInMinutes(now, createTime) % 60,
s: differenceInSeconds(now, createTime) % 60,
},
elapsed: differenceInSeconds(now, createTime),
});
}
selectAnswer = (question, optionId) => {
this.setState(state => {
const answer = state.answer
......@@ -116,13 +131,18 @@ class Exam extends Component {
const keys = Object.keys(answer)
const values = Object.values(answer)
if (keys.length === questions.length && values.every(item => item)) {
this.storeData()
}
})
}
storeData = () => {
const {answer, time, recordId, elapsed} = this.state
const {history} = this.props
clearInterval(this.timer)
const {time, answer, recordId} = this.state
this.store.setAll({time, answer, recordId})
this.store.setAll({time, answer, recordId, elapsed})
history.push('/ai-test/submit')
}
})
}
render() {
......@@ -137,13 +157,32 @@ class Exam extends Component {
<i className={'iconfont iconzhong'}></i>
<span>
{
!!time.d && time.d
}
{
!!time.h && <>{time.h && time.h.toString().padStart(2, '0')}:</>
}
{time.m.toString().padStart(2, '0')}:
{time.s.toString().padStart(2, '0')}
</span>
</div>
{/*
<div className="time">
<i className={'iconfont iconzhong'}></i>
<span>
{
!!time.d && time.d
}
{
!!time.h && <>{time.h && time.h.toString().padStart(2, '0')}:</>
}
{time.m.toString().padStart(2, '0')}:
{time.s.toString().padStart(2, '0')}
</span>
</div>
<div className="count">{Object.values(answer).filter(item => item).length}/{questions.length}</div>
*/}
<div className="count"
onClick={this.storeData}>{Object.values(answer).filter(item => item).length}/{questions.length}</div>
</header>
<div className="banner">
<img src="https://julyedu-cdn.oss-cn-beijing.aliyuncs.com/ai-test/m/scores/exam-banner.png" alt=""/>
......@@ -151,7 +190,8 @@ class Exam extends Component {
<div className="question-section">
{
!!questions.length &&
<Question activeIndex={activeQuestion} question={questions[activeQuestion]} selectAnswer={this.selectAnswer} answer={answer}></Question>
<Question activeIndex={activeQuestion} question={questions[activeQuestion]} selectAnswer={this.selectAnswer}
answer={answer}></Question>
}
</div>
<Navigation questions={questions} answer={answer} handleClick={(index) => {
......@@ -164,4 +204,4 @@ class Exam extends Component {
}
}
export default withRouter(Exam);
\ No newline at end of file
export default Exam;
\ No newline at end of file
......@@ -4,29 +4,23 @@ import { Switch, Route } from 'react-router-dom'
import Scores from './scores'
import Exam from './exam'
import SubmitAnswer from "@components/ai-test/submit-answer"
import Parse from "@components/ai-test/analysis"
import Analysis from "@components/ai-test/analysis"
import Assist from "@components/ai-test/assist"
import Help from '@components/ai-test/share'
import Report from '@components/ai-test/report'
class AiTest extends Component {
render() {
const {match} = this.props
return (
<Switch>
<Route path={`${match.path}/scores`}>
<Scores/>
</Route>
<Route path={`${match.path}/exam`}>
<Exam/>
</Route>
<Route path={`${match.path}/submit`}>
<SubmitAnswer/>
</Route>
<Route path={`${match.path}/parse/:recordId`}>
<Parse/>
</Route>
<Route path={`${match.path}/assist/:assistCode`}>
<Assist/>
</Route>
<Route path={`${match.path}/exam`} render={props => <Exam {...props}/>}/>
<Route path={`${match.path}/submit`} render={props => <SubmitAnswer {...props}/>}/>
<Route path={`${match.path}/analysis/:recordId`} render={props => <Analysis {...props}/>}/>
<Route path={`${match.path}/assist/:assistCode`} render={props => <Assist {...props}/>}/>
<Route path={`${match.path}/share`} render={props => <Help {...props}/>}/>
<Route path={`${match.path}/report`} render={props => <Report {...props}/>}/>
<Route render={(props) => <Scores {...props}/>}/>
</Switch>
);
}
......
......@@ -5,7 +5,7 @@ import { http } from "@/utils"
import storage from 'store2'
import { html } from '@/utils'
import { compareDesc } from "date-fns";
import { withRouter, Link } from "react-router-dom";
import { Link } from "react-router-dom";
class Scores extends Component {
......@@ -161,7 +161,7 @@ class Scores extends Component {
isShowUserAddress,
userAddress,
} = this.state
const _rankList = isExpandRankList ? rankList : rankList.slice(0, 10)
const _rankList = Array.isArray(rankList) ? isExpandRankList ? rankList : rankList.slice(0, 10) : []
return (
<div className={'scores'}>
<div className="banner">
......@@ -176,7 +176,7 @@ class Scores extends Component {
}}>规则</a>
</div>
{
!!userScore.r_id &&
userScore.rank !== '-' &&
<div className="score-list">
<Tabs tabs={tabs} tabBarUnderlineStyle={{display: 'none'}} onChange={(tab, i) => {
this.getUserScores(i)
......@@ -205,7 +205,7 @@ class Scores extends Component {
}
</Tabs>
<div className="share">
<a href="javascript:void(0);">分享</a>
<Link to={'/ai-test/report'}>分享</Link>
</div>
</div>
}
......@@ -294,7 +294,9 @@ class Scores extends Component {
isShowRule: true,
})
}}>开始测试<span>(今日可测试{pageState.daily_test_num}次)</span></button>
: <button className={'get-chance'}>获取测试机会<span>(今日可测试0次)</span></button>
: <Link to={'/ai-test/share'}>
<button className={'get-chance'}>获取测试机会<span>(今日可测试0次)</span></button>
</Link>
: <button className={'unavailable'}>活动已结束</button>
}
</div>
......@@ -353,4 +355,4 @@ function Rule({neverShow, isNeverShow, rule, close, startTest}) {
}
export default withRouter(Scores);
\ No newline at end of file
export default Scores;
\ No newline at end of file
import React, {Component} from 'react'
import {CopyToClipboard} from 'react-copy-to-clipboard'
import {browser, http, getParam, wxShare} from '@/utils'
import {browser, http, wxShare} from '@/utils'
import './index.scss'
import {Toast} from "antd-mobile"
class aiTestHelp extends Component {
constructor(props) {
......
......@@ -4,41 +4,91 @@ import { HeaderBar } from "@common/index"
import storage from 'store2'
import { Toast } from "antd-mobile";
import { http } from "@/utils"
import classnames from 'classnames'
import { Link } from "react-router-dom";
import { isEmpty } from 'lodash'
class SubmitAnswer extends Component {
store = storage.namespace('aiTestExam')
timer = null
state = {
time: this.store.get('time') || {h: 0, m: 0, s: 0},
time: this.store.get('time') || {d: 0, h: 0, m: 0, s: 0},
answer: this.store.get('answer'),
recordId: this.store.get('recordId'),
analysis: [],
results: [],
elapsed: this.store.get('elapsed'),
}
componentDidMount() {
this.setCounter()
if (isEmpty(this.state.answer) || !this.state.recordId) {
this.props.history.replace('/ai-test')
}
}
componentWillUnmount() {
clearInterval(this.timer)
}
setCounter = () => {
this.timer = setInterval(() => {
this.setState(state => {
const s = state.elapsed + 1
return {
time: {
d: Math.floor(s / (60 * 60 * 24)),
h: Math.floor(s / (60 * 60)) % 24,
m: Math.floor(s / 60) % 60,
s: s % 60,
},
elapsed: s,
}
})
}, 1000)
}
submit = () => {
const {answer, recordId} = this.state
http.post(`${API.home}/sys/submit_answer`, {
answer: answer,
cost_time: this.getCostTime(),
answer: JSON.stringify(answer),
cost_time: this.state.elapsed,
record_id: recordId,
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.store.clearAll()
this.store.set('submitted', true)
clearInterval(this.timer)
this.getAnalysis()
} else {
Toast.fail(msg, 2, null, false)
}
})
}
getCostTime = () => {
const {time} = this.state
return parseInt(time.h) * 60 * 60 * 1000 + parseInt(time.m) * 60 * 1000 + parseInt(time.s) * 1000
getAnalysis = () => {
http.post(`${API.home}/sys/get_analysis`, {
record_id: this.state.recordId,
}).then(res => {
const {code, msg, data} = res.data
if (code === 200) {
this.setState({
analysis: data,
});
} else {
Toast.fail(msg, 2, null, false)
}
})
}
render() {
const {time, answer} = this.state
const {time, answer, analysis, recordId} = this.state
return (
<div className={'submit-answer'}>
<HeaderBar title={'提交试卷'} arrow={true}/>
......@@ -46,12 +96,40 @@ class SubmitAnswer extends Component {
<div className="cost">用时:
<span>
{
!!time.d && time.d
}
{
!!time.h && <>{time.h && time.h.toString().padStart(2, '0')}:</>
}
{time.m.toString().padStart(2, '0')}:
{time.s.toString().padStart(2, '0')}
</span>
</div>
{
analysis.length
? <>
<ul className={'answers'}>
{
analysis.map((item, index) => {
const userSelectIndex = item.options.findIndex(item => item.user_select)
const rightAnswerIndex = item.options.findIndex(item => item.is_ans)
return <li key={item.id}
className={classnames({
correct: userSelectIndex === rightAnswerIndex,
wrong: userSelectIndex >= 0 && userSelectIndex !== rightAnswerIndex,
unselect: userSelectIndex < 0,
})}>{index + 1}</li>
})
}
</ul>
{
!!analysis.length && <div className={'score'}>总分:{analysis[0].score}</div>
}
<Link to={`/ai-test/analysis/${recordId}`}>
<button>查看解析</button>
</Link>
</>
: <>
<ul className={'answers'}>
{
answer && !!Object.keys(answer).length && Object.keys(answer).map((item, index) => {
......@@ -60,6 +138,8 @@ class SubmitAnswer extends Component {
}
</ul>
<button onClick={this.submit}>提交</button>
</>
}
</div>
</div>
);
......
......@@ -73,8 +73,32 @@ html, body {
background-color: #09f;
color: #fff;
}
&.wrong {
background-color: #E64949;
border-color: #E64949;
color: #fff;
}
&.unselect {
border: 1px solid #E64949;
color: #E64949;
}
&.correct {
background-color: #2CDBAF;
border-color: #2CDBAF;
color: #fff;
}
}
}
.score {
margin-bottom: 30px;
font-size: 21px;
color: #09f;
text-align: center;
}
button {
width: 343px;
......
......@@ -335,14 +335,4 @@ export default [
path: '/ai-test',
component: loadable(() => import('@/components/ai-test')),
},
// AI水平测试 成绩报告
{
path: '/scoreReport',
component: loadable(() => import('@/components/scoreReport'))
},
// AI水平测试 邀请好友助力
{
path: '/aiTestHelp',
component: loadable(() => import('@/components/aiTestHelp'))
}
]
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