CaseShow.jsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import React, {Component} from 'react';
  2. import {Layout, Card, Button, Avatar, Spin, Icon, Row, Col, notification, Tabs, Select} from 'antd';
  3. import lo from '../../../images/lo.png'
  4. import './index.css'
  5. import {graphqlUrl} from "../../../config";
  6. import {SHOW_ALL_CASE, SHOW_CASE} from "../../../gql";
  7. import {FormattedMessage} from 'react-intl';
  8. import {request} from 'graphql-request'
  9. import UserCustom from "./UserCustom";
  10. import {Query} from "react-apollo";
  11. import gql from "graphql-tag";
  12. import {getCookie} from "../../../cookie";
  13. const TabPane = Tabs.TabPane;
  14. const {Content} = Layout;
  15. const {Meta} = Card;
  16. class CaseShow extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. examplesMP: [],
  21. examplesPublic: [],
  22. examplesH5: [],
  23. showCustom: false,
  24. chosenSchemaID: '',
  25. activeKey: '1',
  26. showCaseID: 'order-react-CaseID'
  27. }
  28. }
  29. componentWillMount() {
  30. this._isMounted = true;
  31. // 查询是否登录
  32. let userID = getCookie('user_id');
  33. if (userID !== undefined && userID !== '') {
  34. this.setState({
  35. userID
  36. });
  37. }
  38. request(graphqlUrl, SHOW_ALL_CASE, {}).then(data => {
  39. let cases = data.case_by_props;
  40. let examplesMP = cases.filter(case1 => case1.description === '小程序');
  41. let examplesPublic = cases.filter(case2 => case2.description === '公众号');
  42. let examplesH5 = cases.filter(case2 => case2.description === 'H5');
  43. if (this._isMounted) {
  44. this.setState({
  45. examplesMP,
  46. examplesPublic,
  47. examplesH5
  48. })
  49. }
  50. }
  51. )
  52. }
  53. componentWillUnmount() {
  54. this._isMounted = false;
  55. }
  56. schemaIDChangeBucket = (schemaID) => {
  57. if (this.props.location && this.props.location.state) {
  58. switch (schemaID) {
  59. case 'order_schemaID':
  60. return 'appointment';
  61. case 'ecommerce_schemaID':
  62. return 'e-commerce';
  63. case 'bills_schemaID':
  64. return 'bills';
  65. default:
  66. break;
  67. }
  68. }
  69. };
  70. backToMe = () => {
  71. this.setState({
  72. showCustom: false
  73. })
  74. };
  75. render() {
  76. let {userID, showCustom, chosenSchemaID, activeKey, showCaseID} = this.state;
  77. const tabStyle = {
  78. paddingTop: '50px',
  79. paddingBottom: '50px',
  80. height: '550px',
  81. display: 'inline-block',
  82. };
  83. return (
  84. <div id="example-show">
  85. <Layout style={{padding: '24px', minHeight: '300px'}}>
  86. <Content className="content">
  87. {
  88. !showCustom ?
  89. <div>
  90. <div className={'schema-name'} style={{fontSize: 25}}><FormattedMessage
  91. id='scan and use'/></div>
  92. <div>
  93. <Tabs tabPosition='left' size='large' tabBarStyle={tabStyle} tabBarGutter={100}>
  94. <TabPane tab="公众号" key="1">
  95. <div>
  96. <Row>
  97. <Col span={12}>
  98. <Row>
  99. <Query query={gql(SHOW_CASE)} variables={{id: showCaseID}}>
  100. {
  101. ({loading, error, data}) => {
  102. if (loading) {
  103. return <Spin/>
  104. }
  105. if (error) {
  106. return 'error!';
  107. }
  108. let thisCase = data.case_by_id;
  109. return (
  110. <div>
  111. <div>{thisCase.title}</div>
  112. <div className={'case-detail-description'}>{thisCase.detailDescription ? thisCase.detailDescription : '暂无简介'}</div>
  113. </div>
  114. )
  115. }
  116. }
  117. </Query>
  118. </Row>
  119. <Row>
  120. {
  121. this.state.examplesMP.map((item, index) => (
  122. <div
  123. className='cover-div'
  124. onMouseEnter={() => {
  125. this.setState({
  126. showCaseID: item.id
  127. })
  128. }}
  129. >
  130. <img
  131. className='cover-img'
  132. src={item.img}
  133. alt={item.title + '' + item.description}
  134. />
  135. <div>{item.title}</div>
  136. </div>
  137. ))
  138. }
  139. </Row>
  140. </Col>
  141. <Col span={6}>
  142. 这个地方是截图,可以放在 detailImage 里面
  143. </Col>
  144. </Row>
  145. {/*下面这串代码仅供参考,可以整体删除*/}
  146. {
  147. this.state.examplesMP.map((item, index) => (
  148. <Row key={index} className='case-item'>
  149. <Col span={12} style={{padding: '20px'}}>
  150. <Query query={gql(SHOW_CASE)}
  151. variables={{id: item.id}}>
  152. {
  153. ({loading, error, data}) => {
  154. if (loading) {
  155. return <Spin/>
  156. }
  157. if (error) {
  158. return 'error!';
  159. }
  160. let thisCase = data.case_by_id;
  161. return (
  162. <div>
  163. <div
  164. className={'case-detail-attention'}> {thisCase.detailAttention ?
  165. <div>
  166. <Icon
  167. type="alert"/>{thisCase.detailAttention}
  168. </div>
  169. :
  170. ''
  171. }
  172. </div>
  173. <div
  174. className={'case-detail-description'}>{thisCase.detailDescription ? thisCase.detailDescription : '暂无简介'}</div>
  175. <div
  176. className={'detail-images'}>
  177. <img
  178. key={thisCase.detailImages[0]}
  179. src={thisCase.detailImages[0]}
  180. alt=""
  181. height="500"/>
  182. </div>
  183. </div>
  184. )
  185. }
  186. }
  187. </Query>
  188. </Col>
  189. <Col span={4}>
  190. <div>
  191. <div
  192. className={'schema-name'}>想要定制化该案例
  193. </div>
  194. <div>
  195. <div>联系作者</div>
  196. <div>
  197. <Icon type="mail"/>
  198. {
  199. item.user_id.email ? item.user_id.email : '该作者未留下联系方式'
  200. }
  201. </div>
  202. </div>
  203. <div>
  204. <div>自行修改代码</div>
  205. <div>
  206. <Icon type="github"/>
  207. {
  208. item.codeAddress ? item.codeAddress : '该作者未留下代码仓库地址'
  209. }
  210. </div>
  211. </div>
  212. </div>
  213. </Col>
  214. <Col span={8}>
  215. <div style={{padding: '10px 0'}}>
  216. <Card
  217. key={index}
  218. style={{width: 300}}
  219. cover={<div className='cover-div'><img
  220. className='cover-img'
  221. src={item.img}
  222. alt={item.title + '' + item.description}/>
  223. </div>}
  224. actions={[
  225. <span>已部署: {item.deployedNum}</span>,
  226. <span><Icon
  227. type="like"/>: {item.like}</span>,
  228. <Button type="primary" onClick={() => {
  229. this.setState({
  230. showCustom: true,
  231. chosenSchemaID: item.schema_id.id
  232. })
  233. }}><FormattedMessage
  234. id='one more step'/></Button>
  235. ]}
  236. >
  237. <Meta
  238. avatar={<Avatar src={lo}/>}
  239. title={item.title}
  240. description={item.description}
  241. />
  242. </Card>
  243. </div>
  244. </Col>
  245. </Row>
  246. ))
  247. }
  248. </div>
  249. </TabPane>
  250. <TabPane onMouseEnter={() => {
  251. this.setState({activeKey: '2'})
  252. }} tab="小程序" key="2">Content of Tab 2</TabPane>
  253. <TabPane onMouseEnter={() => {
  254. this.setState({activeKey: '3'})
  255. }} tab="H5 网页" key="3">Content of Tab 3</TabPane>
  256. </Tabs>
  257. </div>
  258. </div>
  259. :
  260. <UserCustom
  261. userID={userID}
  262. bucketName={this.schemaIDChangeBucket(chosenSchemaID)}
  263. history={this.props.history}
  264. backToMe={this.backToMe}
  265. />
  266. }
  267. </Content>
  268. </Layout>
  269. </div>
  270. )
  271. }
  272. }
  273. export default CaseShow;