PictureList.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React, { Component } from 'react';
  2. import { connect } from 'dva';
  3. import { routerRedux } from 'dva/router';
  4. import { Card, Modal, Button, message } from 'antd';
  5. import PictureCardList from './PictureCardList';
  6. import PictureTableList from './PictureTableList';
  7. const Message = message;
  8. @connect(({ resource, loading }) => ({
  9. resource,
  10. loading: loading.models.resource,
  11. }))
  12. export default class PictureListPage extends Component {
  13. constructor(props) {
  14. super(props);
  15. const { state } = props.location;
  16. this.state = {
  17. UIParams: (state || {}).UIParams, // 组件的状态参数
  18. Queryers: (state || {}).Queryers, // 查询的条件参数
  19. isCard: true,
  20. };
  21. }
  22. componentDidMount() {
  23. this.props.dispatch({
  24. type: 'resource/fetchImageList',
  25. payload: { ...this.state.Queryers },
  26. });
  27. }
  28. handleShowTypeChange = () => {
  29. this.setState({ isCard: !!!this.state.isCard });
  30. }
  31. // 增加
  32. handleCreateOperation = () => {
  33. // 页面跳转把这些参数传递过去,返回的时候再传回来,来保证组件等状态不变
  34. const { Queryers, UIParams } = this.state;
  35. this.props.dispatch(
  36. routerRedux.push({
  37. pathname: '/resource/imageCreate/single',
  38. state: {
  39. Queryers,
  40. UIParams,
  41. },
  42. })
  43. );
  44. }
  45. // 删除
  46. handleDeleteOperation = (item) => {
  47. Modal.confirm({
  48. okText: '确定',
  49. cancelText: '取消',
  50. title: '你确定要删除这张图片吗?',
  51. content: '删除后所有与之关联的课件将不再显示该图片',
  52. onOk: () => {
  53. this.props.dispatch({
  54. type: 'resource/deleteImage',
  55. payload: { id: item.id },
  56. });
  57. },
  58. });
  59. }
  60. // 修改
  61. handleEditOperation = () => {
  62. }
  63. // 查询
  64. handleFilterOperation = (params, states) => {
  65. this.props.dispatch({
  66. type: 'resource/fetchImageList',
  67. payload: params,
  68. });
  69. this.setState({
  70. UIParams: states,
  71. Queryers: params,
  72. });
  73. }
  74. // 批量
  75. handleBatchOperation = () => {
  76. Message.info('暂不支持批量操作!');
  77. }
  78. render() {
  79. const { resource, loading } = this.props;
  80. const { list, totalSize, pageSize, pageNo } = resource;
  81. const publicProps = {
  82. loading,
  83. pageNo,
  84. pageSize,
  85. totalSize,
  86. dataSource: list,
  87. onCreateClick: this.handleCreateOperation,
  88. onDeleteClick: this.handleDeleteOperation,
  89. onEditClick: this.handleEditOperation,
  90. onFilterClick: this.handleFilterOperation,
  91. onBatchClick: this.handleBatchOperation,
  92. };
  93. return (
  94. <Card bordered={false}>
  95. <Button.Group style={{marginBottom: 16}}>
  96. <Button
  97. style={{width: 50}}
  98. onClick={this.handleShowTypeChange}
  99. icon="appstore-o"
  100. type={this.state.isCard ? 'primary' : null}
  101. />
  102. <Button
  103. style={{width: 50}}
  104. onClick={this.handleShowTypeChange}
  105. icon="table"
  106. type={this.state.isCard ? null : 'primary'}
  107. />
  108. </Button.Group>
  109. {this.state.isCard ?
  110. <PictureCardList {...publicProps} /> :
  111. <PictureTableList {...publicProps} />
  112. }
  113. </Card>
  114. );
  115. }
  116. }