page.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. import React from 'react';
  2. import './index.less';
  3. import { Tooltip, Popover, Checkbox } from 'antd';
  4. import Page from '@src/containers/Page';
  5. import Assets from '@src/components/Assets';
  6. import { timeRange, formatPercent, formatSeconds, formatDate, getMap } from '@src/services/Tools';
  7. import UserLayout from '../../../layouts/User';
  8. import UserAction from '../../../components/UserAction';
  9. import UserTable from '../../../components/UserTable';
  10. import IconButton from '../../../components/IconButton';
  11. import menu, { refreshQuestionType, refreshStruct } from '../index';
  12. import Tabs from '../../../components/Tabs';
  13. import { TimeRange, QuestionType } from '../../../../Constant';
  14. import { My } from '../../../stores/my';
  15. import { Main } from '../../../stores/main';
  16. import { Question } from '../../../stores/question';
  17. const QuestionnTypeMap = getMap(QuestionType, 'value', 'label');
  18. export default class extends Page {
  19. constructor(props) {
  20. props.size = 10;
  21. super(props);
  22. this.columns = [
  23. { key: 'title', title: '练习册名称', fixSort: true },
  24. {
  25. key: 'create_time',
  26. title: '做题时间',
  27. fixSort: true,
  28. render: (text, row, index) => {
  29. return (
  30. <div>
  31. <div className="t-2">
  32. 2019-12-12
  33. {row.children && (
  34. <Popover
  35. trigger="click"
  36. content={
  37. <table className="user-report-history-overlay">
  38. <tbody>
  39. {row.children.map((child, i) => {
  40. return (
  41. <tr>
  42. <td>{row.children.length - i}</td>
  43. <td>2019-12-12 13:13:13</td>
  44. <td>3/20</td>
  45. <td>
  46. <Checkbox
  47. checked={!child.disabled}
  48. onChange={e => this.onChangeShowHistory(index, i, e.target.checked)}
  49. />
  50. </td>
  51. </tr>
  52. );
  53. })}
  54. </tbody>
  55. </table>
  56. }
  57. >
  58. <Tooltip overlayClassName="gray" title="历史数据">
  59. <span>
  60. <Assets className="m-l-5" name="down_normal" />
  61. </span>
  62. </Tooltip>
  63. </Popover>
  64. )}
  65. </div>
  66. <div className="t-6">13:13:13</div>
  67. </div>
  68. );
  69. },
  70. },
  71. { key: 'correct', title: '正确率', sort: true },
  72. { key: 'time', title: '平均耗时', sort: true },
  73. { key: 'progress', title: '完成度' },
  74. {
  75. key: 'report',
  76. title: '报告',
  77. render() {
  78. return <IconButton type="report" tip="report" />;
  79. },
  80. },
  81. ];
  82. Main.getExaminationNumber().then(nums => {
  83. this.nums = nums;
  84. this.setState({ load: false });
  85. });
  86. }
  87. initState() {
  88. return {
  89. tab: 'exercise',
  90. timerange: 'today',
  91. filterMap: {},
  92. sortMap: {},
  93. list: [], // { children: [{}, {}], title: 'channgnanjue' }, {}, {}, {}
  94. selectList: [],
  95. allChecked: false,
  96. };
  97. }
  98. init() {
  99. this.exerciseColumns = [
  100. {
  101. key: 'title',
  102. title: '练习册名称',
  103. fixSort: true,
  104. // render: (text, record) => {
  105. // const { reports } = record;
  106. // return reports.map((report, index) => {
  107. // return <div className="sub">{index === 0 && text}</div>;
  108. // });
  109. // },
  110. },
  111. {
  112. key: 'latest_time',
  113. title: '做题时间',
  114. fixSort: true,
  115. render: (text, record, index, childIndex) => {
  116. const { reports, show } = record;
  117. const report = childIndex === -1 ? reports[0] : record;
  118. const time = formatDate(report.updateTime, 'YYYY-MM-DD HH:mm:ss');
  119. return <div className="">
  120. <div className="t-2 t-s-12">{time.split(' ')[0]}
  121. {childIndex === -1 && reports.length > 1 && (
  122. <Popover
  123. trigger="click"
  124. content={
  125. <table className="user-report-history-overlay">
  126. <tbody>
  127. {reports.map((child, ii) => {
  128. if (ii === 0) return null;
  129. return <tr>
  130. <td>{reports.length - ii}</td>
  131. <td>{formatDate(child.updateTime, 'YYYY-MM-DD HH:mm:ss')}</td>
  132. <td>{child.userNumber}/{child.questionNumber}</td>
  133. <td>
  134. <Checkbox
  135. checked={show.indexOf(child.id) >= 0}
  136. onChange={e => this.onChangeShowHistory(index, ii, e.target.checked)}
  137. />
  138. </td>
  139. </tr>;
  140. })}
  141. </tbody>
  142. </table>
  143. }
  144. >
  145. <Tooltip overlayClassName="gray" title="历史数据">
  146. <span>
  147. <Assets className="m-l-5" name="down_normal" />
  148. </span>
  149. </Tooltip>
  150. </Popover>
  151. )}</div>
  152. <div className="t-6 t-s-12">{time.split(' ')[1]}</div>
  153. </div>;
  154. },
  155. },
  156. {
  157. key: 'correct',
  158. title: '正确率',
  159. sort: true,
  160. render: (text, record, index, childIndex) => {
  161. const { reports } = record;
  162. const report = childIndex === -1 ? reports[0] : record;
  163. const user = formatPercent(report.userCorrect, report.userNumber);
  164. const all = formatPercent(record.stat.totalCorrect, record.stat.totalNumber);
  165. return <div className="">
  166. <div className="t-2 t-s-12">{user}%<Assets height={10} width={10} name={user > all ? 'up' : 'down'} /></div>
  167. <div className="t-6 t-s-12">全站{all}%</div>
  168. </div>;
  169. },
  170. },
  171. {
  172. key: 'time',
  173. title: '平均耗时',
  174. sort: true,
  175. render: (text, record, index, childIndex) => {
  176. const { reports } = record;
  177. const report = childIndex === -1 ? reports[0] : record;
  178. const user = report.userTime / report.userNumber;
  179. const all = record.stat.totalTime / record.stat.totalNumber;
  180. return <div className="">
  181. <div className="t-2 t-s-12">{formatSeconds(user)}<Assets height={10} width={10} name={user > all ? 'up' : 'down'} /></div>
  182. <div className="t-6 t-s-12">全站{formatSeconds(all)}</div>
  183. </div>;
  184. },
  185. },
  186. {
  187. key: 'progress',
  188. title: '完成度',
  189. render: (text, record, index, childIndex) => {
  190. const { reports } = record;
  191. const report = childIndex === -1 ? reports[0] : record;
  192. return (
  193. <div className="">
  194. <div className="t-2 t-s-12">{formatPercent(report.userNumber, report.questionNumber, false)}</div>
  195. </div>
  196. );
  197. },
  198. },
  199. {
  200. key: 'report',
  201. title: '报告',
  202. render: (text, record, index, childIndex) => {
  203. const { reports } = record;
  204. const report = childIndex === -1 ? reports[0] : record;
  205. return (
  206. <div className="">
  207. <IconButton
  208. type="report"
  209. tip="report"
  210. onClick={() => {
  211. Question.reportLink({ report });
  212. }}
  213. />
  214. </div>
  215. );
  216. },
  217. },
  218. ];
  219. this.examinationColumns = [
  220. { key: 'title', title: '模考名称', fixSort: true },
  221. {
  222. key: 'latest_time',
  223. title: '做题时间',
  224. fixSort: true,
  225. render: (text, record) => {
  226. const time = formatDate(record.latestTime, 'YYYY-MM-DD HH:mm:ss');
  227. return (
  228. <div className="sub">
  229. <div className="t-2 t-s-12">{time.split(' ')[0]}</div>
  230. <div className="t-6 t-s-12">{time.split(' ')[1]}</div>
  231. </div>
  232. );
  233. },
  234. },
  235. {
  236. key: 'overall',
  237. title: 'Overall',
  238. render: (text, record) => {
  239. const [report] = record.reports;
  240. if (!report) return null;
  241. if (!report.qxCat) {
  242. return (
  243. <div className="f-s-12">
  244. 仅CAT模考
  245. <br />
  246. 提供分数
  247. </div>
  248. );
  249. }
  250. return (
  251. <div className="sub">
  252. <div className="t-2 t-s-12">{report.score.totalScore}</div>
  253. <div className="t-6 t-s-12">
  254. {record.qxCat === 1
  255. ? Math.round(record.origin.totalScore / record.origin.totalTimes)
  256. : Math.round(record.origin.secondTotalScore / record.origin.secondTotalTimes)}
  257. </div>
  258. </div>
  259. );
  260. },
  261. },
  262. {
  263. key: 'verbal',
  264. title: 'Verbal',
  265. render: (text, record) => {
  266. const [report] = record.reports;
  267. if (!report) return null;
  268. if (!report.qxCat) {
  269. return (
  270. <div className="f-s-12">
  271. {formatPercent(report.setting.number.verbal, this.nums.verbal.number, false)}
  272. </div>
  273. );
  274. }
  275. return (
  276. <div className="sub">
  277. <div className="t-2 t-s-12">{report.score.verbalScore}</div>
  278. <div className="t-6 t-s-12">
  279. {record.qxCat === 1
  280. ? Math.round(record.origin.verbalScore / record.origin.totalTimes)
  281. : Math.round(record.origin.secondVerbalScore / record.origin.secondTotalTimes)}
  282. </div>
  283. </div>
  284. );
  285. },
  286. },
  287. {
  288. key: 'quant',
  289. title: 'Quant',
  290. render: (text, record) => {
  291. const [report] = record.reports;
  292. if (!report) return null;
  293. if (!report.qxCat) {
  294. return (
  295. <div className="f-s-12">{formatPercent(report.setting.number.quant, this.nums.quant.number, false)}</div>
  296. );
  297. }
  298. return (
  299. <div className="sub">
  300. <div className="t-2 t-s-12">{report.score.quantScore}</div>
  301. <div className="t-6 t-s-12">
  302. {record.qxCat === 1
  303. ? Math.round(record.origin.quantScore / record.origin.totalTimes)
  304. : Math.round(record.origin.secondQuantScore / record.origin.secondTotalTimes)}
  305. </div>
  306. </div>
  307. );
  308. },
  309. },
  310. {
  311. key: 'ir',
  312. title: 'IR',
  313. render: (text, record) => {
  314. const [report] = record.reports;
  315. if (!report) return null;
  316. if (!report.qxCat) {
  317. return <div className="f-s-12">{formatPercent(report.setting.number.ir, this.nums.ir.number, false)}</div>;
  318. }
  319. return (
  320. <div className="sub">
  321. <div className="t-2 t-s-12">{report.score.irScore}</div>
  322. <div className="t-6 t-s-12">
  323. {record.qxCat === 1
  324. ? Math.round(record.origin.irScore / record.origin.totalTimes)
  325. : Math.round(record.origin.secondIrScore / record.origin.secondTotalTimes)}
  326. </div>
  327. </div>
  328. );
  329. },
  330. },
  331. {
  332. key: 'report',
  333. title: '报告',
  334. render: (text, record) => {
  335. const [report] = record.reports;
  336. return (
  337. <IconButton
  338. type="report"
  339. tip="report"
  340. onClick={() => {
  341. Question.reportLink({ report });
  342. }}
  343. />
  344. );
  345. },
  346. },
  347. ];
  348. this.originColumns = [
  349. {
  350. key: 'title',
  351. title: '名称',
  352. fixSort: true,
  353. render: (text, record) => {
  354. const { reports } = record;
  355. return reports.map((report, index) => {
  356. return <div className="sub">{index === 0 && text}</div>;
  357. });
  358. },
  359. },
  360. {
  361. key: 'latest_time',
  362. title: '做题时间',
  363. fixSort: true,
  364. render: (text, record) => {
  365. const time = formatDate(record.latestTime, 'YYYY-MM-DD HH:mm:ss');
  366. return (
  367. <div className="sub">
  368. <div className="t-2 t-s-12">{time.split(' ')[0]}</div>
  369. <div className="t-6 t-s-12">{time.split(' ')[1]}</div>
  370. </div>
  371. );
  372. },
  373. },
  374. {
  375. key: 'questionType',
  376. title: '题型',
  377. render: (text, record) => {
  378. return record.questionTypes.map(row => <p>{QuestionnTypeMap[row]}</p>);
  379. },
  380. },
  381. {
  382. key: 'progress',
  383. title: '完成度',
  384. render: (text, record) => {
  385. const { reports } = record;
  386. return reports.map(report => {
  387. return (
  388. <div className="sub">
  389. <div className="t-2 t-s-12">{formatPercent(report.userNumber, report.questionNumber, false)}</div>
  390. <div className="t-6 t-s-12">
  391. {report.userNumber}/{report.questionNumber}
  392. </div>
  393. </div>
  394. );
  395. });
  396. },
  397. },
  398. {
  399. key: 'correct',
  400. title: '正确率',
  401. sort: true,
  402. render: (text, record) => {
  403. const { reports } = record;
  404. return reports.map(report => {
  405. return (
  406. <div className="sub">
  407. <div className="t-2 t-s-12">{formatPercent(report.userCorrect, report.userNumber, false)}</div>
  408. </div>
  409. );
  410. });
  411. },
  412. },
  413. {
  414. key: 'time',
  415. title: '平均耗时',
  416. sort: true,
  417. render: (text, record) => {
  418. const { reports } = record;
  419. return reports.map(report => {
  420. return (
  421. <div className="sub">
  422. <div className="t-2 t-s-12">{formatSeconds(report.userTime / report.userNumber)}</div>
  423. </div>
  424. );
  425. });
  426. },
  427. },
  428. {
  429. key: 'report',
  430. title: '报告',
  431. render: (text, record) => {
  432. const { reports } = record;
  433. return reports.map(report => {
  434. return (
  435. <div className="sub">
  436. <IconButton
  437. type="report"
  438. tip="report"
  439. onClick={() => {
  440. Question.reportLink({ report });
  441. }}
  442. />
  443. </div>
  444. );
  445. });
  446. },
  447. },
  448. ];
  449. }
  450. initData() {
  451. const data = Object.assign(this.state, this.state.search);
  452. data.filterMap = this.state.search;
  453. if (data.order) {
  454. data.sortMap = { [data.order]: data.direction };
  455. }
  456. if (data.timerange) {
  457. data.filterMap.timerange = data.timerange;
  458. }
  459. const [startTime, endTime] = timeRange(data.timerange);
  460. switch (data.tab) {
  461. case 'error':
  462. case 'collect':
  463. My.listReport(
  464. Object.assign({ origin: data.tab, startTime, endTime }, this.state.search, {
  465. order: Object.keys(data.sortMap)
  466. .map(key => {
  467. return `${key} ${data.sortMap[key]}`;
  468. })
  469. .join(','),
  470. }),
  471. ).then(result => {
  472. result.list = result.list.map(row => {
  473. row.questionTypes = row.questionTypes || [];
  474. row.reports = row.reports || [];
  475. row.stat = row.stat || {};
  476. return row;
  477. });
  478. this.setState({ list: result.list, total: result.total, page: data.page, columns: this.originColumns });
  479. });
  480. break;
  481. case 'exercise':
  482. case 'examination':
  483. default:
  484. refreshQuestionType(this, data.subject, data.questionType, {
  485. all: true,
  486. needSentence: true,
  487. allSubject: true,
  488. }).then(({ questionTypes, courseModules }) => {
  489. return refreshStruct(this, data.tab, data.one, data.two, {
  490. all: true,
  491. needPreview: true,
  492. needTextbook: false,
  493. }).then(({ structIds, latest, year }) => {
  494. My.listReport(
  495. Object.assign(
  496. { module: data.tab, questionTypes, structIds, latest, year, courseModules, startTime, endTime },
  497. this.state.search,
  498. {
  499. order: Object.keys(data.sortMap)
  500. .map(key => {
  501. return `${key} ${data.sortMap[key]}`;
  502. })
  503. .join(','),
  504. },
  505. ),
  506. ).then(result => {
  507. result.list = result.list.map(row => {
  508. row.questionTypes = row.questionTypes || [];
  509. row.reports = row.reports || [];
  510. row.stat = row.stat || {};
  511. row.reports.forEach(r => {
  512. r.stat = row.stat;
  513. });
  514. row.children = [];
  515. row.show = [];
  516. return row;
  517. });
  518. this.setState({
  519. list: result.list,
  520. total: result.total,
  521. page: data.page,
  522. columns: data.tab === 'exercise' ? this.exerciseColumns : this.examinationColumns,
  523. });
  524. });
  525. });
  526. });
  527. }
  528. }
  529. onChangeShowHistory(index, childIndex, checked) {
  530. const { list } = this.state;
  531. const item = list[index];
  532. const { reports } = item;
  533. const { children } = item;
  534. const show = children.map(row => row.id);
  535. const childId = reports[childIndex].id;
  536. // 第一个不允许切换
  537. if (checked) {
  538. if (show.indexOf(childId) >= 0) return;
  539. children.push(reports[childIndex]);
  540. } else {
  541. const k = show.indexOf(childId);
  542. if (k < 0) return;
  543. children.splice(k, 1);
  544. }
  545. list[index].children = children;
  546. list[index].show = children.map(row => row.id);
  547. this.setState({ list });
  548. }
  549. onTabChange(tab) {
  550. const data = { tab };
  551. this.refreshQuery(data);
  552. }
  553. onFilter(value) {
  554. this.search(value, false);
  555. this.initData();
  556. }
  557. onSearch(value) {
  558. this.search({ keyword: value }, false);
  559. this.initData();
  560. }
  561. onSort(value) {
  562. const keys = Object.keys(value);
  563. // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null });
  564. const { sortMap } = this.state;
  565. const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0;
  566. this.search({ order: keys.length ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }, false);
  567. this.initData();
  568. }
  569. onChangePage(page) {
  570. this.search({ page }, false);
  571. this.initData();
  572. }
  573. renderView() {
  574. const { config } = this.props;
  575. return <UserLayout active={config.key} menu={menu} center={this.renderTable()} />;
  576. }
  577. renderTable() {
  578. const {
  579. tab,
  580. questionSubjectSelect,
  581. questionSubjectMap = {},
  582. oneSelect,
  583. twoSelectMap = {},
  584. filterMap = {},
  585. sortMap = {},
  586. list = [],
  587. } = this.state;
  588. const { page, total, columns } = this.state;
  589. const selectList = [];
  590. if (tab === 'exercise') {
  591. selectList.push({
  592. children: [
  593. {
  594. key: 'subject',
  595. placeholder: '学科',
  596. select: questionSubjectSelect,
  597. },
  598. {
  599. placeholder: '题型',
  600. key: 'questionType',
  601. be: 'subject',
  602. selectMap: questionSubjectMap,
  603. },
  604. ],
  605. });
  606. }
  607. if (tab === 'exercise' || tab === 'examination') {
  608. selectList.push({
  609. label: '范围',
  610. children: [
  611. {
  612. key: 'one',
  613. placeholder: '全部',
  614. select: oneSelect,
  615. },
  616. {
  617. key: 'two',
  618. be: 'one',
  619. placeholder: '全部',
  620. selectMap: twoSelectMap,
  621. },
  622. ],
  623. });
  624. }
  625. selectList.push({
  626. right: true,
  627. key: 'timerange',
  628. select: TimeRange,
  629. });
  630. return (
  631. <div className="table-layout">
  632. <Tabs
  633. border
  634. type="division"
  635. theme="theme"
  636. size="small"
  637. space={2.5}
  638. width={100}
  639. active={tab}
  640. tabs={[
  641. { key: 'exercise', title: '练习' },
  642. { key: 'examination', title: '模考' },
  643. { key: 'error', title: '错误组卷' },
  644. { key: 'collect', title: '收藏组卷' },
  645. ]}
  646. onChange={key => this.onTabChange(key)}
  647. />
  648. <UserAction
  649. search
  650. defaultSearch={filterMap.keyword}
  651. selectList={selectList}
  652. filterMap={filterMap}
  653. onFilter={value => this.onFilter(value)}
  654. onChange={key => this.onChangeTab(key)}
  655. onSearch={value => this.onSearch(value)}
  656. />
  657. <UserTable
  658. even="children"
  659. columns={columns}
  660. sortMap={sortMap}
  661. data={list}
  662. current={page}
  663. total={total}
  664. pageSize={this.state.search.size}
  665. selectList={selectList}
  666. onSelect={l => this.onSelect(l)}
  667. onSort={v => this.onSort(v)}
  668. onChange={p => this.onChangePage(p)}
  669. />
  670. </div>
  671. );
  672. }
  673. }