page.js 8.3 KB

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