page.js 4.7 KB

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