page.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import React from 'react';
  2. import { Button } from 'antd';
  3. import { Link } from 'react-router-dom';
  4. import './index.less';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. import FilterLayout from '@src/layouts/FilterLayout';
  8. import ActionLayout from '@src/layouts/ActionLayout';
  9. import TableLayout from '@src/layouts/TableLayout';
  10. import { QuestionType, QuestionDifficult } from '@src/services/Constant';
  11. import { getMap, formatTreeData, bindSearch, formatDate } from '@src/services/Tools';
  12. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  13. import { Exercise } from '../../../stores/exercise';
  14. import { System } from '../../../stores/system';
  15. import { Question } from '../../../stores/question';
  16. import { Slient } from '../../../stores/slient';
  17. const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
  18. const filterForm = [
  19. {
  20. key: 'type',
  21. type: 'select',
  22. allowClear: true,
  23. name: '题型',
  24. select: QuestionType,
  25. placeholder: '请选择',
  26. number: true,
  27. },
  28. {
  29. key: 'struct_id',
  30. type: 'tree',
  31. allowClear: true,
  32. name: '分册',
  33. select: [],
  34. placeholder: '请选择',
  35. number: true,
  36. },
  37. {
  38. key: 'paper_id',
  39. type: 'select',
  40. allowClear: true,
  41. name: '练习册',
  42. select: [],
  43. placeholder: '请选择',
  44. number: true,
  45. },
  46. {
  47. key: 'place',
  48. type: 'select',
  49. allowClear: true,
  50. name: '考点',
  51. select: [],
  52. placeholder: '请选择',
  53. number: true,
  54. },
  55. {
  56. key: 'difficult',
  57. type: 'select',
  58. allowClear: true,
  59. name: '难度',
  60. select: QuestionDifficult,
  61. placeholder: '请选择',
  62. number: true,
  63. },
  64. {
  65. key: 'time',
  66. type: 'daterange',
  67. name: '修改时间',
  68. },
  69. {
  70. key: 'question_no_id',
  71. type: 'select',
  72. name: '题目ID',
  73. select: [],
  74. number: true,
  75. placeholder: '请输入',
  76. },
  77. ];
  78. export default class extends Page {
  79. constructor(props) {
  80. super(props);
  81. this.actionList = [{
  82. key: 'add',
  83. name: '新建',
  84. render: (item) => {
  85. return <Button onClick={() => {
  86. linkTo('/subject/question');
  87. }}>{item.name}</Button>;
  88. },
  89. }, {
  90. key: 'auto',
  91. name: '重新组卷',
  92. }, {
  93. key: 'delete',
  94. name: '批量删除',
  95. needSelect: 1,
  96. }];
  97. this.categoryMap = {};
  98. this.columns = [{
  99. title: '学科',
  100. dataIndex: 'first',
  101. render: (text, record) => {
  102. return this.categoryMap[record.questionNo.moduleStruct[0]] || text;
  103. },
  104. }, {
  105. title: '题型',
  106. dataIndex: 'type',
  107. render: (text, record) => {
  108. return QuestionTypeMap[record.question.type] || text;
  109. },
  110. }, {
  111. title: '练习册',
  112. dataIndex: 'paper',
  113. render: (text) => {
  114. return text.title;
  115. },
  116. }, {
  117. title: '考点',
  118. dataIndex: 'place',
  119. render: (text, record) => {
  120. return record.question.place;
  121. },
  122. }, {
  123. title: '难度',
  124. dataIndex: 'difficlut',
  125. render: (text, record) => {
  126. return record.question.difficult;
  127. },
  128. }, {
  129. title: '易错度',
  130. dataIndex: 'correct',
  131. render: (text, record) => {
  132. return `${record.questionNo.totalCorrect * 100 / record.questionNo.totalNumber}%`;
  133. },
  134. }, {
  135. title: '平均时间',
  136. dataIndex: 'time',
  137. render: (text, record) => {
  138. return `${record.questionNo.totalTime / record.questionNo.totalNumber}s`;
  139. },
  140. }, {
  141. title: '序号',
  142. dataIndex: 'no',
  143. render: (text, record) => {
  144. const { search } = this.state;
  145. if (search.paper_id) {
  146. return record.paper.no;
  147. }
  148. return '--';
  149. },
  150. }, {
  151. title: '修改时间',
  152. dataIndex: 'updateTime',
  153. render: (text, record) => {
  154. return formatDate(record.question.updateTime);
  155. },
  156. }, {
  157. title: '操作',
  158. dataIndex: 'handler',
  159. render: (text, record) => {
  160. return <div className="table-button">
  161. {(
  162. <Link to={`/subject/question/${record.question_id}`}>编辑</Link>
  163. )}
  164. </div>;
  165. },
  166. }];
  167. }
  168. initAuto() {
  169. this.outPage();
  170. this.interval = setInterval(() => {
  171. Slient.exerciseAuto().then((result) => {
  172. if (result.process == null || result.process === 100) {
  173. this.actionList[1].disabled = false;
  174. result.process = 100;
  175. } else {
  176. this.actionList[1].disabled = true;
  177. }
  178. this.setState({ process: result.process });
  179. });
  180. }, 30000);
  181. }
  182. outPage() {
  183. if (this.interval) {
  184. clearInterval(this.interval);
  185. }
  186. }
  187. init() {
  188. Exercise.allStruct().then(result => {
  189. const list = result.filter(row => row.level > 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  190. filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
  191. this.categoryMap = getMap(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }), 'id', 'title');
  192. this.setState({ exercise: result });
  193. });
  194. System.getPlace().then(result => {
  195. filterForm[3].select = [].concat(...Object.keys(result).map(key => result[key]));
  196. this.setState({ place: result });
  197. });
  198. bindSearch(filterForm, 'paper_id', this, (search) => {
  199. return Exercise.listPaper(search);
  200. }, (row) => {
  201. return {
  202. title: row.title,
  203. value: row.id,
  204. };
  205. }, [], null);
  206. bindSearch(filterForm, 'question_no_id', this, (search) => {
  207. return Question.searchNo(search);
  208. }, (row) => {
  209. return {
  210. title: row.no,
  211. value: row.id,
  212. };
  213. }, [], null);
  214. this.initAuto();
  215. }
  216. initData() {
  217. const { search } = this.state;
  218. const data = Object.assign({}, search);
  219. if (data.time) {
  220. data.startTime = data.time[0] || '';
  221. data.endTime = data.time[1] || '';
  222. }
  223. Exercise.listQuestion(data).then(result => {
  224. this.setTableData(result.list, result.total);
  225. });
  226. }
  227. autoAction() {
  228. asyncDelConfirm('组卷确认', '是否重新组卷?', () => {
  229. return Exercise.auto();
  230. }).then(() => {
  231. asyncSMessage('开始组卷!');
  232. this.refresh();
  233. });
  234. }
  235. deleteAction() {
  236. const { selectedRows } = this.state;
  237. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  238. return Promise.all(selectedRows.map(row => Question.del({ id: row.question_id })));
  239. }).then(() => {
  240. asyncSMessage('删除成功!');
  241. this.refresh();
  242. });
  243. }
  244. renderView() {
  245. return <Block flex>
  246. <FilterLayout
  247. show
  248. itemList={filterForm}
  249. data={this.state.search}
  250. onChange={data => {
  251. if (data.time.length > 0) {
  252. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  253. }
  254. this.search(data);
  255. }} />
  256. <ActionLayout
  257. itemList={this.actionList}
  258. selectedKeys={this.state.selectedKeys}
  259. onAction={key => this.onAction(key)}
  260. />
  261. <TableLayout
  262. select
  263. columns={this.columns}
  264. list={this.state.list}
  265. pagination={this.state.page}
  266. loading={this.props.core.loading}
  267. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  268. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  269. selectedKeys={this.state.selectedKeys}
  270. />
  271. </Block>;
  272. }
  273. }