| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- 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 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 { Sentence } from '../../../stores/sentence';
- import { Question } from '../../../stores/question';
- // import { Course } from '../../../stores/course';
- const SENTENCE = 'sentence';
- const PREVIEW = 'preview';
- const PREVIEW_CLASS = 'PREVIEW_CLASS';
- const PREVIEW_LIST = 'PREVIEW_LIST';
- const columns = [
- {
- title: '练习册',
- width: 250,
- align: 'left',
- render: item => {
- return (
- <div className="table-row">
- <div className="night f-s-16">{item.title}</div>
- <div>
- <ProgressText
- progress={item.report.id ? item.repport.userNumber / item.report.questionNumber : 0}
- size="small"
- />
- </div>
- </div>
- );
- },
- },
- {
- title: '正确率',
- width: 150,
- align: 'left',
- render: item => {
- return (
- <div className="table-row">
- <div className="night f-s-16 f-w-b">--</div>
- <div className="f-s-12">{item.stat.totalCorrect / item.stat.totalNumber}</div>
- </div>
- );
- },
- },
- {
- title: '全站用时',
- width: 150,
- align: 'left',
- render: item => {
- return (
- <div className="table-row">
- <div className="night f-s-16 f-w-b">--</div>
- <div className="f-s-12">全站{item.stat.totalTime / item.stat.totalNumber}s</div>
- </div>
- );
- },
- },
- {
- title: '最近做题',
- width: 150,
- align: 'left',
- render: () => {
- return (
- <div className="table-row">
- <div>2019-04-28</div>
- <div>07:30</div>
- </div>
- );
- },
- },
- {
- title: '操作',
- width: 180,
- align: 'left',
- render: item => {
- return (
- <div className="table-row p-t-1">
- {!item.repport.id && (
- <IconButton type="start" tip="Start" onClick={() => this.previewAction('start', item)} />
- )}
- {item.repport.id && (
- <IconButton
- className="m-r-2"
- type="continue"
- tip="Continue"
- onClick={() => this.previewAction('continue', item)}
- />
- )}
- {item.repport.id && (
- <IconButton type="restart" tip="Restart" onClick={() => this.previewAction('restart', item)} />
- )}
- </div>
- );
- },
- },
- {
- title: '报告',
- width: 30,
- align: 'right',
- render: item => {
- return (
- <div className="table-row p-t-1">
- {item.report.userNumber === item.report.questionNumber && <IconButton type="report" tip="Report" />}
- </div>
- );
- },
- },
- ];
- export default class extends Page {
- initState() {
- this.code = null;
- this.columns = columns;
- this.exerciseProcess = {};
- return {
- tab1: PREVIEW,
- tab2: '',
- previewType: PREVIEW_CLASS,
- tabs: [],
- allClass: [],
- classProcess: {},
- };
- }
- initData() {
- 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);
- tabs.push({ key: PREVIEW, name: '预习作业' });
- const map = getMap(tabs, 'key');
- this.setState({ tabs, map });
- });
- this.refresh();
- }
- refresh() {
- const { tab1 } = this.state;
- switch (tab1) {
- case SENTENCE:
- this.refreshSentence();
- break;
- case PREVIEW:
- this.refreshPreview();
- break;
- default:
- this.refreshExercise();
- }
- }
- refreshSentence() {
- Sentence.getInfo().then(result => {
- this.setState({ sentence: result });
- });
- Sentence.listArticle().then(result => {
- const articleMap = {};
- result.forEach((article) => {
- if (!articleMap[article.chapter]) {
- articleMap[article.chapter] = [];
- }
- articleMap[article.chapter].push(article);
- });
- this.setState({ articleMap });
- });
- }
- refreshPreview() {
- const { previewType } = this.state;
- switch (previewType) {
- case PREVIEW_LIST:
- this.refreshListPreview();
- break;
- case PREVIEW_CLASS:
- default:
- this.refreshClassProcess();
- break;
- }
- }
- refreshClassProcess() {
- Question.getClassProcess().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;
- 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.refresh();
- });
- }
- renderView() {
- const { tab1 = {}, tab2 = {}, tabs, map = {} } = this.state;
- const children = (map[tab1] || {}).children || [];
- return (
- <div>
- <div className="content">
- <Module className="m-t-2">
- <Tabs type="card" active={tab1} tabs={tabs} onChange={key => {
- this.onChangeTab(1, key);
- }} />
- {children.length > 1 && <Tabs active={tab2} tabs={children} onChange={key => this.onChangeTab(2, key)} />}
- </Module>
- {tab1 !== SENTENCE && tab1 !== PREVIEW && this.renderExercise()}
- {tab1 === SENTENCE && this.renderSentence()}
- {tab1 === PREVIEW && this.renderPreview()}
- </div>
- </div>
- );
- }
- renderPreview() {
- const { previewType } = this.state;
- switch (previewType) {
- case PREVIEW_CLASS:
- return this.renderPreviewClass();
- case PREVIEW_LIST:
- return this.renderPreviewList();
- default:
- return <div />;
- }
- }
- renderPreviewClass() {
- const { allClass, classProcess } = this.state;
- return (
- <div className="work-body">
- <div className="work-nav">
- <div className="left">完成情况</div>
- <div className="right theme c-p" onClick={() => this.onChangePreviewType(PREVIEW_LIST)}>
- 全部作业 >
- </div>
- </div>
- <Division col="3">
- {allClass.map(item => {
- return <Card data={item} process={classProcess[item.id]} previewAction={this.previewAction} />;
- })}
- </Division>
- </div>
- );
- }
- renderPreviewList() {
- const { previews } = this.state;
- return (
- <div className="work-body">
- <div className="work-nav">
- <div className="left">全部作业</div>
- <div className="right theme c-p" onClick={() => this.onChangePreviewType(PREVIEW_CLASS)}>
- 我的课程 >
- </div>
- </div>
- <ListTable
- filters={[
- {
- type: 'radio',
- checked: 'today',
- list: [{ key: 'today', title: '今日需完成' }, { key: 'tomorrow', title: '明日需完成' }],
- },
- {
- type: 'radio',
- checked: 'unfinish',
- list: [{ key: 'unfinish', title: '未完成' }, { key: 'finish', title: '已完成' }],
- },
- { type: 'select', checked: 'all', list: [{ key: 'all', title: '全部' }] },
- ]}
- data={previews}
- columns={this.columns}
- />
- </div>
- );
- }
- renderSentence() {
- const { sentence = {}, trail = false } = this.state;
- if (sentence.code || trail) {
- return this.renderSentenceArticle();
- }
- return this.renderInputCode();
- }
- renderSentenceArticle() {
- // const { sentence = {}, trail } = this.state;
- return <div />;
- }
- renderInputCode() {
- return (
- <Module className="code-module">
- <div className="title">输入《千行GMAT长难句》专属 Code,解锁在线练习功能。</div>
- <div className="input-block">
- <Input size="lager" placeholder="请输入CODE" onChange={(value) => {
- this.code = value;
- }} />
- <Button size="lager" onClick={() => {
- this.activeSentence();
- }}>解锁</Button>
- </div>
- <div className="tip">
- <Link to="/" className="left link">
- 什么是CODE?
- </Link>
- <span>没有 CODE?</span>
- <Link to="/" className="link">
- 去获取 >>
- </Link>
- <a onClick={() => {
- this.setState({ trail: true });
- }} className="right link">
- 试用 >>
- </a>
- </div>
- </Module>
- );
- }
- renderExercise() {
- return <div />;
- }
- }
|