page.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. return Question.searchNo(search);
  159. }, (row) => {
  160. return {
  161. title: row.title,
  162. value: row.id,
  163. };
  164. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  165. }
  166. initData() {
  167. const { search } = this.state;
  168. const data = Object.assign({}, search);
  169. Examination.listQuestion(data).then(result => {
  170. this.setTableData(result.list, result.total);
  171. });
  172. }
  173. deleteAction() {
  174. const { selectedRows } = this.state;
  175. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  176. return Promise.all(selectedRows.map(row => Question.delNo({ id: row.id }))).then(() => {
  177. asyncSMessage('删除成功!');
  178. this.refresh();
  179. });
  180. });
  181. }
  182. renderView() {
  183. const { examination } = this.state;
  184. return <Block flex>
  185. {examination && <FilterLayout
  186. show
  187. itemList={filterForm}
  188. data={this.state.search}
  189. onChange={data => {
  190. data.page = 1;
  191. this.search(data);
  192. }} />}
  193. <ActionLayout
  194. itemList={this.actionList}
  195. selectedKeys={this.state.selectedKeys}
  196. onAction={key => this.onAction(key)}
  197. />
  198. <TableLayout
  199. select
  200. columns={this.tableSort(this.columns)}
  201. list={this.state.list}
  202. pagination={this.state.page}
  203. loading={this.props.core.loading}
  204. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  205. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  206. selectedKeys={this.state.selectedKeys}
  207. />
  208. </Block>;
  209. }
  210. }