import React, { Component } from 'react';
import './index.less';
import { Icon, Checkbox } from 'antd';
import Page from '@src/containers/Page';
import Assets from '@src/components/Assets';
import { timeRange, getMap, formatPercent, formatMonth, formatDate, formatSeconds } from '@src/services/Tools';
import UserLayout from '../../../layouts/User';
import UserTable from '../../../components/UserTable';
import UserAction from '../../../components/UserAction';
import { RealAuth } from '../../../components/OtherModal';
import Examination from '../../../components/Examination';
import VipRenew from '../../../components/VipRenew';
import menu, { refreshQuestionType } from '../index';
import Tabs from '../../../components/Tabs';
import Modal from '../../../components/Modal';
import Select from '../../../components/Select';
import GIcon from '../../../components/Icon';
import { TimeRange, QuestionType, PrepareStatus, ExperiencePercent } from '../../../../Constant';
import { My } from '../../../stores/my';
import { Question } from '../../../stores/question';
const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
const PrepareStatusMap = getMap(PrepareStatus, 'value', 'label');
const ExperiencePercentMap = getMap(ExperiencePercent, 'value', 'label');
const columns = [
{
key: 'question_type',
title: '题型',
render: (text, record) => {
return QuestionTypeMap[record.questionType];
},
fixSort: true,
},
{
key: 'title',
title: '题目ID',
fixSort: true,
},
{
key: 'description',
title: '内容',
},
{
key: 'time',
title: '耗时',
sort: true,
render: (text, record) => {
const user = record.stat.userTime / record.stat.userNumber;
const all = record.questionNo.totalTime / record.questionNo.totalNumber;
return
{formatSeconds(user)}
all ? 'up' : 'down'} />
全站{formatSeconds(all)}
;
},
},
{
key: 'correct',
title: '错误率',
sort: true,
render: (text, record) => {
return
{formatPercent(record.stat.userNumber - record.stat.userCorrect, record.stat.userNumber, false)}
{record.stat.userNumber - record.stat.userCorrect}/{record.stat.userNumber}
;
},
},
{
key: 'latest_time',
title: '最近做题',
render: (text) => {
return
{text.split(' ')[0]}
{text.split(' ')[1]}
;
},
},
{
key: '',
title: '',
render: (text, record) => {
return
;
},
},
];
const exportType = [
{ key: 'question', title: '题目' },
{ key: 'official', title: '官方解析' },
{ key: 'note', title: '我的笔记' },
{ key: 'qx', title: '千行解析', auth: true },
{ key: 'association', title: '题源联想', auth: true },
{ key: 'qa', title: '相关问答', auth: true },
];
export default class extends Page {
constructor(props) {
props.size = 10;
super(props);
}
initState() {
return {
tab: 'question',
module: 'exercise',
timerange: 'today',
filterMap: {},
sortMap: {},
list: [],
selectList: [],
allChecked: false,
showDetail: false,
};
}
initData() {
const data = Object.assign(this.state, this.state.search);
data.filterMap = this.state.search;
if (data.order) {
data.sortMap = { [data.order]: data.direction };
}
if (data.timerange) {
data.filterMap.timerange = data.timerange;
}
switch (data.tab) {
case 'question':
return this.refreshQuestion(data);
case 'article':
return this.refreshArticle(data);
default:
return null;
}
}
refreshQuestion(data) {
const [startTime, endTime] = timeRange(data.timerange);
refreshQuestionType(this, data.subject, data.questionType, {
all: true,
needSentence: true,
allSubject: true,
}).then(({ questionTypes }) => {
this.setState({ moduleSelect: [{ title: '练习', key: 'exercise' }, { title: '模考', key: 'examination' }] });
My.listQuestionCollect(
Object.assign(
{ module: data.module, questionTypes, startTime, endTime },
this.state.search,
{
order: Object.keys(data.sortMap)
.map(key => {
if (key === 'title') return 'pid desc, no desc';
return `${key} ${data.sortMap[key]}`;
})
.join(','),
},
),
).then(result => {
result.list = result.list.map(row => {
row.key = row.questionNoId;
row.questionType = row.question.questionType;
row.title = row.questionNo.title;
row.description = row.question.description;
row.latest_time = formatDate(row.latestTime, 'YYYY-MM-DD HH:mm:ss');
return row;
});
this.setState({ list: result.list, total: result.total });
});
});
}
refreshArticle(data) {
const [startTime, endTime] = timeRange(data.timerange);
My.listExperienceCollect(Object.assign({ startTime, endTime }, this.state.search)).then(result => {
this.setState({ list: result.list, total: result.total });
});
}
onTabChange(tab) {
const data = { tab };
this.refreshQuery(data);
}
onFilter(value) {
this.search(value, false);
this.initData();
}
onSearch(value) {
this.search({ keyword: value }, false);
this.initData();
}
onSort(value) {
const keys = Object.keys(value);
// this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null });
const { sortMap } = this.state;
const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }, false);
this.initData();
}
onChangePage(page) {
this.search({ page }, false);
this.initData();
}
onAll(checked) {
const selectList = [];
if (checked) {
const { list = [] } = this.state;
list.forEach(item => {
if (selectList.indexOf(item.key) >= 0) return;
selectList.push(item.key);
});
}
this.setState({ selectList, allChecked: checked });
}
onSelect(selectList) {
this.setState({ selectList });
}
onAction(key) {
const { info } = this.props.user;
const { selectList } = this.state;
switch (key) {
case 'help':
this.setState({ showTips: true });
return;
case 'clear':
if (selectList.length === 0) {
this.setState({ showWarn: true, warn: { title: '移除', content: '不可少于1题,请重新选择' } });
return;
}
this.setState({ showClearCollectConfirm: true, clearInfo: { questionNoIds: selectList } });
break;
case 'group':
if (!info.vip) {
this.setState({ showVip: true });
return;
}
if (selectList.length < 10) {
this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可小于10题,请重新选择' } });
return;
}
if (selectList.length > 50) {
this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可多余50题,请重新选择' } });
return;
}
if (selectList.length === 0) {
this.setState({ showWarn: true, warn: { title: '组卷练习', content: '不可同时选中语文题和数学题,请重新选择。' } });
return;
}
this.setState({ showGroupConfirm: true, groupInfo: { questionNoIds: selectList } });
break;
case 'export':
if (!info.vip) {
this.setState({ showVip: true });
return;
}
if (selectList.length < 1) {
this.setState({ showWarn: true, warn: { title: '导出', content: '不可小于1题,请重新选择' } });
return;
}
if (selectList.length > 100) {
this.setState({ showWarn: true, warn: { title: '导出', content: '不可多余100题,请重新选择' } });
return;
}
if (info.bindReal) {
this.setState({ showExportConfirm: true, exportInfo: { info: exportType.map(row => row.key), questionNoIds: selectList } });
} else {
this.setState({ showExportAuthConfirm: true, exportInfo: { info: exportType.filter(row => !row.auth).map(row => row.key), questionNoIds: selectList } });
}
break;
default:
}
}
clearCollectQuestion() {
const { exportInfo } = this.state;
My.clearQuestionCollect(exportInfo.questionNoIds)
.then(() => {
this.refresh();
})
.then(e => {
this.setState({ warn: { title: '移除', content: e.message }, showClearCollectConfirm: false });
});
}
group() {
const { groupInfo } = this.state;
My.groupQuestionCollect(groupInfo)
.then((result) => {
Question.startLink('collect', result);
this.setState({ showGroupConfirm: false });
})
.catch(e => {
this.setState({ warn: { title: '组卷练习', content: e.message }, showGroupConfirm: false });
});
}
export() {
const { exportInfo } = this.state;
this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false });
My.exportQuestion(exportInfo)
.then((result) => {
openLink(`/export/${result.id}`);
this.setState({ showExportWait: false });
})
.catch(e => {
this.setState({ warn: { title: '导出', content: e.message }, showExportWait: false });
});
}
collectArticle(row, checked) {
if (checked) {
My.addExperienceCollect(row.id).then(() => {
this.refresh();
});
} else {
My.delExperienceCollect(row.id).then(() => {
this.refresh();
});
}
}
prevArticle() {
const { list, article } = this.state;
let index = -1;
list.forEach((row, i) => {
if (row.id === article.id) {
index = i;
}
});
if (index === 0) return;
this.setState({ article: list[index - 1] });
}
nextArticle() {
const { list, article } = this.state;
let index = -1;
list.forEach((row, i) => {
if (row.id === article.id) {
index = i;
}
});
if (index === list.length - 1) return;
this.setState({ article: list[index + 1] });
}
renderView() {
const { config } = this.props;
return ;
}
renderTable() {
const { tab } = this.state;
return (
this.onTabChange(key)}
/>
{this[`renderTab${tab}`]()}
{this.renderModal()}
);
}
renderTabquestion() {
const { info } = this.props.user;
const {
questionSubjectSelect,
questionSubjectMap = {},
moduleSelect,
filterMap = {},
sortMap = {},
list = [],
} = this.state;
const { selectList = [], allChecked, page, total } = this.state;
return (
this.onFilter(value)}
onSearch={value => this.onSearch(value)}
/>
this.onAll(checked)}
onAction={key => this.onAction(key)}
/>
this.onSelect(l)}
onSort={v => this.onSort(v)}
onChange={p => this.onChangePage(p)}
/>
);
}
renderTabarticle() {
const { filterMap = {}, sortMap = {}, list = [] } = this.state;
return (
this.onFilter(value)}
onSort={value => this.onSort(value)}
/>
{list.map(item => {
return this.setState({ showDetail: true, article: item })} onUnCollect={() => this.collectArticle(item, false)} />;
})}
);
}
renderModal() {
const { article = {}, showTips, showWarn, warn = {}, showClearCollectConfirm, clearInfo = {}, showGroupConfirm, groupInfo = {}, showExportConfirm, showExportAuthConfirm, exportInfo = {}, showExportWait, showExamination, showVip, showReal } = this.state;
const { info } = this.props.user;
return [
this.setState({ showDetail: false })} onPrev={() => this.prevArticle()} onNext={() => this.nextArticle()} />,
this.setState({ showTips: false })}>
组卷功能
操作数量:10-50;
注意事项:可跨题型、不可跨学科。
导出功能
操作数量:1-100;
注意事项:“综合推理IR”暂时无法导出。
*您可点击
查阅以上信息。
,
this.setState({ showWarn: false })}>
{warn.content}
,
this.group()} onCancel={() => this.setState({ showGroupConfirm: false })}>
您共选择了 {groupInfo.questionNoIds ? groupInfo.questionNoIds.length : 0} 道题目,是否开始练习?
剔除已组卷练习
,
this.clearCollectQuestion()} onCancel={() => this.setState({ showClearCollectConfirm: false })}>
当前选中的 {clearInfo.questionNoIds ? clearInfo.questionNoIds.length : 0} 道题即将被移出收藏,移出后无法恢复,是否继续?
,
this.setState({ showExportWait: false })}>
正在下载中,请不要关闭当前页面!
,
this.export()} onCancel={() => this.setState({ showExportConfirm: false })}>
当前共选中 {exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0} 道题,请确认需要导出的内容:
{exportType.map(item => {
return (
= 0 : false} className="m-r-5" onChange={() => {
const index = exportInfo.info.indexOf(item.key);
if (index >= 0) {
exportInfo.info.splice(index, 1);
} else {
exportInfo.info.push(item.key);
}
this.setState({ exportInfo });
}} />
{item.title}
);
})}
,
this.export()} onCancel={() => this.setState({ showExportAuthConfirm: false })}>
当前共选中 {exportInfo.questionNoIds ? exportInfo.questionNoIds.length : 0} 道题,请确认需要导出的内容:
{exportType
.filter(item => !item.auth)
.map(item => {
return (
= 0 : false} className="m-r-5" onChange={() => {
const index = exportInfo.info.indexOf(item.key);
if (index >= 0) {
exportInfo.info.splice(index, 1);
} else {
exportInfo.info.push(item.key);
}
this.setState({ exportInfo });
}} />
{item.title}
);
})}
{exportType
.filter(item => item.auth)
.map(item => {
return (
{item.title}
);
})}
,
this.setState({ showExamination: false })}
onCancel={() => this.setState({ showExamination: false })}
onClose={() => this.setState({ showExamination: false })}
/>,
this.setState({ showReal: false })} />,
this.setState({ showVip: false, showReal: true })}
onPrepare={() => this.setState({ showVip: false, showExamination: true })}
onClose={() => this.setState({ showVip: false })}
/>,
];
}
}
class ArticleDetail extends Component {
render() {
const { show, data, onClose, onPrev, onNext } = this.props;
return (
onPrev && onPrev()} />
onNext && onNext()} />
{data.title}
{data.user ? data.user.nickname : data.nickname}
{PrepareStatusMap[data.prepareStatus]}
备考:{formatMonth(data.experienceDay, false)}
{data.experienceScore}分 /提分 {ExperiencePercentMap[data.experiencePercent]}
更多信息
);
}
}
class Article extends Component {
render() {
const { data, onClick, onUnCollect } = this.props;
return (
onClick && onClick()}>
{data.title}
{formatDate(data.updateTime, 'YYYY-MM-DD HH:mm:ss')}
阅读 {data.viewNumber}
onUnCollect()}>取消收藏
{data.user ? data.user.nickname : data.nickname}
{PrepareStatusMap[data.prepareStatus]}
备考:{formatMonth(data.experienceDay, false)}
{data.experienceScore}分 /提分 {ExperiencePercentMap[data.experiencePercent]}
);
}
}