1
0

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. },
  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: '练习册',
  109. dataIndex: 'paper',
  110. render: (text) => {
  111. return (text || {}).title;
  112. },
  113. }, {
  114. title: '考点',
  115. dataIndex: 'place',
  116. render: (text, record) => {
  117. return record.question.place;
  118. },
  119. }, {
  120. title: '难度',
  121. dataIndex: 'difficlut',
  122. render: (text, record) => {
  123. return record.question.difficult;
  124. },
  125. }, {
  126. title: '易错度',
  127. dataIndex: 'correct',
  128. render: (text, record) => {
  129. return formatPercent(record.totalNumber - record.totalCorrect, record.totalNumber, false);
  130. },
  131. }, {
  132. title: '平均时间',
  133. dataIndex: 'time',
  134. render: (text, record) => {
  135. return formatSeconds(record.totalTime / record.totalNumber);
  136. },
  137. }, {
  138. title: '序号',
  139. sorter: this.state.search.paperId,
  140. dataIndex: 'no',
  141. render: (text, record) => {
  142. const { search } = this.state;
  143. if (search.paperId) {
  144. return record.no;
  145. }
  146. return '--';
  147. },
  148. }, {
  149. title: '修改时间',
  150. sorter: true,
  151. dataIndex: 'updateTime',
  152. render: (text, record) => {
  153. return formatDate(record.question.updateTime, 'YYYY-MM-DD HH:mm:ss');
  154. },
  155. }, {
  156. title: '操作',
  157. dataIndex: 'handler',
  158. render: (text, record) => {
  159. return <div className="table-button">
  160. {(
  161. <Link to={`/subject/question/${record.questionId}`}>编辑</Link>
  162. )}
  163. {(
  164. <a onClick={() => {
  165. asyncGet(() => import('../../../components/Association'),
  166. { title: '题源联想', ids: record.question.associationContent, field: 'associationContent', module: 'exercise', modal: true },
  167. (data) => {
  168. data.id = record.questionId;
  169. data.associationContent = data.associationContent.map(row => row.id);
  170. return Question.edit(data).then(() => {
  171. asyncSMessage('修改成功!');
  172. });
  173. });
  174. }}>题源联想</a>
  175. )}
  176. </div>;
  177. },
  178. }];
  179. }
  180. initAuto() {
  181. this.outPage();
  182. this.interval = setInterval(() => {
  183. Slient.exerciseAuto().then((result) => {
  184. if (result.progress == null || result.progress === 100) {
  185. this.actionList[1].disabled = false;
  186. result.progress = 100;
  187. } else {
  188. this.actionList[1].disabled = true;
  189. }
  190. this.setState({ progress: result.progress });
  191. });
  192. }, 30000);
  193. }
  194. outPage() {
  195. if (this.interval) {
  196. clearInterval(this.interval);
  197. }
  198. }
  199. init() {
  200. Exercise.allStruct().then(result => {
  201. const list = result.filter(row => row.level >= 2).map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; });
  202. filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
  203. this.categoryMap = getMap(result.map(row => { row.title = `${row.titleZh}/${row.titleEn}`; row.value = row.id; return row; }), 'id', 'title');
  204. this.setState({ exercise: result });
  205. });
  206. System.getPlace().then(result => {
  207. filterForm[3].select = [].concat(...Object.keys(result).map(key => result[key]));
  208. this.setState({ place: result });
  209. });
  210. bindSearch(filterForm, 'paperId', this, (search) => {
  211. return Exercise.listPaper(search);
  212. }, (row) => {
  213. return {
  214. title: row.title,
  215. value: row.id,
  216. };
  217. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  218. bindSearch(filterForm, 'questionNoId', this, (search) => {
  219. return Question.searchNo(search);
  220. }, (row) => {
  221. return {
  222. title: row.title,
  223. value: row.id,
  224. };
  225. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  226. this.initAuto();
  227. }
  228. initData() {
  229. const { search } = this.state;
  230. const data = Object.assign({}, search);
  231. if (data.time) {
  232. data.startTime = data.time[0] || '';
  233. data.endTime = data.time[1] || '';
  234. }
  235. Exercise.listQuestion(data).then(result => {
  236. this.setTableData(result.list, result.total);
  237. });
  238. }
  239. autoAction() {
  240. asyncDelConfirm('组卷确认', '是否重新组卷?', () => {
  241. return Exercise.auto().then(() => {
  242. asyncSMessage('开始组卷!');
  243. this.refresh();
  244. });
  245. });
  246. }
  247. deleteAction() {
  248. const { selectedRows } = this.state;
  249. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  250. return Promise.all(selectedRows.map(row => Question.del({ id: row.question_id }))).then(() => {
  251. asyncSMessage('删除成功!');
  252. this.refresh();
  253. });
  254. });
  255. }
  256. renderView() {
  257. const { exercise } = this.state;
  258. return <Block flex>
  259. {exercise && <FilterLayout
  260. show
  261. itemList={filterForm}
  262. data={this.state.search}
  263. onChange={data => {
  264. if (data.time.length > 0) {
  265. data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  266. }
  267. console.log(data);
  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. }