Commit 08b54cab by zhanghaozhe

ai测试

parent 7f6decfa
...@@ -7,7 +7,8 @@ import storage from 'store2' ...@@ -7,7 +7,8 @@ import storage from 'store2'
import Navigation from "@components/ai-test/common/navigation" import Navigation from "@components/ai-test/common/navigation"
import { differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays, lightFormat } from "date-fns"; import { differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays, lightFormat } from "date-fns";
import { isEmpty } from 'lodash' import { isEmpty } from 'lodash'
import { connect } from 'react-redux'
import { matchPath } from 'react-router-dom'
class Exam extends Component { class Exam extends Component {
...@@ -30,10 +31,23 @@ class Exam extends Component { ...@@ -30,10 +31,23 @@ class Exam extends Component {
} }
componentDidMount() { componentDidMount() {
const {user, history} = this.props
if (user.hasError) {
return history.push('/passport')
}
if (this.store.get('submitted')) { if (this.store.get('submitted')) {
this.store.remove('submitted') this.store.remove('submitted')
this.props.history.replace('/ai-test') this.props.history.replace('/ai-test')
} }
this.unlisten = history.listen((location) => {
const match = matchPath(location.pathname, {
path: '/ai-test',
})
if (match.isExact) {
this.store.clearAll()
}
this.unlisten && this.unlisten()
})
this.getQuestions() this.getQuestions()
} }
...@@ -202,4 +216,7 @@ class Exam extends Component { ...@@ -202,4 +216,7 @@ class Exam extends Component {
} }
} }
export default Exam; export default connect(
\ No newline at end of file ({user}) => ({user}),
null,
)(Exam);
\ No newline at end of file
...@@ -8,8 +8,27 @@ import Analysis from "@components/ai-test/analysis" ...@@ -8,8 +8,27 @@ import Analysis from "@components/ai-test/analysis"
import Assist from "@components/ai-test/assist" import Assist from "@components/ai-test/assist"
import Help from '@components/ai-test/share' import Help from '@components/ai-test/share'
import Report from '@components/ai-test/report' import Report from '@components/ai-test/report'
import storage from 'store2'
class AiTest extends Component { class AiTest extends Component {
examStore = storage.namespace('aiTestExam')
componentDidMount() {
window.addEventListener('beforeunload', this.handleBeforeUnload)
}
componentWillUnmount() {
this.handleBeforeUnload()
window.removeEventListener('beforeunload', this.handleBeforeUnload)
}
handleBeforeUnload = () => {
this.examStore.clearAll()
}
render() { render() {
const {match} = this.props const {match} = this.props
return ( return (
......
...@@ -12,15 +12,20 @@ class Scores extends Component { ...@@ -12,15 +12,20 @@ class Scores extends Component {
store = storage.namespace('aiTestEntry') store = storage.namespace('aiTestEntry')
state = { state = {
tabs: [ selfTabs: [
{title: '当前成绩'}, {title: '当前成绩'},
{title: '今日最佳'}, {title: '今日最佳'},
{title: '本月最佳'}, {title: '本月最佳'},
], ],
rankList: [], rankList: [],
rankListTabs: [
{title: '日榜'},
{title: '周榜'},
{title: '总榜'},
],
isExpandRankList: false, isExpandRankList: false,
type: 2,
icons: [ icons: [
require('./rank-1.png'), require('./rank-1.png'),
require('./rank-2.png'), require('./rank-2.png'),
...@@ -42,7 +47,7 @@ class Scores extends Component { ...@@ -42,7 +47,7 @@ class Scores extends Component {
componentDidMount() { componentDidMount() {
this.getInitialData() this.getInitialData()
this.getRankList() this.getRankList(null, 0)
this.getUserScores(0) this.getUserScores(0)
this.getUserAddress() this.getUserAddress()
} }
...@@ -73,8 +78,8 @@ class Scores extends Component { ...@@ -73,8 +78,8 @@ class Scores extends Component {
}) })
} }
getRankList = () => { getRankList = (tab, type) => {
http.get(`${API.home}/sys/at/ranks/${this.state.type}`) http.get(`${API.home}/sys/at/ranks/${type}`)
.then(res => { .then(res => {
const {code, msg, data} = res.data const {code, msg, data} = res.data
if (code === 200) { if (code === 200) {
...@@ -151,8 +156,9 @@ class Scores extends Component { ...@@ -151,8 +156,9 @@ class Scores extends Component {
render() { render() {
const { const {
tabs, selfTabs,
rankList, rankList,
rankListTabs,
icons, icons,
isExpandRankList, isExpandRankList,
isShowRule, isShowRule,
...@@ -178,13 +184,12 @@ class Scores extends Component { ...@@ -178,13 +184,12 @@ class Scores extends Component {
}}>规则</a> }}>规则</a>
</div> </div>
{ {
userScore.rank !== '-' &&
<div className="score-list"> <div className="score-list">
<Tabs tabs={tabs} tabBarUnderlineStyle={{display: 'none'}} onChange={(tab, i) => { <Tabs tabs={selfTabs} tabBarUnderlineStyle={{display: 'none'}} onChange={(tab, i) => {
this.getUserScores(i) this.getUserScores(i)
}}> }}>
{ {
tabs.map((tab, index) => { selfTabs.map((tab, index) => {
return <div className={'tab-content'} key={index}> return <div className={'tab-content'} key={index}>
<table> <table>
<thead> <thead>
...@@ -231,7 +236,10 @@ class Scores extends Component { ...@@ -231,7 +236,10 @@ class Scores extends Component {
</div> </div>
</div> </div>
<div className="list"> <div className="list">
<table> <Tabs tabs={rankListTabs} tabBarUnderlineStyle={{display: 'none'}} onChange={this.getRankList}>
{
rankListTabs.map((item, index) => {
return <table key={index}>
<thead> <thead>
<tr> <tr>
<th>名次</th> <th>名次</th>
...@@ -266,6 +274,9 @@ class Scores extends Component { ...@@ -266,6 +274,9 @@ class Scores extends Component {
} }
</tbody> </tbody>
</table> </table>
})
}
</Tabs>
{ {
!isExpandRankList ? !isExpandRankList ?
<div className="expand" onClick={() => { <div className="expand" onClick={() => {
......
...@@ -139,12 +139,13 @@ ...@@ -139,12 +139,13 @@
.head { .head {
height: 68px; height: 68px;
padding-top: 12px; padding-top: 12px;
background-color: $blue-bg;
text-align: center; text-align: center;
color: #fff;
margin-bottom: 15px;
div:nth-child(1) { div:nth-child(1) {
font-size: 18px; font-size: 18px;
color: #0E75E6;
margin-bottom: 5px; margin-bottom: 5px;
} }
...@@ -152,7 +153,7 @@ ...@@ -152,7 +153,7 @@
position: relative; position: relative;
span { span {
color: #666; color: #E5F5FF;
font-size: 12px; font-size: 12px;
} }
...@@ -163,17 +164,17 @@ ...@@ -163,17 +164,17 @@
transform: translateY(-50%); transform: translateY(-50%);
text-decoration: underline; text-decoration: underline;
font-size: 14px; font-size: 14px;
color: #077EE8; color: #fff;
} }
} }
} }
.list { .list {
background: #fff; background: #fff;
padding-top: 11px;
table { table {
width: 100%; width: 100%;
margin-top: 10px;
border-collapse: collapse; border-collapse: collapse;
border-spacing: 0; border-spacing: 0;
border: none; border: 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