index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import queryString from 'query-string';
  4. import { connect } from 'dva';
  5. import { routerRedux } from 'dva/router';
  6. import { Card } from 'antd';
  7. import TableList from './table';
  8. import ModalForm from './modal';
  9. import Search from './search';
  10. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  11. function Terminal({ location, dispatch, terminal }) {
  12. location.query = queryString.parse(location.search);
  13. const { query, pathname } = location;
  14. const { field, keyword } = query;
  15. const { list, listLoading, pagination, currentItem, itemLoading, modalVisible, modalType } = terminal;
  16. const modalProps = {
  17. item: modalType === 'create' ? {} : currentItem,
  18. visible: modalVisible,
  19. maskClosable: false,
  20. title: `${modalType === 'create' ? '添加终端' : '编辑终端'}`,
  21. wrapClassName: 'vertical-center-modal',
  22. onOk (data) {
  23. dispatch({
  24. type: `terminal/${modalType}`,
  25. payload: data,
  26. });
  27. },
  28. onCancel () {
  29. dispatch({
  30. type: 'terminal/hideModal',
  31. });
  32. },
  33. };
  34. const searchProps = {
  35. field,
  36. keyword,
  37. onSearch: (payload) => {
  38. if (!payload.keyword.length) {
  39. delete payload.field;
  40. delete payload.keyword;
  41. }
  42. dispatch(routerRedux.push({
  43. pathname,
  44. search: queryString.stringify({
  45. ...payload
  46. })
  47. }));
  48. },
  49. onAdd: () => {
  50. dispatch({
  51. type: 'terminal/showModal',
  52. payload: {
  53. modalType: 'create',
  54. },
  55. });
  56. }
  57. };
  58. const listProps = {
  59. dataSource: list,
  60. loading: listLoading,
  61. pagination,
  62. location,
  63. onChange: (page) => {
  64. dispatch(routerRedux.push({
  65. pathname,
  66. search: queryString.stringify({
  67. ...query,
  68. pageNo: page.current,
  69. pageSize: page.pageSize,
  70. }),
  71. }));
  72. },
  73. onEditItem: (item) => {
  74. dispatch({
  75. type: 'terminal/showModal',
  76. payload: {
  77. modalType: 'update',
  78. currentItem: item,
  79. },
  80. })
  81. },
  82. onDeleteItem: (id) => {
  83. dispatch({
  84. type: 'terminal/delete',
  85. payload: id,
  86. });
  87. }
  88. };
  89. return (
  90. <PageHeaderLayout>
  91. <Card>
  92. <Search { ...searchProps } />
  93. <TableList { ...listProps } />
  94. {modalVisible && <ModalForm { ...modalProps } />}
  95. </Card>
  96. </PageHeaderLayout>
  97. );
  98. }
  99. Terminal.propTypes = {
  100. Terminal: PropTypes.object,
  101. location: PropTypes.object,
  102. dispatch: PropTypes.func,
  103. }
  104. export default connect(({ terminal }) => ({ terminal }))(Terminal);