page.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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, formatPercent } from '@src/services/Tools';
  11. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. import { QuestionType, QuestionDifficult } from '../../../../Constant';
  13. import { Question } from '../../../stores/question';
  14. import { Examination } from '../../../stores/examination';
  15. const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
  16. const filterForm = [
  17. {
  18. key: 'structId',
  19. type: 'tree',
  20. allowClear: true,
  21. name: '出题原理',
  22. select: [],
  23. placeholder: '请选择',
  24. number: true,
  25. },
  26. {
  27. key: 'paperId',
  28. type: 'select',
  29. allowClear: true,
  30. name: '练习册',
  31. select: [],
  32. placeholder: '请选择',
  33. number: true,
  34. },
  35. {
  36. key: 'difficult',
  37. type: 'select',
  38. allowClear: true,
  39. name: '难度',
  40. select: QuestionDifficult,
  41. placeholder: '请选择',
  42. number: true,
  43. },
  44. {
  45. key: 'questionType',
  46. type: 'select',
  47. allowClear: true,
  48. name: '题型',
  49. select: QuestionType,
  50. placeholder: '请选择',
  51. number: true,
  52. },
  53. {
  54. key: 'questionNoId',
  55. type: 'select',
  56. allowClear: true,
  57. name: '题目ID',
  58. select: [],
  59. number: true,
  60. placeholder: '请输入',
  61. },
  62. ];
  63. export default class extends Page {
  64. constructor(props) {
  65. super(props);
  66. this.actionList = [{
  67. key: 'add',
  68. name: '新建',
  69. render: (item) => {
  70. return <Button onClick={() => {
  71. linkTo('/subject/question');
  72. }}>{item.name}</Button>;
  73. },
  74. }, {
  75. key: 'delete',
  76. name: '批量删除',
  77. needSelect: 1,
  78. }];
  79. this.categoryMap = {};
  80. this.columns = [{
  81. title: '出题原理',
  82. dataIndex: 'first',
  83. render: (text, record) => {
  84. return this.categoryMap[record.questionNo.moduleStruct[0]] || text;
  85. },
  86. }, {
  87. title: '类别',
  88. dataIndex: 'second',
  89. render: (text, record) => {
  90. return QuestionTypeMap[record.question.questionType] || text;
  91. },
  92. }, {
  93. title: '试卷',
  94. dataIndex: 'three',
  95. render: (text, record) => {
  96. return QuestionTypeMap[record.question.questionType] || text;
  97. },
  98. }, {
  99. title: '题型',
  100. dataIndex: 'questionType',
  101. render: (text, record) => {
  102. return QuestionTypeMap[record.question.questionType] || text;
  103. },
  104. }, {
  105. title: '难度',
  106. dataIndex: 'difficlut',
  107. render: (text, record) => {
  108. return record.question.difficult;
  109. },
  110. }, {
  111. title: '错误率',
  112. dataIndex: 'correct',
  113. render: (text, record) => {
  114. return formatPercent(record.questionNo.totalNumber - record.questionNo.totalCorrect, record.questionNo.totalNumber, false);
  115. },
  116. }, {
  117. title: '修改时间',
  118. sorter: true,
  119. dataIndex: 'updateTime',
  120. render: (text, record) => {
  121. return formatDate(record.question.updateTime);
  122. },
  123. }, {
  124. title: '操作',
  125. dataIndex: 'handler',
  126. render: (text, record) => {
  127. return <div className="table-button">
  128. {(
  129. <Link to={`/subject/question/${record.question_id}`}>编辑</Link>
  130. )}
  131. </div>;
  132. },
  133. }];
  134. }
  135. init() {
  136. Examination.allStruct().then(result => {
  137. const list = result.filter(row => row.level < 3).map(row => { row.title = row.titleZh; row.value = row.id; return row; });
  138. filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  139. this.categoryMap = getMap(result.map(row => { row.title = row.titleZh; row.value = row.id; return row; }), 'id', 'title');
  140. this.setState({ examination: result });
  141. });
  142. bindSearch(filterForm, 'paperId', this, (search) => {
  143. return Examination.listPaper(search);
  144. }, (row) => {
  145. return {
  146. title: row.title,
  147. value: row.id,
  148. };
  149. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  150. bindSearch(filterForm, 'questionNoId', this, (search) => {
  151. return Question.searchNo(search);
  152. }, (row) => {
  153. return {
  154. title: row.title,
  155. value: row.id,
  156. };
  157. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  158. }
  159. initData() {
  160. const { search } = this.state;
  161. const data = Object.assign({}, search);
  162. Examination.listQuestion(data).then(result => {
  163. this.setTableData(result.list, result.total);
  164. });
  165. }
  166. deleteAction() {
  167. const { selectedRows } = this.state;
  168. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  169. return Promise.all(selectedRows.map(row => Question.del({ id: row.question_id }))).then(() => {
  170. asyncSMessage('删除成功!');
  171. this.refresh();
  172. });
  173. });
  174. }
  175. renderView() {
  176. const { examination } = this.state;
  177. return <Block flex>
  178. {examination && <FilterLayout
  179. show
  180. itemList={filterForm}
  181. data={this.state.search}
  182. onChange={data => {
  183. this.search(data);
  184. }} />}
  185. <ActionLayout
  186. itemList={this.actionList}
  187. selectedKeys={this.state.selectedKeys}
  188. onAction={key => this.onAction(key)}
  189. />
  190. <TableLayout
  191. select
  192. columns={this.tableSort(this.columns)}
  193. list={this.state.list}
  194. pagination={this.state.page}
  195. loading={this.props.core.loading}
  196. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  197. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  198. selectedKeys={this.state.selectedKeys}
  199. />
  200. </Block>;
  201. }
  202. }