123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751 |
- import React from 'react';
- import './index.less';
- import { Tooltip, Popover, Checkbox } from 'antd';
- import Page from '@src/containers/Page';
- import Assets from '@src/components/Assets';
- import { timeRange, formatPercent, formatSeconds, formatDate, getMap } from '@src/services/Tools';
- import UserLayout from '../../../layouts/User';
- import UserAction from '../../../components/UserAction';
- import UserTable from '../../../components/UserTable';
- import IconButton from '../../../components/IconButton';
- import menu, { refreshQuestionType, refreshStruct } from '../index';
- import Tabs from '../../../components/Tabs';
- import { TimeRange, QuestionType } from '../../../../Constant';
- import { My } from '../../../stores/my';
- import { Main } from '../../../stores/main';
- import { Question } from '../../../stores/question';
- const QuestionnTypeMap = getMap(QuestionType, 'value', 'label');
- export default class extends Page {
- constructor(props) {
- props.size = 10;
- super(props);
- this.columns = [
- { key: 'title', title: '练习册名称', fixSort: true },
- {
- key: 'create_time',
- title: '做题时间',
- fixSort: true,
- render: (text, row, index) => {
- return (
- <div>
- <div className="t-2">
- 2019-12-12
- {row.children && (
- <Popover
- trigger="click"
- content={
- <table className="user-report-history-overlay">
- <tbody>
- {row.children.map((child, i) => {
- return (
- <tr>
- <td>{row.children.length - i}</td>
- <td>2019-12-12 13:13:13</td>
- <td>3/20</td>
- <td>
- <Checkbox
- checked={!child.disabled}
- onChange={e => this.onChangeShowHistory(index, i, e.target.checked)}
- />
- </td>
- </tr>
- );
- })}
- </tbody>
- </table>
- }
- >
- <Tooltip overlayClassName="gray" title="历史数据">
- <span>
- <Assets className="m-l-5" name="down_normal" />
- </span>
- </Tooltip>
- </Popover>
- )}
- </div>
- <div className="t-6">13:13:13</div>
- </div>
- );
- },
- },
- { key: 'correct', title: '正确率', sort: true },
- { key: 'time', title: '平均耗时', sort: true },
- { key: 'progress', title: '完成度' },
- {
- key: 'report',
- title: '报告',
- render() {
- return <IconButton type="report" tip="report" />;
- },
- },
- ];
- Main.getExaminationNumber().then(nums => {
- this.nums = nums;
- this.setState({ load: false });
- });
- }
- initState() {
- return {
- tab: 'exercise',
- timerange: 'all',
- filterMap: {},
- sortMap: {},
- list: [], // { children: [{}, {}], title: 'channgnanjue' }, {}, {}, {}
- selectList: [],
- allChecked: false,
- defaultSortMap: { latest_time: 'desc' },
- };
- }
- init() {
- this.exerciseColumns = [
- {
- key: 'title',
- title: '练习册名称',
- fixSort: true,
- render: (text, record) => {
- if (text) {
- if (QuestionnTypeMap[record.questionTypes[0]]) return `${QuestionnTypeMap[record.questionTypes[0]]}-${text}`;
- return `${text}`;
- }
- return '';
- },
- },
- {
- key: 'latest_time',
- title: '做题时间',
- sort: true,
- render: (text, record, index, childIndex) => {
- const { reports, show } = record;
- const report = childIndex === -1 ? reports[0] : record;
- const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss');
- return <div className="">
- <div className="t-2 t-s-12">{time.split(' ')[0]}
- {childIndex === -1 && reports && reports.length > 1 && (
- <Popover
- trigger="click"
- content={
- <table className="user-report-history-overlay">
- <tbody>
- {reports.map((child, ii) => {
- if (ii === 0) return null;
- return <tr>
- <td>{reports.length - ii}</td>
- <td>{formatDate(child.updateTime, 'YYYY-MM-DD HH:mm:ss')}</td>
- <td>{child.userNumber}/{child.questionNumber}</td>
- <td>
- <Checkbox
- checked={show.indexOf(child.id) >= 0}
- onChange={e => this.onChangeShowHistory(index, ii, e.target.checked)}
- />
- </td>
- </tr>;
- })}
- </tbody>
- </table>
- }
- >
- <Tooltip overlayClassName="gray" title="历史数据">
- <span>
- <Assets className="m-l-5" name="down_normal" />
- </span>
- </Tooltip>
- </Popover>
- )}</div>
- <div className="t-6 t-s-12">{time.split(' ')[1]}</div>
- </div>;
- },
- },
- {
- key: 'correct',
- title: '正确率',
- sort: true,
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- const user = formatPercent(report.userCorrect, report.userNumber);
- const all = formatPercent(record.stat.totalCorrect, record.stat.totalNumber);
- return <div className="">
- <div className="t-2 t-s-12">{user}%<Assets height={10} width={10} name={user > all ? 'up' : 'down'} /></div>
- <div className="t-6 t-s-12">全站{all}%</div>
- </div>;
- },
- },
- {
- key: 'time',
- title: '平均耗时',
- sort: true,
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- const user = Math.floor(report.userTime / report.userNumber);
- const all = Math.floor(record.stat.totalTime / record.stat.totalNumber);
- return <div className="">
- <div className="t-2 t-s-12">{formatSeconds(user)}<Assets height={10} width={10} name={user > all ? 'down' : 'up'} /></div>
- <div className="t-6 t-s-12">全站{formatSeconds(all)}</div>
- </div>;
- },
- },
- {
- key: 'progress',
- title: '完成度',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- return (
- <div className="">
- <div className="t-2 t-s-12">{formatPercent(report.userNumber, report.questionNumber, false)}</div>
- </div>
- );
- },
- },
- {
- key: 'report',
- title: '报告',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- return (
- <div className="">
- <IconButton
- type="report"
- tip="report"
- onClick={() => {
- Question.reportLink({ report }, true);
- }}
- />
- </div>
- );
- },
- },
- ];
- this.examinationColumns = [
- { key: 'title', title: '模考名称', fixSort: true },
- {
- key: 'latest_time',
- title: '做题时间',
- sort: true,
- render: (text, record, index, childIndex) => {
- const { reports, show } = record;
- const report = childIndex === -1 ? reports[0] : record;
- const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss');
- return <div className="">
- <div className="t-2 t-s-12">{time.split(' ')[0]}
- {childIndex === -1 && reports && reports.length > 1 && (
- <Popover
- trigger="click"
- content={
- <table className="user-report-history-overlay">
- <tbody>
- {reports.map((child, ii) => {
- if (ii === 0) return null;
- return <tr>
- <td>{reports.length - ii}</td>
- <td>{formatDate(child.updateTime, 'YYYY-MM-DD HH:mm:ss')}</td>
- <td>{child.userNumber}/{child.questionNumber}</td>
- <td>
- <Checkbox
- checked={show.indexOf(child.id) >= 0}
- onChange={e => this.onChangeShowHistory(index, ii, e.target.checked)}
- />
- </td>
- </tr>;
- })}
- </tbody>
- </table>
- }
- >
- <Tooltip overlayClassName="gray" title="历史数据">
- <span>
- <Assets className="m-l-5" name="down_normal" />
- </span>
- </Tooltip>
- </Popover>
- )}</div>
- <div className="t-6 t-s-12">{time.split(' ')[1]}</div>
- </div>;
- },
- },
- {
- key: 'overall',
- title: 'Overall',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- if (!report) return null;
- if (!report.qxCat) {
- return (
- <div className="f-s-12">
- 仅CAT模考
- <br />
- 提供分数
- </div>
- );
- }
- if (!report.score) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{report.score.totalScore}</div>
- <div className="t-6 t-s-12">
- {record.qxCat === 1
- ? Math.round(record.origin.totalScore / record.origin.totalTimes)
- : Math.round(record.origin.secondTotalScore / record.origin.secondTotalTimes)}
- </div>
- </div>
- );
- },
- },
- {
- key: 'verbal',
- title: 'Verbal',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- if (!report) return null;
- if (!report.qxCat) {
- return (
- <div className="f-s-12">
- {formatPercent(report.setting.real ? report.setting.real.verbal : report.setting.number.verbal, this.nums.verbal.number, false)}
- </div>
- );
- }
- if (!report.score) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{report.score.verbalScore}</div>
- <div className="t-6 t-s-12">
- {record.qxCat === 1
- ? Math.round(record.origin.verbalScore / record.origin.totalTimes)
- : Math.round(record.origin.secondVerbalScore / record.origin.secondTotalTimes)}
- </div>
- </div>
- );
- },
- },
- {
- key: 'quant',
- title: 'Quant',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- if (!report) return null;
- if (!report.qxCat) {
- return (
- <div className="f-s-12">{formatPercent(report.setting.real ? report.setting.real.quant : report.setting.number.quant, false)}</div>
- );
- }
- if (!report.score) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{report.score.quantScore}</div>
- <div className="t-6 t-s-12">
- {record.qxCat === 1
- ? Math.round(record.origin.quantScore / record.origin.totalTimes)
- : Math.round(record.origin.secondQuantScore / record.origin.secondTotalTimes)}
- </div>
- </div>
- );
- },
- },
- {
- key: 'ir',
- title: 'IR',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- if (!report) return null;
- if (!report.qxCat) {
- return <div className="f-s-12">{formatPercent(report.setting.real ? report.setting.real.ir : report.setting.number.ir, this.nums.ir.number, false)}</div>;
- }
- if (!report.score) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{report.score.irScore}</div>
- <div className="t-6 t-s-12">
- {record.qxCat === 1
- ? Math.round(record.origin.irScore / record.origin.totalTimes)
- : Math.round(record.origin.secondIrScore / record.origin.secondTotalTimes)}
- </div>
- </div>
- );
- },
- },
- {
- key: 'report',
- title: '报告',
- render: (text, record, index, childIndex) => {
- const { reports } = record;
- const report = childIndex === -1 ? reports[0] : record;
- return (
- <IconButton
- type="report"
- tip="report"
- onClick={() => {
- Question.reportLink({ report }, true);
- }}
- />
- );
- },
- },
- ];
- this.originColumns = [
- {
- key: 'title',
- title: '名称',
- fixSort: true,
- render: (text) => {
- return <div className="sub">{text}</div>;
- },
- },
- {
- key: 'questionType',
- title: '题型',
- render: (text, record) => {
- return record.questionTypes.map(row => <p>{QuestionnTypeMap[row]}</p>);
- },
- },
- {
- key: 'latest_time',
- title: '做题时间',
- sort: true,
- render: (text, record) => {
- const { reports } = record;
- if (!reports) return null;
- const report = reports[0];
- if (!report) return null;
- const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss');
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{time.split(' ')[0]}</div>
- <div className="t-6 t-s-12">{time.split(' ')[1]}</div>
- </div>
- );
- },
- },
- {
- key: 'correct',
- title: '正确率',
- sort: true,
- render: (text, record) => {
- const { reports } = record;
- if (!reports) return null;
- const report = reports[0];
- if (!report) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{formatPercent(report.userCorrect, report.userNumber, false)}</div>
- </div>
- );
- },
- },
- {
- key: 'time',
- title: '平均耗时',
- sort: true,
- render: (text, record) => {
- const { reports } = record;
- if (!reports) return null;
- const report = reports[0];
- if (!report) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{formatSeconds(report.userTime / report.userNumber)}</div>
- </div>
- );
- },
- },
- {
- key: 'progress',
- title: '完成度',
- render: (text, record) => {
- const { reports } = record;
- if (!reports) return null;
- const report = reports[0];
- if (!report) return null;
- return (
- <div className="sub">
- <div className="t-2 t-s-12">{formatPercent(report.userNumber, report.questionNumber, false)}</div>
- <div className="t-6 t-s-12">
- {report.userNumber}/{report.questionNumber}
- </div>
- </div>
- );
- },
- },
- {
- key: 'report',
- title: '报告',
- render: (text, record) => {
- const { reports } = record;
- if (!reports) return null;
- const report = reports[0];
- if (!report) return null;
- return (
- <div className="sub">
- <IconButton
- type="report"
- tip="report"
- onClick={() => {
- Question.reportLink({ report }, true);
- }}
- />
- </div>
- );
- },
- },
- ];
- }
- initData() {
- const data = Object.assign(this.state, this.state.search);
- 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 [startTime, endTime] = timeRange(data.timerange);
- switch (data.tab) {
- case 'error':
- case 'collect':
- My.listReport(
- Object.assign({ origin: data.tab, startTime, endTime }, this.state.search, {
- order: Object.keys(data.sortMap)
- .map(key => {
- return `${key} ${data.sortMap[key]}`;
- })
- .join(','),
- }),
- ).then(result => {
- result.list = result.list.map(row => {
- row.questionTypes = row.questionTypes || [];
- row.reports = row.reports || [];
- row.stat = row.stat || {};
- return row;
- });
- this.setState({ list: result.list, total: result.total, page: data.page, columns: this.originColumns });
- });
- break;
- case 'exercise':
- case 'examination':
- default:
- refreshQuestionType(this, data.subject, data.questionType, {
- all: true,
- needSentence: true,
- allSubject: true,
- onlyPreview: data.one === 'preview',
- }).then(({ questionTypes, selectSentence }) => {
- return refreshStruct(this, questionTypes, data.tab, data.one, data.two, {
- all: true,
- needPreview: true,
- needTextbook: false,
- selectSentence,
- }).then(({ structIds, courseModules }) => {
- My.listReport(
- Object.assign(
- { module: data.tab, questionTypes, structIds, courseModules, startTime, endTime },
- this.state.search,
- {
- order: Object.keys(data.sortMap)
- .map(key => {
- if (key === 'title') return 'struct_three asc, struct_four asc, no asc';
- return `${key} ${data.sortMap[key]}`;
- })
- .join(','),
- },
- ),
- ).then(result => {
- result.list = result.list.map(row => {
- row.questionTypes = row.questionTypes || [];
- row.reports = row.reports || [];
- row.stat = row.stat || {};
- row.reports.forEach(r => {
- r.stat = row.stat;
- });
- row.children = [];
- row.show = [];
- return row;
- });
- this.setState({
- list: result.list,
- total: result.total,
- page: data.page,
- columns: data.tab === 'exercise' ? this.exerciseColumns : this.examinationColumns,
- });
- });
- });
- });
- }
- }
- onChangeShowHistory(index, childIndex, checked) {
- const { list } = this.state;
- const item = list[index];
- const { reports } = item;
- const { children } = item;
- const show = children.map(row => row.id);
- const childId = reports[childIndex].id;
- // 第一个不允许切换
- if (checked) {
- if (show.indexOf(childId) >= 0) return;
- children.push(reports[childIndex]);
- } else {
- const k = show.indexOf(childId);
- if (k < 0) return;
- children.splice(k, 1);
- }
- list[index].children = children;
- list[index].show = children.map(row => row.id);
- this.setState({ list });
- }
- 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(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();
- }
- renderView() {
- const { config } = this.props;
- return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
- }
- renderTable() {
- const {
- tab,
- questionSubjectSelect,
- questionSubjectMap = {},
- oneSelect,
- twoSelectMap = {},
- oneSelectPlaceholder,
- twoSelectPlaceholder,
- filterMap = {},
- sortMap = {},
- list = [],
- } = this.state;
- const { page, total, columns } = this.state;
- const selectList = [];
- if (tab === 'exercise') {
- selectList.push({
- children: [
- {
- key: 'subject',
- placeholder: '学科',
- select: questionSubjectSelect,
- },
- {
- placeholder: '题型',
- key: 'questionType',
- be: 'subject',
- selectMap: questionSubjectMap,
- },
- ],
- });
- }
- if (tab === 'exercise' || tab === 'examination') {
- selectList.push({
- label: '范围',
- children: [
- {
- key: 'one',
- placeholder: oneSelectPlaceholder,
- select: oneSelect,
- },
- {
- key: 'two',
- be: 'one',
- placeholder: twoSelectPlaceholder,
- selectMap: twoSelectMap,
- },
- ],
- });
- }
- selectList.push({
- right: true,
- key: 'timerange',
- select: TimeRange,
- });
- return (
- <div className="table-layout">
- <Tabs
- border
- type="division"
- theme="theme"
- size="small"
- space={2.5}
- width={100}
- active={tab}
- tabs={[
- { key: 'exercise', title: '练习' },
- { key: 'examination', title: '模考' },
- { key: 'error', title: '错题组卷' },
- { key: 'collect', title: '收藏组卷' },
- ]}
- onChange={key => this.onTabChange(key)}
- />
- <UserAction
- search
- defaultSearch={filterMap.keyword}
- selectList={selectList}
- filterMap={filterMap}
- onFilter={value => this.onFilter(value)}
- onChange={key => this.onChangeTab(key)}
- onSearch={value => this.onSearch(value)}
- />
- <UserTable
- even="children"
- columns={columns}
- sortMap={sortMap}
- data={list}
- current={page}
- total={total}
- pageSize={this.state.search.size}
- selectList={selectList}
- onSelect={l => this.onSelect(l)}
- onSort={v => this.onSort(v)}
- onChange={p => this.onChangePage(p)}
- />
- </div>
- );
- }
- }
|