page.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import React from 'react';
  2. import { Breadcrumb, Switch } from 'antd';
  3. import './index.less';
  4. import Page from '@src/containers/Page';
  5. import { asyncConfirm, asyncSMessage } from '@src/services/AsyncTools';
  6. import { formatPercent, formatSeconds, formatDate } from '@src/services/Tools';
  7. import ListTable from '../../../components/ListTable';
  8. import ProgressText from '../../../components/ProgressText';
  9. import IconButton from '../../../components/IconButton';
  10. import Button from '../../../components/Button';
  11. import { DownloadModal } from '../../../components/OtherModal';
  12. import { Question } from '../../../stores/question';
  13. import { Textbook } from '../../../stores/textbook';
  14. import Select from '../../../components/Select';
  15. import { TextbookMinYear } from '../../../../Constant';
  16. export default class extends Page {
  17. initState() {
  18. this.columns = [{
  19. title: '练习册',
  20. width: 250,
  21. align: 'left',
  22. render: (record) => {
  23. let progress = 0;
  24. if (record.report) {
  25. progress = formatPercent(record.report.userNumber, record.report.questionNumber);
  26. }
  27. return (
  28. <div className="table-row">
  29. <div className="night f-s-16">{record.title}</div>
  30. <div>
  31. <ProgressText progress={progress} times={record.paper ? record.paper.resetTimes : 0} size="small" />
  32. </div>
  33. </div>
  34. );
  35. },
  36. }, {
  37. title: '正确率',
  38. width: 150,
  39. align: 'left',
  40. render: (record) => {
  41. let correct = '--';
  42. if (record.report) {
  43. correct = formatPercent(record.report.userCorrect, record.report.userNumber, false);
  44. }
  45. return (
  46. <div className="table-row">
  47. <div className="night f-s-16 f-w-b">{correct}</div>
  48. <div className="f-s-12">全站{formatPercent(record.stat.totalCorrect, record.stat.totalNumber, false)}</div>
  49. </div>
  50. );
  51. },
  52. }, {
  53. title: '全站用时',
  54. width: 150,
  55. align: 'left',
  56. render: (record) => {
  57. let time = '--';
  58. if (record.report) {
  59. time = formatSeconds(record.report.userTime / record.report.userNumber);
  60. }
  61. return (
  62. <div className="table-row">
  63. <div className="night f-s-16 f-w-b">{time}</div>
  64. <div className="f-s-12">全站{formatSeconds(record.stat.totalTime / record.stat.totalNumber)}</div>
  65. </div>
  66. );
  67. },
  68. }, {
  69. title: '最近做题',
  70. width: 150,
  71. align: 'left',
  72. render: (record) => {
  73. const time = record.report ? record.report.updateTime : record.paper ? record.paper.latestTime : null;
  74. return (
  75. <div className="table-row">
  76. <div>{time && formatDate(time, 'YYYY-MM-DD')}</div>
  77. <div>{time && formatDate(time, 'HH:mm')}</div>
  78. </div>
  79. );
  80. },
  81. }, {
  82. title: '操作',
  83. width: 180,
  84. align: 'left',
  85. render: (record) => {
  86. return (
  87. <div className="table-row p-t-1">
  88. {!record.report && <IconButton type="start" tip="Start" onClick={() => {
  89. Question.startLink('exercise', record);
  90. }} />}
  91. {(record.report && !record.report.isFinish) && <IconButton className="m-r-2" type="continue" tip="Continue" onClick={() => {
  92. Question.continueLink('exercise', record);
  93. }} />}
  94. {(record.report) && <IconButton type="restart" tip="Restart" onClick={() => {
  95. this.restart(record);
  96. }} />}
  97. </div>
  98. );
  99. },
  100. }, {
  101. title: '报告',
  102. width: 30,
  103. align: 'right',
  104. render: (record) => {
  105. return (
  106. <div className="table-row p-t-1">
  107. {record.report && !!record.report.isFinish && <IconButton type="report" tip="Report" onClick={() => {
  108. Question.reportLink(record);
  109. }} />}
  110. </div>
  111. );
  112. },
  113. }];
  114. this.inited = false;
  115. const year = [];
  116. const nowYear = new Date().getFullYear();
  117. for (let i = TextbookMinYear; i <= nowYear; i += 1) {
  118. year.push({
  119. title: i.toString(),
  120. key: i.toString(),
  121. });
  122. }
  123. return {
  124. yearList: year,
  125. };
  126. }
  127. initData() {
  128. const { search } = this.state;
  129. const info = {};
  130. info.latest = search.latest ? Number(search.latest) : 0;
  131. info.logic = search.logic ? search.logic : 'ds';
  132. info.year = search.year ? search.year : new Date().getFullYear().toString();
  133. const data = Object.assign(this.state, this.state.search);
  134. data.info = info;
  135. this.setState(data);
  136. this.refreshData();
  137. }
  138. refreshData() {
  139. Textbook.getInfo().then((result) => {
  140. this.setState({ textbook: result });
  141. });
  142. this.refreshTextbook();
  143. }
  144. refreshTextbook() {
  145. Textbook.listPaper(Object.assign({ year: new Date().getFullYear().toString() }, this.state.search, this.state.info))
  146. .then((result) => {
  147. this.setState({ list: result });
  148. })
  149. .catch(err => {
  150. asyncSMessage(err.message, 'warn');
  151. linkTo('/examination');
  152. });
  153. }
  154. restart(item) {
  155. asyncConfirm('提示', '你打算重做本套练习,过往做题记录可至「个人中心-报告」查看。', () => {
  156. Question.restart(item.paper.id).then(() => {
  157. this.refresh();
  158. });
  159. });
  160. }
  161. subscribe(value) {
  162. Textbook.subscribe(value)
  163. .then(() => {
  164. this.refresh();
  165. })
  166. .catch(err => {
  167. asyncSMessage(err.message, 'warn');
  168. });
  169. }
  170. renderView() {
  171. const { list, search, info = {}, textbook = {}, showDownload } = this.state;
  172. const { finish } = search;
  173. return (
  174. <div>
  175. <div className="content">
  176. <div className="textbook-head">
  177. <Breadcrumb separator=">">
  178. <Breadcrumb.Item href="/examination">模考</Breadcrumb.Item>
  179. <Breadcrumb.Item href="/examination?tab1=textbook">数学机经</Breadcrumb.Item>
  180. <Breadcrumb.Item>{info.latest ? '最新' : '往期'}</Breadcrumb.Item>
  181. <Breadcrumb.Item>{info.logic ? info.logic.toUpperCase() : ''}</Breadcrumb.Item>
  182. </Breadcrumb>
  183. {!!info.latest && !!textbook.latest && <div className='textbook-time'>最近更新:{formatDate(textbook.latest.updateTime, 'YYYY-MM-DD')}</div>}
  184. </div>
  185. <ListTable
  186. rightAction={<div>
  187. {!!info.latest && <span>邮箱订阅<Switch checked={textbook.subscribe} onChange={() => {
  188. this.subscribe(!textbook.subscribe);
  189. }} /></span>}
  190. {!!info.latest && <Button radius onClick={() => {
  191. this.setState({ showDownload: true });
  192. }}>下载</Button>}
  193. {!info.latest && <Select value={info.year} theme="default" list={this.state.yearList || []} onChange={(item) => {
  194. this.search({ year: item.key });
  195. }} />}
  196. </div>}
  197. filters={[
  198. {
  199. type: 'radio',
  200. checked: finish,
  201. list: [{ key: '0', title: '未完成' }, { key: '1', title: '已完成' }],
  202. onChange: item => {
  203. if (item.key === finish) {
  204. this.search({ finish: null });
  205. } else if (item.key === '0') {
  206. this.search({ finish: 0 });
  207. } else if (item.key === '1') {
  208. this.search({ finish: 1 });
  209. } else {
  210. this.search({ finish: null });
  211. }
  212. },
  213. },
  214. ]}
  215. data={list}
  216. columns={this.columns}
  217. />
  218. </div>
  219. <DownloadModal
  220. show={showDownload}
  221. data={textbook.latest}
  222. onConfirm={() => this.setState({ showDownload: false })}
  223. onCancel={() => this.setState({ showDownload: false })}
  224. onClose={() => this.setState({ showDownload: false })}
  225. />
  226. </div>
  227. );
  228. }
  229. }