page.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. dataIndex: 'updateTime',
  119. render: (text, record) => {
  120. return formatDate(record.question.updateTime);
  121. },
  122. }, {
  123. title: '操作',
  124. dataIndex: 'handler',
  125. render: (text, record) => {
  126. return <div className="table-button">
  127. {(
  128. <Link to={`/subject/question/${record.question_id}`}>编辑</Link>
  129. )}
  130. </div>;
  131. },
  132. }];
  133. }
  134. init() {
  135. Examination.allStruct().then(result => {
  136. const list = result.filter(row => row.level < 3).map(row => { row.title = row.titleZh; row.value = row.id; return row; });
  137. filterForm[0].tree = formatTreeData(list, 'id', 'title', 'parentId');
  138. this.categoryMap = getMap(result.map(row => { row.title = row.titleZh; row.value = row.id; return row; }), 'id', 'title');
  139. this.setState({ examination: result });
  140. });
  141. bindSearch(filterForm, 'paperId', this, (search) => {
  142. return Examination.listPaper(search);
  143. }, (row) => {
  144. return {
  145. title: row.title,
  146. value: row.id,
  147. };
  148. }, this.state.search.paperId ? Number(this.state.search.paperId) : null, null);
  149. bindSearch(filterForm, 'questionNoId', this, (search) => {
  150. return Question.searchNo(search);
  151. }, (row) => {
  152. return {
  153. title: row.title,
  154. value: row.id,
  155. };
  156. }, this.state.search.questionNoId ? Number(this.state.search.questionNoId) : null, null);
  157. }
  158. initData() {
  159. const { search } = this.state;
  160. const data = Object.assign({}, search);
  161. Examination.listQuestion(data).then(result => {
  162. this.setTableData(result.list, result.total);
  163. });
  164. }
  165. deleteAction() {
  166. const { selectedRows } = this.state;
  167. asyncDelConfirm('删除确认', '是否删除选中题目?', () => {
  168. return Promise.all(selectedRows.map(row => Question.del({ id: row.question_id }))).then(() => {
  169. asyncSMessage('删除成功!');
  170. this.refresh();
  171. });
  172. });
  173. }
  174. renderView() {
  175. const { examination } = this.state;
  176. return <Block flex>
  177. {examination && <FilterLayout
  178. show
  179. itemList={filterForm}
  180. data={this.state.search}
  181. onChange={data => {
  182. // if (data.time.length > 0) {
  183. // data.time = [data.time[0].format('YYYY-MM-DD HH:mm:ss'), data.time[1].format('YYYY-MM-DD HH:mm:ss')];
  184. // }
  185. this.search(data);
  186. }} />}
  187. <ActionLayout
  188. itemList={this.actionList}
  189. selectedKeys={this.state.selectedKeys}
  190. onAction={key => this.onAction(key)}
  191. />
  192. <TableLayout
  193. select
  194. columns={this.tableSort(this.columns)}
  195. list={this.state.list}
  196. pagination={this.state.page}
  197. loading={this.props.core.loading}
  198. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  199. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  200. selectedKeys={this.state.selectedKeys}
  201. />
  202. </Block>;
  203. }
  204. }