page.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import { asyncConfirm } from '@src/services/AsyncTools';
  5. import Tabs from '../../../components/Tabs';
  6. import Module from '../../../components/Module';
  7. import ProgressText from '../../../components/ProgressText';
  8. import IconButton from '../../../components/IconButton';
  9. import { Main } from '../../../stores/main';
  10. import { Question } from '../../../stores/question';
  11. import { QuestionDifficult } from '../../../../Constant';
  12. const LOGIC_NO = 'no';
  13. const LOGIC_PLACE = 'place';
  14. const LOGIC_DIFFICULT = 'difficult';
  15. const LOGIC_ERROR = 'error';
  16. const columns = [
  17. {
  18. title: '练习册',
  19. width: 250,
  20. align: 'left',
  21. render: item => {
  22. return (
  23. <div className="table-row">
  24. <div className="night f-s-16">{item.title}</div>
  25. <div>
  26. <ProgressText
  27. progress={item.report.id ? item.repport.userNumber / item.report.questionNumber : 0}
  28. size="small"
  29. />
  30. </div>
  31. </div>
  32. );
  33. },
  34. },
  35. {
  36. title: '正确率',
  37. width: 150,
  38. align: 'left',
  39. render: item => {
  40. return (
  41. <div className="table-row">
  42. <div className="night f-s-16 f-w-b">--</div>
  43. <div className="f-s-12">{item.stat.totalCorrect / item.stat.totalNumber}</div>
  44. </div>
  45. );
  46. },
  47. },
  48. {
  49. title: '全站用时',
  50. width: 150,
  51. align: 'left',
  52. render: item => {
  53. return (
  54. <div className="table-row">
  55. <div className="night f-s-16 f-w-b">--</div>
  56. <div className="f-s-12">全站{item.stat.totalTime / item.stat.totalNumber}s</div>
  57. </div>
  58. );
  59. },
  60. },
  61. {
  62. title: '最近做题',
  63. width: 150,
  64. align: 'left',
  65. render: () => {
  66. return (
  67. <div className="table-row">
  68. <div>2019-04-28</div>
  69. <div>07:30</div>
  70. </div>
  71. );
  72. },
  73. },
  74. {
  75. title: '操作',
  76. width: 180,
  77. align: 'left',
  78. render: item => {
  79. return (
  80. <div className="table-row p-t-1">
  81. {!item.repport.id && (
  82. <IconButton type="start" tip="Start" onClick={() => this.previewAction('start', item)} />
  83. )}
  84. {item.repport.id && (
  85. <IconButton
  86. className="m-r-2"
  87. type="continue"
  88. tip="Continue"
  89. onClick={() => this.previewAction('continue', item)}
  90. />
  91. )}
  92. {item.repport.id && (
  93. <IconButton type="restart" tip="Restart" onClick={() => this.previewAction('restart', item)} />
  94. )}
  95. </div>
  96. );
  97. },
  98. },
  99. {
  100. title: '报告',
  101. width: 30,
  102. align: 'right',
  103. render: item => {
  104. return (
  105. <div className="table-row p-t-1">
  106. {item.report.userNumber === item.report.questionNumber && <IconButton type="report" tip="Report" />}
  107. </div>
  108. );
  109. },
  110. },
  111. ];
  112. export default class extends Page {
  113. initState() {
  114. this.columns = columns;
  115. this.placeList = [];
  116. return {
  117. logic: LOGIC_NO,
  118. logicExtend: '',
  119. tabs: [{
  120. key: LOGIC_NO,
  121. title: '按顺序练习',
  122. }, {
  123. key: LOGIC_PLACE,
  124. title: '按考点练习',
  125. }, {
  126. key: LOGIC_DIFFICULT,
  127. title: '按难度练习',
  128. }, {
  129. key: LOGIC_ERROR,
  130. title: '按易错度练习',
  131. }],
  132. };
  133. }
  134. init() {
  135. const { id } = this.params;
  136. Main.getExerciseParent(id).then(result => {
  137. const navs = result;
  138. this.setState({ navs });
  139. });
  140. }
  141. initData() {
  142. this.refresh();
  143. }
  144. refresh() {
  145. const { logic } = this.state;
  146. let handler = null;
  147. switch (logic) {
  148. case LOGIC_PLACE:
  149. handler = this.refreshPlace();
  150. break;
  151. case LOGIC_DIFFICULT:
  152. handler = this.refreshDifficult();
  153. break;
  154. default:
  155. handler = Promise.resolve();
  156. }
  157. handler.then(() => {
  158. this.refreshExercise();
  159. });
  160. }
  161. refreshPlace() {
  162. if (this.placeList.length > 0) {
  163. this.setState({ logicExtend: this.placeList[0] });
  164. return Promise.resolve();
  165. }
  166. const { id } = this.params;
  167. return Question.getExercisePlace(id).then(result => {
  168. this.placeList = result;
  169. this.setState({ logicExtend: this.placeList[0] });
  170. });
  171. }
  172. refreshDifficult() {
  173. this.setState({ logicExtend: QuestionDifficult[0].value });
  174. return Promise.resolve();
  175. }
  176. refreshExercise() {
  177. Question.getExerciseList(this.state.search)
  178. .then((result) => {
  179. this.setState({ list: result.list, total: result.total });
  180. });
  181. }
  182. onChangeTab(level, tab) {
  183. const state = {};
  184. state[`level${level}Tab`] = tab;
  185. this.setState(state);
  186. this.refresh();
  187. }
  188. restart(item) {
  189. asyncConfirm('提示', '是否重置', () => {
  190. Question.restart(item.report.id).then(() => {
  191. this.refresh();
  192. });
  193. });
  194. }
  195. start(type, item) {
  196. linkTo(`/paper/process/${type}/${item.id}`);
  197. }
  198. continue(type, item) {
  199. linkTo(`/paper/process/${type}/${item.id}?r=${item.report.id}`);
  200. }
  201. renderView() {
  202. const { level1Tab = {}, level2Tab = {}, tabs } = this.state;
  203. return (
  204. <div>
  205. <div className="content">
  206. <Module className="m-t-2">
  207. <Tabs type="card" active={level1Tab.key} tabs={tabs} onChange={key => {
  208. this.onChangeTab(1, key);
  209. }} />
  210. {level1Tab.children > 1 && <Tabs active={level2Tab.key} tabs={level1Tab.children} onChange={key => this.onChangeTab(2, key)} />}
  211. </Module>
  212. </div>
  213. </div>
  214. );
  215. }
  216. }