page.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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, formatSeconds, formatPercent } 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. key: 'questionType',
  21. type: 'select',
  22. allowClear: true,
  23. name: '题型',
  24. select: QuestionType,
  25. placeholder: '请选择',
  26. number: true,
  27. },
  28. {
  29. key: 'structId',
  30. type: 'tree',
  31. allowClear: true,
  32. name: '分册',
  33. select: [],
  34. placeholder: '请选择',
  35. number: true,
  36. },
  37. {
  38. key: 'paperId',
  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: 'questionNoId',
  71. type: 'select',
  72. allowClear: true,
  73. name: '题目ID',
  74. select: [],
  75. number: true,
  76. placeholder: '请输入',
  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: 'questionType',
  107. render: (text, record) => {
  108. return QuestionTypeMap[record.question.questionType] || 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 formatPercent(record.questionNo.totalNumber - record.questionNo.totalCorrect, record.questionNo.totalNumber, false);
  133. },
  134. }, {
  135. title: '平均时间',
  136. dataIndex: 'time',
  137. render: (text, record) => {
  138. return formatSeconds(record.questionNo.totalTime / record.questionNo.totalNumber);
  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. {(
  165. <a onClick={() => {
  166. asyncGet(() => import('../../../components/Association'),
  167. { title: '题源联想', ids: record.question.associationContent, field: 'associationContent', module: 'exercise', modal: true },
  168. (data) => {
  169. data.id = record.questionId;
  170. data.associationContent = data.associationContent.map(row => row.id);
  171. return Question.edit(data).then(() => {
  172. asyncSMessage('修改成功!');
  173. });
  174. });
  175. }}>题源联想</a>
  176. )}
  177. </div>;
  178. },
  179. }];
  180. }
  181. initAuto() {
  182. this.outPage();
  183. this.interval = setInterval(() => {
  184. Slient.exerciseAuto().then((result) => {
  185. if (result.progress == null || result.progress === 100) {
  186. this.actionList[1].disabled = false;
  187. result.progress = 100;
  188. } else {
  189. this.actionList[1].disabled = true;
  190. }
  191. this.setState({ progress: result.progress });
  192. });
  193. }, 30000);
  194. }
  195. outPage() {
  196. if (this.interval) {
  197. clearInterval(this.interval);
  198. }
  199. }
  200. init() {
  201. Exercise.allStruct().then(result => {
  202. const list = result.filter(row => row.level >= 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  203. filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
  204. this.categoryMap = getMap(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }), 'id', 'title');
  205. this.setState({ exercise: result });
  206. });
  207. System.getPlace().then(result => {
  208. filterForm[3].select = [].concat(...Object.keys(result).map(key => result[key]));
  209. this.setState({ place: result });
  210. });
  211. bindSearch(filterForm, 'paperId', this, (search) => {
  212. return Exercise.listPaper(search);
  213. }, (row) => {
  214. return {
  215. title: row.title,
  216. value: row.id,
  217. };
  218. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  219. bindSearch(filterForm, 'questionNoId', this, (search) => {
  220. return Question.searchNo(search);
  221. }, (row) => {
  222. return {
  223. title: row.title,
  224. value: row.id,
  225. };
  226. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  227. this.initAuto();
  228. }
  229. initData() {
  230. const { search } = this.state;
  231. const data = Object.assign({}, search);
  232. if (data.time) {
  233. data.startTime = data.time[0] || '';
  234. data.endTime = data.time[1] || '';
  235. }
  236. Exercise.listQuestion(data).then(result => {
  237. this.setTableData(result.list, result.total);
  238. });
  239. }
  240. autoAction() {
  241. asyncDelConfirm('组卷确认', '是否重新组卷?', () => {
  242. return Exercise.auto().then(() => {
  243. asyncSMessage('开始组卷!');
  244. this.refresh();
  245. });
  246. });
  247. }
  248. deleteAction() {
  249. const { selectedRows } = this.state;
  250. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  251. return Promise.all(selectedRows.map(row => Question.del({ id: row.question_id }))).then(() => {
  252. asyncSMessage('删除成功!');
  253. this.refresh();
  254. });
  255. });
  256. }
  257. renderView() {
  258. const { exercise } = this.state;
  259. return <Block flex>
  260. {exercise && <FilterLayout
  261. show
  262. itemList={filterForm}
  263. data={this.state.search}
  264. onChange={data => {
  265. if (data.time.length > 0) {
  266. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  267. }
  268. this.search(data);
  269. }} />}
  270. <ActionLayout
  271. itemList={this.actionList}
  272. selectedKeys={this.state.selectedKeys}
  273. onAction={key => this.onAction(key)}
  274. />
  275. <TableLayout
  276. select
  277. columns={this.tableSort(this.columns)}
  278. list={this.state.list}
  279. pagination={this.state.page}
  280. loading={this.props.core.loading}
  281. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  282. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  283. selectedKeys={this.state.selectedKeys}
  284. />
  285. </Block>;
  286. }
  287. }