page.js 7.6 KB

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