mock平台

MockList.js 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Row, Input } from 'antd';
  4. import constants from '../../constants/variable.js';
  5. const wordList = constants.MOCK_SOURCE;
  6. const Search = Input.Search;
  7. class MockList extends Component {
  8. static propTypes = {
  9. click: PropTypes.func,
  10. clickValue: PropTypes.string
  11. };
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. filter: '',
  16. list: []
  17. };
  18. }
  19. componentDidMount() {
  20. this.setState({
  21. list: wordList
  22. });
  23. }
  24. onFilter = e => {
  25. const list = wordList.filter(item => {
  26. return item.mock.indexOf(e.target.value) !== -1;
  27. });
  28. this.setState({
  29. filter: e.target.value,
  30. list: list
  31. });
  32. };
  33. render() {
  34. const { list, filter } = this.state;
  35. const { click, clickValue } = this.props;
  36. return (
  37. <div className="modal-postman-form-mock">
  38. <Search
  39. onChange={this.onFilter}
  40. value={filter}
  41. placeholder="搜索mock数据"
  42. className="mock-search"
  43. />
  44. {list.map((item, index) => {
  45. return (
  46. <Row
  47. key={index}
  48. type="flex"
  49. align="middle"
  50. className={'row ' + (item.mock === clickValue ? 'checked' : '')}
  51. onClick={() => click(item.mock)}
  52. >
  53. <span>{item.mock}</span>
  54. </Row>
  55. );
  56. })}
  57. </div>
  58. );
  59. }
  60. }
  61. export default MockList;