CaseShow.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import React, {Component} from 'react';
  2. import {Layout, Card, Button, Avatar, Spin, Icon} from 'antd';
  3. import lo from '../../../images/lo.png'
  4. import './index.css'
  5. import {graphqlUrl} from "../../../config";
  6. import {SHOW_ALL_CASE} from "../../../gql";
  7. import {FormattedMessage} from 'react-intl';
  8. import {request} from 'graphql-request'
  9. const {Content} = Layout;
  10. const {Meta} = Card;
  11. class CaseShow extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. examplesIoobot: [],
  16. examplesOthers: []
  17. }
  18. }
  19. componentWillMount() {
  20. this._isMounted = true;
  21. request(graphqlUrl, SHOW_ALL_CASE, {}).then(data => {
  22. let cases = data.case_by_props;
  23. console.log(cases);
  24. let examplesIoobot = cases.filter(case1 => case1.user_id.id === 'ioobot');
  25. let examplesOthers = cases.filter(case2 => case2.user_id.id !== 'ioobot');
  26. if (this._isMounted) {
  27. this.setState({
  28. examplesIoobot,
  29. examplesOthers
  30. })
  31. }
  32. }
  33. )
  34. }
  35. componentWillUnmount() {
  36. this._isMounted = false;
  37. }
  38. render() {
  39. return (
  40. <div id="example-show">
  41. <Layout style={{padding: '24px', minHeight: '300px'}}>
  42. <Content className="content">
  43. <div className={'schema-name'} style={{fontSize: 25}}><FormattedMessage id='scan and use'/>
  44. </div>
  45. <div>
  46. <div className={'schema-name'}><FormattedMessage id='ioobot case'/></div>
  47. <div className="caseAllShow">
  48. {
  49. this.state.examplesIoobot.length === 0 ?
  50. <Spin/>
  51. :
  52. this.state.examplesIoobot.map((item, index) => (
  53. <span key={index} style={{padding: '10px 0'}}>
  54. <Card
  55. key={index}
  56. style={{width: 300}}
  57. cover={<div className='cover-div'><img className='cover-img' src={item.img}
  58. alt={item.title + '' + item.description}/>
  59. </div>}
  60. actions={[
  61. <span>已部署: {item.deployedNum}</span>,
  62. <span><Icon type="like" />: {item.like}</span>,
  63. <Button type="primary" onClick={() => {
  64. this.props.history.push({
  65. pathname: `/common/deploy-cloud-choose`,
  66. state: {caseID: item.id,}
  67. });
  68. }}><FormattedMessage id='step more'/></Button>
  69. ]}
  70. >
  71. <Meta
  72. avatar={<Avatar src={lo}/>}
  73. title={item.title}
  74. description={item.description}
  75. />
  76. </Card>
  77. </span>
  78. ))
  79. }
  80. </div>
  81. </div>
  82. <div>
  83. <div className={'schema-name'}><FormattedMessage id='other developer case'/></div>
  84. <div className="caseAllShow">
  85. {
  86. this.state.examplesOthers.length === 0 ?
  87. <Spin/>
  88. :
  89. this.state.examplesOthers.map((item, index) => (
  90. <span key={index} style={{padding: '10px 0'}}>
  91. <Card
  92. key={index}
  93. style={{width: 300}}
  94. cover={<div className='cover-div'><img className='cover-img' src={item.img} alt={item.title + '' + item.description}/></div>}
  95. actions={[
  96. <span>已部署: {item.deployedNum}</span>,
  97. <span><Icon type="like" />: {item.like}</span>,
  98. <Button type="primary" onClick={() => {
  99. this.props.history.push({
  100. pathname: `/common/deploy-cloud-choose`,
  101. state: {caseID: item.id,}
  102. });
  103. }}><FormattedMessage id='step more'/></Button>
  104. ]}
  105. >
  106. <Meta
  107. avatar={<Avatar src={item.user_id.avatar}/>}
  108. title={item.title}
  109. description={item.description}
  110. />
  111. </Card>
  112. </span>
  113. ))
  114. }
  115. </div>
  116. </div>
  117. </Content>
  118. </Layout>
  119. </div>
  120. )
  121. }
  122. }
  123. export default CaseShow;