page.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. info: {
  126. year: new Date().getFullYear().toString(),
  127. },
  128. };
  129. }
  130. initData() {
  131. const { search } = this.state;
  132. const info = {};
  133. info.latest = search.latest ? Number(search.latest) : 0;
  134. info.logic = search.logic ? search.logic : 'ds';
  135. info.year = search.year ? search.year : new Date().getFullYear().toString();
  136. const data = Object.assign(this.state, this.state.search);
  137. data.info = info;
  138. this.setState(data);
  139. this.refreshData();
  140. }
  141. refreshData() {
  142. Textbook.getInfo().then((result) => {
  143. this.setState({ textbook: result });
  144. });
  145. this.refreshTextbook();
  146. }
  147. refreshTextbook() {
  148. Textbook.listPaper(Object.assign(this.state.search, this.state.info))
  149. .then((result) => {
  150. this.setState({ list: result });
  151. })
  152. .catch(err => {
  153. asyncSMessage(err.message, 'warn');
  154. linkTo('/examination');
  155. });
  156. }
  157. restart(item) {
  158. asyncConfirm('提示', '你打算重做本套练习,过往做题记录可至「个人中心-报告」查看。', () => {
  159. Question.restart(item.paper.id).then(() => {
  160. this.refresh();
  161. });
  162. });
  163. }
  164. subscribe(value) {
  165. Textbook.subscribe(value)
  166. .then(() => {
  167. this.refresh();
  168. })
  169. .catch(err => {
  170. asyncSMessage(err.message, 'warn');
  171. });
  172. }
  173. renderView() {
  174. const { list, search, info = {}, textbook = {}, showDownload } = this.state;
  175. const { finish } = search;
  176. return (
  177. <div>
  178. <div className="content">
  179. <div className="textbook-head">
  180. <Breadcrumb separator=">">
  181. <Breadcrumb.Item href="/examination">模考</Breadcrumb.Item>
  182. <Breadcrumb.Item href="/examination?tab1=textbook">数学机经</Breadcrumb.Item>
  183. <Breadcrumb.Item>{info.latest ? '最新' : '往期'}</Breadcrumb.Item>
  184. <Breadcrumb.Item>{info.logic ? info.logic.toUpperCase() : ''}</Breadcrumb.Item>
  185. </Breadcrumb>
  186. {!!info.latest && !!textbook.latest && <div className='textbook-time'>最近更新:{formatDate(textbook.latest.updateTime, 'YYYY-MM-DD')}</div>}
  187. </div>
  188. <ListTable
  189. rightAction={<div>
  190. {!!info.latest && <span>邮箱订阅<Switch checked={textbook.subscribe} onChange={() => {
  191. this.subscribe(!textbook.subscribe);
  192. }} /></span>}
  193. {!!info.latest && <Button radius onClick={() => {
  194. this.setState({ showDownload: true });
  195. }}>下载</Button>}
  196. {!info.latest && <Select value={info.year} theme="default" list={this.state.yearList || []} onChange={(item) => {
  197. this.search({ year: item.key });
  198. }} />}
  199. </div>}
  200. filters={[
  201. {
  202. type: 'radio',
  203. checked: finish,
  204. list: [{ key: '0', title: '未完成' }, { key: '1', title: '已完成' }],
  205. onChange: item => {
  206. if (item.key === finish) {
  207. this.search({ finish: null });
  208. } else if (item.key === '0') {
  209. this.search({ finish: 0 });
  210. } else if (item.key === '1') {
  211. this.search({ finish: 1 });
  212. } else {
  213. this.search({ finish: null });
  214. }
  215. },
  216. },
  217. ]}
  218. data={list}
  219. columns={this.columns}
  220. />
  221. </div>
  222. <DownloadModal
  223. show={showDownload}
  224. data={textbook.latest}
  225. onConfirm={() => this.setState({ showDownload: false })}
  226. onCancel={() => this.setState({ showDownload: false })}
  227. onClose={() => this.setState({ showDownload: false })}
  228. />
  229. </div>
  230. );
  231. }
  232. }