page.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 QuestionTypeMap[record.question.questionType] || text;
  89. },
  90. }, {
  91. title: '试卷',
  92. dataIndex: 'three',
  93. render: (text, record) => {
  94. return QuestionTypeMap[record.question.questionType] || text;
  95. },
  96. }, {
  97. title: '题型',
  98. dataIndex: 'questionType',
  99. render: (text, record) => {
  100. return QuestionTypeMap[record.question.questionType] || text;
  101. },
  102. }, {
  103. title: '难度',
  104. dataIndex: 'difficlut',
  105. render: (text, record) => {
  106. return record.question.difficult;
  107. },
  108. }, {
  109. title: '错误率',
  110. dataIndex: 'correct',
  111. render: (text, record) => {
  112. return formatPercent(record.totalNumber - record.totalCorrect, record.totalNumber, false);
  113. },
  114. }, {
  115. title: '修改时间',
  116. sorter: true,
  117. dataIndex: 'updateTime',
  118. render: (text, record) => {
  119. return formatDate(record.question.updateTime, 'YYYY-MM-DD HH:mm:ss');
  120. },
  121. }, {
  122. title: '操作',
  123. dataIndex: 'handler',
  124. render: (text, record) => {
  125. return <div className="table-button">
  126. {(
  127. <Link to={`/subject/question/${record.questionId}`}>编辑</Link>
  128. )}
  129. </div>;
  130. },
  131. }];
  132. }
  133. init() {
  134. Examination.allStruct().then(result => {
  135. const list = result.filter(row => row.level < 3).map(row => { row.title = row.titleZh; row.value = row.id; return row; });
  136. filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  137. this.categoryMap = getMap(result.map(row => { row.title = row.titleZh; row.value = row.id; return row; }), 'id', 'title');
  138. this.setState({ examination: result });
  139. });
  140. bindSearch(filterForm, 'paperId', this, (search) => {
  141. return Examination.listPaper(search);
  142. }, (row) => {
  143. return {
  144. title: row.title,
  145. value: row.id,
  146. };
  147. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  148. bindSearch(filterForm, 'questionNoId', this, (search) => {
  149. return Question.searchNo(search);
  150. }, (row) => {
  151. return {
  152. title: row.title,
  153. value: row.id,
  154. };
  155. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  156. }
  157. initData() {
  158. const { search } = this.state;
  159. const data = Object.assign({}, search);
  160. Examination.listQuestion(data).then(result => {
  161. this.setTableData(result.list, result.total);
  162. });
  163. }
  164. deleteAction() {
  165. const { selectedRows } = this.state;
  166. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  167. return Promise.all(selectedRows.map(row => Question.delNo({ id: row.id }))).then(() => {
  168. asyncSMessage('删除成功!');
  169. this.refresh();
  170. });
  171. });
  172. }
  173. renderView() {
  174. const { examination } = this.state;
  175. return <Block flex>
  176. {examination && <FilterLayout
  177. show
  178. itemList={filterForm}
  179. data={this.state.search}
  180. onChange={data => {
  181. data.page = 1;
  182. this.search(data);
  183. }} />}
  184. <ActionLayout
  185. itemList={this.actionList}
  186. selectedKeys={this.state.selectedKeys}
  187. onAction={key => this.onAction(key)}
  188. />
  189. <TableLayout
  190. select
  191. columns={this.tableSort(this.columns)}
  192. list={this.state.list}
  193. pagination={this.state.page}
  194. loading={this.props.core.loading}
  195. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  196. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  197. selectedKeys={this.state.selectedKeys}
  198. />
  199. </Block>;
  200. }
  201. }