page.js 6.0 KB

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