LessonList.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import React, { Component } from 'react';
  2. import moment from 'moment';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import { Card, Modal, Button, message } from 'antd';
  6. import { StandardTableList } from '../../../components/AXList/index';
  7. import { renderStatus, addRowKey } from '../../../utils/utils';
  8. const Message = message;
  9. @connect(({ loading, lesson }) => ({
  10. lesson,
  11. loading: loading.models.lesson,
  12. }))
  13. export default class LessonListPage extends Component {
  14. constructor(props) {
  15. super(props);
  16. const { state } = props.location;
  17. this.state = {
  18. UIParams: (state || {}).UIParams, // 组件的状态参数
  19. Queryers: (state || {}).Queryers, // 查询的条件参数
  20. };
  21. }
  22. componentDidMount() {
  23. this.props.dispatch({
  24. type: 'lesson/fetchLessonList',
  25. payload: { ...this.state.Queryers },
  26. });
  27. }
  28. handleCreateOperation = () => {
  29. this.props.dispatch(routerRedux.push({
  30. pathname: '/product/lesson/create',
  31. state: this.state,
  32. }));
  33. }
  34. handleDeleteOperation = (item) => {
  35. Modal.confirm({
  36. okText: '确定',
  37. cancelText: '取消',
  38. title: '你确定要删除该课吗?',
  39. content: '如果该课已经被某些课程关联,则将导致删除失败,需要手动解除与这些课程的关联才可进行删除',
  40. onOk: () => {
  41. this.props.dispatch({
  42. type: 'lesson/deleteLessonItem',
  43. payload: { id: item.id },
  44. states: this.state,
  45. });
  46. },
  47. });
  48. }
  49. handleEditOperation = (item) => {
  50. this.props.dispatch(routerRedux.push({
  51. pathname: `/product/lesson/edit/${item.id}`,
  52. state: this.state,
  53. }));
  54. }
  55. handleFilterOperation = (params, states) => {
  56. this.props.dispatch({
  57. type: 'lesson/fetchLessonList',
  58. payload: params,
  59. });
  60. this.setState({
  61. UIParams: states,
  62. Queryers: params,
  63. });
  64. }
  65. handleBatchOperation = () => {
  66. Message.info('暂不支持批量操作!');
  67. }
  68. render() {
  69. const { loading, lesson } = this.props;
  70. const { list, totalSize, pageSize, pageNo } = lesson;
  71. const renderOperation = (item) => {
  72. return (
  73. <div>
  74. <Button
  75. size="small"
  76. className="editBtn"
  77. onClick={() => this.handleEditOperation(item)}
  78. >编辑
  79. </Button>
  80. <Button
  81. size="small"
  82. className="delBtn"
  83. onClick={() => this.handleDeleteOperation(item)}
  84. >删除
  85. </Button>
  86. </div>
  87. );
  88. };
  89. const batchActions = [{
  90. key: 'delete',
  91. name: '批量删除',
  92. }, {
  93. key: 'recovery',
  94. name: '批量恢复',
  95. }];
  96. const basicSearch = {
  97. keys: [{
  98. name: '课编号',
  99. field: 'code',
  100. }, {
  101. name: '课名称',
  102. field: 'name',
  103. }],
  104. };
  105. const pagination = {
  106. pageNo,
  107. pageSize,
  108. totalSize,
  109. };
  110. const columns = [{
  111. title: '课编号',
  112. key: 1,
  113. dataIndex: 'code',
  114. width: '25%',
  115. }, {
  116. title: '课名称',
  117. key: 2,
  118. dataIndex: 'title',
  119. width: '30%',
  120. }, {
  121. title: '课状态',
  122. key: 3,
  123. dataIndex: 'status',
  124. render: text => renderStatus(text),
  125. width: '12%',
  126. }, {
  127. title: '更新时间',
  128. key: 4,
  129. dataIndex: 'gmtModified',
  130. render: text => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  131. width: '20%',
  132. }, {
  133. title: '操作',
  134. key: 5,
  135. dataIndex: 'operation',
  136. render: (_, record) => renderOperation(record),
  137. width: '13%',
  138. align: 'right',
  139. }];
  140. return (
  141. <Card>
  142. <StandardTableList
  143. columns={columns}
  144. loading={loading}
  145. dataSource={addRowKey(list)}
  146. header={{
  147. basicSearch,
  148. onFilterClick: this.handleFilterOperation,
  149. onCreateClick: this.handleCreateOperation,
  150. }}
  151. footer={{
  152. pagination,
  153. batchActions,
  154. onBatchClick: this.handleBatchOperation,
  155. }}
  156. keepUIState={{ ...this.state.UIParams }}
  157. />
  158. </Card>
  159. );
  160. }
  161. }