page.js 8.6 KB

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