page.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. dataIndex: 'title',
  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.totalNumber - record.totalCorrect, record.totalNumber, false);
  133. },
  134. }, {
  135. title: '平均时间',
  136. dataIndex: 'time',
  137. render: (text, record) => {
  138. return formatSeconds(record.totalTime / record.totalNumber);
  139. },
  140. }, {
  141. title: '序号',
  142. sorter: this.state.search.paperId,
  143. dataIndex: 'no',
  144. render: (text, record) => {
  145. const { search } = this.state;
  146. if (search.paperId) {
  147. return record.no;
  148. }
  149. return '--';
  150. },
  151. }, {
  152. title: '修改时间',
  153. sorter: true,
  154. dataIndex: 'updateTime',
  155. render: (text, record) => {
  156. return formatDate(record.question.updateTime, 'YYYY-MM-DD HH:mm:ss');
  157. },
  158. }, {
  159. title: '操作',
  160. dataIndex: 'handler',
  161. render: (text, record) => {
  162. return <div className="table-button">
  163. {(
  164. <Link to={`/subject/question/${record.questionId}`}>编辑</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.progress == null || result.progress === 100) {
  188. this.actionList[1].disabled = false;
  189. result.progress = 100;
  190. } else {
  191. this.actionList[1].disabled = true;
  192. }
  193. this.setState({ progress: result.progress });
  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.delNo({ id: row.id }))).then(() => {
  254. asyncSMessage('删除成功!');
  255. this.refresh();
  256. });
  257. });
  258. }
  259. renderView() {
  260. const { exercise } = this.state;
  261. return <Block flex>
  262. {exercise && <FilterLayout
  263. show
  264. itemList={filterForm}
  265. data={this.state.search}
  266. onChange={data => {
  267. if (data.time.length > 0) {
  268. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  269. }
  270. data.page = 1;
  271. this.search(data);
  272. }} />}
  273. <ActionLayout
  274. itemList={this.actionList}
  275. selectedKeys={this.state.selectedKeys}
  276. onAction={key => this.onAction(key)}
  277. />
  278. <TableLayout
  279. select
  280. columns={this.tableSort(this.columns)}
  281. list={this.state.list}
  282. pagination={this.state.page}
  283. loading={this.props.core.loading}
  284. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  285. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  286. selectedKeys={this.state.selectedKeys}
  287. />
  288. </Block>;
  289. }
  290. }