import React from 'react'; import './index.less'; import { Link } from 'react-router-dom'; import Page from '@src/containers/Page'; import { asyncConfirm } from '@src/services/AsyncTools'; import { formatTreeData, getMap } from '@src/services/Tools'; import Continue from '../../../components/Continue'; import Step from '../../../components/Step'; import List from '../../../components/List'; import Tabs from '../../../components/Tabs'; import Module from '../../../components/Module'; import Input from '../../../components/Input'; import Button from '../../../components/Button'; import Division from '../../../components/Division'; import Card from '../../../components/Card'; import ListTable from '../../../components/ListTable'; import ProgressText from '../../../components/ProgressText'; import IconButton from '../../../components/IconButton'; import { Main } from '../../../stores/main'; import { My } from '../../../stores/my'; import { Sentence } from '../../../stores/sentence'; import { Question } from '../../../stores/question'; import { Course } from '../../../stores/course'; import { User } from '../../../stores/user'; const SENTENCE = 'sentence'; const PREVIEW = 'preview'; const PREVIEW_CLASS = 'PREVIEW_CLASS'; const PREVIEW_LIST = 'PREVIEW_LIST'; const exerciseColumns = [ { title: '练习册', width: 250, align: 'left', render: item => { return (
{item.title}
); }, }, { title: '正确率', width: 150, align: 'left', render: item => { return (
--
{item.stat.totalCorrect / item.stat.totalNumber}
); }, }, { title: '全站用时', width: 150, align: 'left', render: item => { return (
--
全站{item.stat.totalTime / item.stat.totalNumber}s
); }, }, { title: '最近做题', width: 150, align: 'left', render: () => { return (
2019-04-28
07:30
); }, }, { title: '操作', width: 180, align: 'left', render: item => { return (
{!item.repport.id && ( this.previewAction('start', item)} /> )} {item.repport.id && ( this.previewAction('continue', item)} /> )} {item.repport.id && ( this.previewAction('restart', item)} /> )}
); }, }, { title: '报告', width: 30, align: 'right', render: item => { return (
{item.report.userNumber === item.report.questionNumber && }
); }, }, ]; export default class extends Page { constructor(props) { super(props); this.sentenceColums = [ { title: '练习册', width: 250, align: 'left', render: row => { return (
{row.title}
); }, }, { title: '正确率', width: 150, align: 'left', render: () => { return (
--
全站55%
); }, }, { title: '全站用时', width: 150, align: 'left', render: () => { return (
55%
全站56s
); }, }, { title: '最近做题', width: 150, align: 'left', render: () => { return (
2019-04-28
07:30
); }, }, { title: '操作', width: 180, align: 'left', render: () => { return (
); }, }, { title: '报告', width: 30, align: 'right', render: () => { return (
); }, }, ]; } initState() { this.code = null; this.columns = exerciseColumns; this.exerciseProcess = {}; this.inited = false; return { tab1: SENTENCE, tab2: '', previewType: PREVIEW_CLASS, tabs: [], allClass: [], classProcess: {}, }; } init() { Main.getExercise().then(result => { const list = result.map(row => { row.title = `${row.titleZh}${row.titleEn}`; row.key = row.extend; return row; }); const tabs = formatTreeData(list, 'id', 'title', 'parentId'); tabs.push({ key: PREVIEW, name: '预习作业' }); const map = getMap(tabs, 'key'); this.setState({ tabs, map }); this.inited = true; this.refreshData(); }); } initData() { const { info = {} } = this.props.user; if (info.latestExercise) { // 获取最后一次做题记录 Question.baseReport(info.latestExercise).then(result => { this.setState({ latest: result }); }); } if (this.inited) this.refreshData(); } refreshData() { const { tab1 } = this.state; switch (tab1) { case SENTENCE: this.refreshSentence(); break; case PREVIEW: this.refreshPreview(); break; default: this.refreshExercise(); } } refreshSentence() { const { sentence, articleMap, paperList } = this.state; if (!sentence) { Sentence.getInfo().then(result => { const chapters = []; const map = {}; let index = 0; let exerciseChapter = null; if (!result.code) { chapters.push(`${index}」试用`); } index += 1; result.chapters.forEach(row => { map[row.value] = row; chapters.push(`「${index}」${row.short}`); index += 1; if (row.exercise) exerciseChapter = row; }); this.setState({ sentence: result, chapters, chapterMap: map, exerciseChapter }); }); } if (!articleMap) { Sentence.listArticle().then(result => { const map = {}; result.forEach(article => { if (!map[article.chapter]) { map[article.chapter] = []; } map[article.chapter].push(article); }); this.setState({ articleMap: map }); }); } if (!paperList) { Sentence.listPaper().then(result => { this.setState({ paperList: result, paperFilterList: result }); }); } } refreshPreview() { const { previewType } = this.state; switch (previewType) { case PREVIEW_LIST: this.refreshListPreview(); break; case PREVIEW_CLASS: default: this.refreshClassProcess(); break; } } refreshClassProcess() { Course.classProcess().then(result => { const classProcess = {}; for (let i = 0; i < result.length; i += 1) { const item = result[i]; classProcess[item.category].push(item); } this.setState({ classProcess }); }); } refreshListPreview() { Question.listPreview().then(result => { this.setState({ previews: result }); }); } refreshExercise() { const { map, tab1 } = this.state; let { tab2 } = this.state; if (!map) { // 等待数据加载 return; } if (tab1 === '') { return; } const subject = map[tab1]; if (tab2 === '') { tab2 = subject.children[0].key; this.onChangeTab(2, tab2); return; } const type = map[tab2]; Main.getExerciseChildren(type.id, true).then(result => { const exerciseChild = result; this.setState({ exerciseChild }); }); Question.getExerciseProcess(type.id).then(r => { const exerciseProcess = getMap(r, 'id'); this.setState({ exerciseProcess }); }); } onChangePreviewType(type) { this.setState({ previewType: type }); this.refreshPreview(); } onChangeTab(level, tab) { const state = {}; state[`tab${level}`] = tab; this.setState(state); this.refresh(); } previewAction(type, item) { switch (type) { case 'start': this.start('preview', item); break; case 'restart': this.restart(item); break; case 'continue': this.continue('preview', item); break; default: break; } } restart(item) { asyncConfirm('提示', '是否重置', () => { Question.restart(item.report.id).then(() => { this.refresh(); }); }); } start(type, item) { linkTo(`/paper/process/${type}/${item.id}`); } continue(type, item) { linkTo(`/paper/process/${type}/${item.id}?r=${item.report.id}`); } activeSentence() { Sentence.active(this.code).then(() => { // 重新获取长难句信息 this.clearSentenceTrail(); this.setState({ sentence: null, articleMap: null, paperList: null }); this.refresh(); }); } trailSentence() { this.setState({ sentenceInput: false }); User.sentenceTrail(); } sentenceRead(article) { linkTo(`/sentence/read?chapter=${article.chapter}&part=${article.part}`); } sentenceFilter() { const { paperList } = this.state; const list = paperList.filter(row => { return !!row; }); this.setState({ paperFilterList: list }); } clearExercise() { My.clearLatestExercise(); this.setState({ latest: null }); } renderView() { const { tab1 = {}, tab2 = {}, tabs, map = {}, latest } = this.state; const children = (map[tab1] || {}).children || []; return (
{latest && ( { this.clearExercise(); }} onContinue={() => { }} onRestart={() => { }} onNext={() => { }} /> )}
{ this.onChangeTab(1, key); }} /> {children.length > 1 && this.onChangeTab(2, key)} />} {tab1 !== SENTENCE && tab1 !== PREVIEW && this.renderExercise()} {tab1 === SENTENCE && this.renderSentence()} {tab1 === PREVIEW && this.renderPreview()}
); } renderPreview() { const { previewType } = this.state; switch (previewType) { case PREVIEW_CLASS: return this.renderPreviewClass(); case PREVIEW_LIST: return this.renderPreviewList(); default: return
; } } renderPreviewClass() { const { allClass, classProcess } = this.state; return (
完成情况
this.onChangePreviewType(PREVIEW_LIST)}> 全部作业 >
{allClass.map(item => { return ; })}
); } renderPreviewList() { const { previews } = this.state; return (
全部作业
this.onChangePreviewType(PREVIEW_CLASS)}> 我的课程 >
); } renderSentence() { const { sentence = {}, sentenceInput } = this.state; const { sentenceTrail } = this.props.user; if (sentenceInput !== true && (sentence.code || sentenceTrail)) { return this.renderSentenceArticle(); } return this.renderInputCode(); } renderSentenceArticle() { const { sentence = {}, chapters, chapter, exerciseChapter = {}, chapterMap = {}, articleMap = {}, paperFilterList = [], paperList = [], paperChecked, } = this.state; const { sentenceTrail } = this.props.user; let maxStep = 0; if (sentenceTrail) { // 试用只能访问第一step maxStep = 1; // 查找练习章节 } const chapterInfo = chapterMap[chapter] || {}; let isExercise = false; if (chapterInfo && chapterInfo.exercise) { isExercise = true; } return (
{sentence.code &&
CODE: {sentence.code}
} {sentenceTrail && (
CODE: 去获取 { this.setState({ sentenceInput: true }); }} > 输入
)} { this.setState({ chapter: step }); }} message="请购买后访问" maxStep={maxStep} /> {/* 正常文章 */} {sentence.code && !isExercise && ( { this.sentenceRead(part); }} /> )} {/* 正常练习 */} {sentence.code && isExercise && ( { console.log(item); this.sentenceFilter(item); }, }, ]} data={paperFilterList} columns={this.sentenceColums} /> )} {/* 试读文章 */} {sentenceTrail && ( { this.sentenceRead(part); }} /> )} {/* 试练 */} {sentenceTrail && ( )}
); } renderInputCode() { return (
输入《千行GMAT长难句》专属 Code,解锁在线练习功能。
{ this.code = value; }} />
什么是CODE? 没有 CODE? 去获取 >> { this.trailSentence(); }} className="right link" > 试用 >>
); } renderExercise() { return
; } }