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