page.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 } from '@src/services/Tools';
  11. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  12. import { CourseModule, QuestionType } from '../../../../Constant';
  13. import { Exercise } from '../../../stores/exercise';
  14. import { Course } from '../../../stores/course';
  15. import { Preview } from '../../../stores/preview';
  16. const CourseModuleMap = getMap(CourseModule, 'value', 'label');
  17. const QuestionTypeMap = getMap(QuestionType, 'value', 'label');
  18. export default class extends Page {
  19. init() {
  20. this.exerciseMap = {};
  21. this.actionList = [{
  22. key: 'addVideo',
  23. type: 'primary',
  24. name: '创建视频作业',
  25. render: (item) => {
  26. return <Link to='/course/preview/detail?module=video'><Button type='primary'>{item.name}</Button></Link>;
  27. },
  28. }, {
  29. key: 'addOnline',
  30. type: 'primary',
  31. name: '创建小班作业',
  32. render: (item) => {
  33. return <Link to='/course/preview/detail?module=online'><Button type='primary'>{item.name}</Button></Link>;
  34. },
  35. }, {
  36. key: 'addVs',
  37. type: 'primary',
  38. name: '创建1vs1作业',
  39. render: (item) => {
  40. return <Link to='/course/preview/detail?module=vs'><Button type='primary'>{item.name}</Button></Link>;
  41. },
  42. }];
  43. this.filterForm = [{
  44. key: 'courseModule',
  45. type: 'select',
  46. allowClear: true,
  47. name: '课程类型',
  48. placeholder: '请选择',
  49. select: CourseModule,
  50. }, {
  51. key: 'questionType',
  52. type: 'select',
  53. allowClear: true,
  54. name: '题型',
  55. placeholder: '请选择',
  56. select: QuestionType,
  57. }, {
  58. key: 'courseId',
  59. type: 'select',
  60. name: '课程名称',
  61. select: [],
  62. number: true,
  63. placeholder: '请选择',
  64. }];
  65. this.columns = [{
  66. title: '课程类型',
  67. dataIndex: 'courseModule',
  68. render: (text) => {
  69. return CourseModuleMap[text] || text;
  70. },
  71. }, {
  72. title: '课程名称',
  73. dataIndex: 'course.title',
  74. }, {
  75. title: '题型',
  76. dataIndex: 'questionType',
  77. render: (text) => {
  78. return QuestionTypeMap[text] || '';
  79. },
  80. }, {
  81. title: '作业标题',
  82. dataIndex: 'title',
  83. }, {
  84. title: '操作',
  85. dataIndex: 'handler',
  86. render: (text, record) => {
  87. return <div className="table-button">
  88. {(
  89. <Link to={`/course/preview/detail/${record.id}`}>编辑</Link>
  90. )}
  91. </div>;
  92. },
  93. }];
  94. Exercise.courseStruct().then((result) => {
  95. const list = result.map(row => { row.title = `${row.titleZh}`; row.value = row.id; return row; });
  96. this.filterForm[1].tree = formatTreeData(list, 'id', 'title', 'parentId');
  97. this.exerciseMap = getMap(result.map(row => {
  98. row.title = `${row.titleZh}`;
  99. row.value = row.id;
  100. return row;
  101. }), 'id', 'title');
  102. this.setState({ exercise: result });
  103. });
  104. bindSearch(this.filterForm, 'courseId', this, (search) => {
  105. return Course.list(search);
  106. }, (row) => {
  107. return {
  108. title: row.title,
  109. value: row.id,
  110. };
  111. }, this.state.search.courseId ? Number(this.state.search.courseId) : null, null);
  112. }
  113. initData() {
  114. Preview.list(this.state.search).then(result => {
  115. this.setTableData(result.list, result.total);
  116. });
  117. }
  118. deleteAction() {
  119. const { selectedKeys } = this.state;
  120. asyncDelConfirm('删除确认', '是否删除选中作业?', () => {
  121. return Promise.all(selectedKeys.map(row => Preview.del({ id: row }))).then(() => {
  122. asyncSMessage('删除成功!');
  123. this.refresh();
  124. });
  125. });
  126. }
  127. renderView() {
  128. const { exercise } = this.state;
  129. return <Block flex>
  130. {exercise && <FilterLayout
  131. show
  132. itemList={this.filterForm}
  133. data={this.state.search}
  134. onChange={data => {
  135. data.page = 1;
  136. this.search(data);
  137. }} />}
  138. <ActionLayout
  139. itemList={this.actionList}
  140. selectedKeys={this.state.selectedKeys}
  141. onAction={key => this.onAction(key)}
  142. />
  143. <TableLayout
  144. columns={this.tableSort(this.columns)}
  145. list={this.state.list}
  146. pagination={this.state.page}
  147. loading={this.props.core.loading}
  148. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  149. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  150. selectedKeys={this.state.selectedKeys}
  151. />
  152. </Block>;
  153. }
  154. }