import React from 'react'; // import { Link } from 'react-router-dom'; import './index.less'; import { Icon, Checkbox } from 'antd'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import { timeRange, formatDate, getMap, formatSeconds, formatPercent } from '@src/services/Tools'; import UserLayout from '../../../layouts/User'; import UserTable from '../../../components/UserTable'; import UserAction from '../../../components/UserAction'; import { RealAuth, QuestionNoteModal } from '../../../components/OtherModal'; import Examination from '../../../components/Examination'; import VipRenew from '../../../components/VipRenew'; import menu, { refreshQuestionType, refreshStruct } 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 } from '../../../../Constant'; import { My } from '../../../stores/my'; import { Question } from '../../../stores/question'; import { User } from '../../../stores/user'; const QuestionTypeMap = getMap(QuestionType, 'value', 'label'); 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: 'exercise', timerange: 'all', filterMap: {}, sortMap: {}, data: [{}, {}], selectList: [], allChecked: false, defaultSortMap: { latest_time: 'desc' }, }; } init() { this.columns = [ { key: 'question_type', title: '题型', width: 115, style: { whiteSpace: 'nowrap' }, render: (text, record) => { return QuestionTypeMap[record.questionType]; }, fixSort: true, }, { key: 'title', title: '题目ID', width: 100, fixSort: true, style: { whiteSpace: 'nowrap' }, render: (text, record) => { return {text}; }, }, { key: 'description', title: '内容', width: 185, render: (text) => { return
{(text || '').replace(/ /g, '')}
; }, }, { key: 'time', title: '耗时', width: 100, sort: true, style: { whiteSpace: 'nowrap' }, render: (text, record) => { const user = Math.floor(record.stat ? record.stat.userTime / record.stat.userNumber : 0); const all = Math.floor(record.questionNo.totalNumber ? record.questionNo.totalTime / record.questionNo.totalNumber : 0); return
{user > 0 ? formatSeconds(user) : '-'}{user > 0 && all ? 'down' : 'up'} />}
全站{all > 0 ? formatSeconds(all) : '-'}
; }, }, { key: 'correct', title: '错误率', width: 95, sort: true, style: { whiteSpace: 'nowrap' }, render: (text, record) => { return
{record.stat ? formatPercent(record.stat.userNumber - record.stat.userCorrect, record.stat.userNumber, false) : '-'}
{record.stat ? `${record.stat.userNumber - record.stat.userCorrect}/${record.stat.userNumber}` : '-'}
; }, }, { key: 'latest_time', title: '最近做题', width: 105, sort: true, style: { whiteSpace: 'nowrap' }, render: (text) => { return
{text.split(' ')[0]}
{text.split(' ')[1]}
; }, }, { key: '', title: '', width: 70, style: { whiteSpace: 'nowrap' }, render: (text, record, index) => { return
this.toggleCollect(index)} /> this.note(index)} />
; }, }, ]; } initData() { const data = Object.assign(this.state, this.state.search); console.log(data); data.filterMap = this.state.search; if (data.order) { data.sortMap = { [data.order]: data.direction }; } else if (data.order !== null && data.order !== '') { data.sortMap = Object.assign({}, this.state.defaultSortMap); } if (data.timerange) { data.filterMap.timerange = data.timerange; } const { info = {} } = this.props.user; if (info.latestError) { // 获取最后一次错题记录 Question.baseReport(info.latestError).then(result => { this.setState({ latest: result }); }); } const [startTime, endTime] = timeRange(data.timerange); refreshQuestionType(this, data.subject, data.questionType, { all: true, needSentence: data.tab !== 'examination', allSubject: true, }).then(({ questionTypes, selectSentence }) => { return refreshStruct(this, questionTypes, data.tab, data.one, data.two, { all: true, needPreview: true, needTextbook: true, selectSentence, }).then(({ courseModules, structIds, latest, year }) => { My.listError( Object.assign( { module: data.tab, questionTypes, courseModules, structIds, latest, year, startTime, endTime }, this.state.search, { order: Object.keys(data.sortMap) .map(key => { if (key === 'title') return 'pid asc, no asc'; return `${key} ${data.sortMap[key]}`; }) .join(','), }, ), ).then(result => { result.list = result.list.map(row => { row.questionNo = row.questionNo || {}; row.key = row.questionNoId; row.questionType = row.question.questionType; row.title = row.questionNo.title; row.description = row.question.description; row.latest_time = row.latestTime ? formatDate(row.latestTime, 'YYYY-MM-DD HH:mm:ss') : ''; return row; }); const { selectList, allChecked, selectPage } = this.updateSelectInfo(data.page, result.list); this.setState({ list: result.list, total: result.total, selectList, allChecked, selectPage }); }); }); }); } updateSelectInfo(page, list, selectList = null) { const { selectPage = {} } = this.state; let allChecked = false; if (selectList == null) { selectList = []; if (selectPage[Number(page)]) { selectList = selectPage[Number(page)]; } } else { selectPage[Number(page)] = selectList; } allChecked = list.filter(row => selectList.indexOf(row.key) >= 0).length === list.length && list.length > 0; return { selectList, allChecked, selectPage }; } toggleCollect(index) { const { list } = this.state; const userQuestion = list[index]; if (!userQuestion.collect) { My.addQuestionCollect(userQuestion.questionNo.id).then(() => { userQuestion.collect = true; this.setState({ list }); }); } else { My.delQuestionCollect(userQuestion.questionNo.id).then(() => { userQuestion.collect = false; this.setState({ list }); }); } } note(index) { const { list } = this.state; const userQuestion = list[index]; const { questionNo } = userQuestion; My.getQuestionNote(questionNo.id) .then(result => { this.setState({ questionNo, note: result || {}, showNote: true, index }); }); } onTabChange(tab) { const data = { tab }; this.refreshQuery(data); } onFilter(value) { this.search(value, false); this.initData(); } onSearch(value) { this.search({ page: 1, keyword: value }, false); this.initData(); } onSort(value) { const keys = Object.keys(value); const { sortMap, defaultSortMap } = this.state; const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0; let order = keys.length && value[keys[index]] ? keys[index] : null; let direction = keys.length ? value[keys[index]] : null; if (order == null) { const [prevOrder] = Object.keys(sortMap); console.log(prevOrder, defaultSortMap[prevOrder]); if (!defaultSortMap[prevOrder]) { [order] = Object.keys(defaultSortMap); direction = defaultSortMap[order]; } } this.search({ order, direction }, false); this.initData(); } onChangePage(page) { this.search({ page }, false); this.initData(); } onAll(checked) { const { selectPage = {}, search = {} } = this.state; let { selectList } = this.state; const { page } = search; const { list = [] } = this.state; if (checked) { list.forEach(item => { if (selectList.indexOf(item.key) >= 0) return; selectList.push(item.key); }); selectPage[Number(page)] = selectList; } else { selectList = []; delete selectPage[Number(page)]; } this.setState({ selectList, selectPage, allChecked: checked }); } onSelect(slist) { const { search = {}, list } = this.state; const { selectList, allChecked, selectPage } = this.updateSelectInfo(search.page, list, slist); this.setState({ selectList, allChecked, selectPage }); } onAction(key) { const { info } = this.props.user; const { selectPage = {} } = this.state; const selectList = [].concat(...Object.values(selectPage).concat()); 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({ showClearConfirm: 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, filterTimes: 2, checked: true } }); 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: { include: exportType.map(row => row.key), questionNoIds: selectList, answer: true } }); // } else { // this.setState({ showExportAuthConfirm: true, exportInfo: { include: exportType.filter(row => !row.auth).map(row => row.key), questionNoIds: selectList, answer: true } }); // } break; default: } } clearErrorQuestion() { const { clearInfo } = this.state; My.clearError(clearInfo.questionNoIds) .then(() => { this.setState({ showClearConfirm: false, selectList: [], selectPage: {}, allChecked: false }); this.refresh(); }) .catch(e => { this.setState({ showWarn: true, warn: { title: '移除', content: e.message }, showClearConfirm: false }); }); } group() { const { groupInfo } = this.state; if (!groupInfo.checked) { delete groupInfo.filterTimes; } My.groupError(groupInfo) .then((result) => { Question.startLink('error', result); this.setState({ showGroupConfirm: false, selectList: [], selectPage: {}, allChecked: false }); }) .catch(e => { this.setState({ showWarn: true, warn: { title: '组卷练习', content: e.message }, showGroupConfirm: false }); }); } export() { const { exportInfo } = this.state; this.setState({ showExportWait: true, showExportConfirm: false, showExportAuthConfirm: false }); My.exportQuestionError(exportInfo) .then((result) => { openLink(`/export/${result}`); this.setState({ showExportWait: false, selectList: [], selectPage: {}, allChecked: false }); }) .catch(e => { this.setState({ showWarn: true, warn: { title: '导出', content: e.message }, showExportWait: false }); }); } remove(report) { My.removeError(report.id) .then(() => { this.refresh(); }); } clearErrorReport() { My.clearLatestError() .then(() => { const { info } = this.props.user; info.latestError = 0; User.infoHandle(info); }); this.setState({ latest: null }); } renderView() { const { config } = this.props; return ; } renderTable() { const { tab, questionSubjectSelect, questionSubjectMap = {}, oneSelect, twoSelectMap = {}, oneSelectPlaceholder, twoSelectPlaceholder, filterMap = {}, sortMap = {}, list = [], latest, } = this.state; const { selectList = [], allChecked, page, total } = this.state; const { info } = this.props.user; return (
this.onTabChange(key)} /> this.onFilter(value)} onSearch={value => this.onSearch(value)} /> {formatDate(latest.updateTime, 'YYYY-MM-DD HH:mm')} 组卷{latest.questionNumber}题,做对{latest.userCorrect}题。 { this.remove(latest); }}>移除正确题目 { this.clearErrorReport(); }} />
} onAll={checked => this.onAll(checked)} onAction={key => this.onAction(key)} /> this.onSelect(l)} onSort={v => this.onSort(v)} onChange={p => this.onChangePage(p)} /> {this.renderModal()} ); } renderModal() { const { showTips, showWarn, warn = {}, showClearConfirm, clearInfo = {}, showGroupConfirm, groupInfo = {}, showExportConfirm, showExportAuthConfirm, exportInfo = {}, showExportWait, showExamination, showVip, showReal, showNote, note = {}, questionNo = {}, list } = this.state; const { info } = this.props.user; return [ 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} 道题目,是否开始练习?
{ groupInfo.checked = !groupInfo.checked; this.setState({ groupInfo }); }} /> 剔除已组卷练习