CaseShow.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import React, {Component} from 'react';
  2. import {Layout, Card, Button, Avatar, Spin, Icon, Row, Col, notification, Tag} 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 {Content} = Layout;
  14. const {Meta} = Card;
  15. class CaseShow extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. examplesIoobot: [],
  20. examplesOthers: [],
  21. showCustom: false,
  22. chosenSchemaID: ''
  23. }
  24. }
  25. componentWillMount() {
  26. this._isMounted = true;
  27. // 查询是否登录
  28. let userID = getCookie('user_id');
  29. if (userID !== undefined && userID !== '') {
  30. this.setState({
  31. userID
  32. });
  33. }
  34. request(graphqlUrl, SHOW_ALL_CASE, {}).then(data => {
  35. let cases = data.case_by_props;
  36. // console.log(cases);
  37. let examplesIoobot = cases.filter(case1 => case1.user_id.id === 'ioobot');
  38. let IooList = this.examplesFilter(examplesIoobot);
  39. let examplesOthers = cases.filter(case2 => case2.user_id.id !== 'ioobot');
  40. let UserList = this.examplesFilter(examplesOthers);
  41. if (this._isMounted) {
  42. this.setState({
  43. examplesIoobot: IooList,
  44. examplesOthers: UserList
  45. })
  46. }
  47. }
  48. )
  49. }
  50. examplesFilter(example) {
  51. // console.log('examples',example);
  52. let hash = {}, i = 0, list = [];
  53. example.forEach(function (item) {
  54. let {title} = item;
  55. hash[title] ? list[hash[title] - 1].content.push(item) : hash[title] = ++i && list.push({
  56. title,
  57. content: [item],
  58. });
  59. });
  60. // console.log('list',list);
  61. return list;
  62. }
  63. componentWillUnmount() {
  64. this._isMounted = false;
  65. }
  66. schemaIDChangeBucket = (schemaID) => {
  67. switch (schemaID) {
  68. case 'order_schemaID':
  69. return 'appointment';
  70. case 'ecommerce_schemaID':
  71. return 'e-commerce';
  72. case 'bills_schemaID':
  73. return 'bills';
  74. default:
  75. return 'nothing';
  76. }
  77. };
  78. backToMe = () => {
  79. this.setState({
  80. showCustom: false
  81. })
  82. };
  83. showCustom = (item) => {
  84. this.setState({
  85. showCustom: true,
  86. chosenSchemaID: item
  87. })
  88. };
  89. render() {
  90. let {userID, showCustom, chosenSchemaID} = this.state;
  91. return (
  92. <div id="example-show">
  93. <Layout style={{padding: '24px 48px', minHeight: '300px'}}>
  94. {
  95. !showCustom ?
  96. <div>
  97. <div className={'card card-head'}>
  98. <Card.Grid className={'card-head-item orange-change'}>
  99. <p>我们永久无年费 &nbsp;&nbsp;&nbsp;&nbsp; 告别高成本</p>
  100. <p>省钱、更省心</p>
  101. </Card.Grid>
  102. <Card.Grid className={'card-head-item pink-change'}>
  103. <p>数据完全私有 &nbsp;&nbsp;&nbsp;&nbsp; 安全更可靠</p>
  104. <p>数据分析图表为您提供更细致的服务</p>
  105. </Card.Grid>
  106. <Card.Grid className={'card-head-item blue-change'}>
  107. <p>模板不满意 &nbsp;&nbsp;&nbsp;&nbsp; 快来定制化吧!</p>
  108. <p>上手有困难,联系我们即可</p>
  109. <Button
  110. onClick={() => {
  111. this.props.history.push({
  112. pathname: `/common/communication`
  113. })
  114. }}>立即定制</Button>
  115. </Card.Grid>
  116. </div>
  117. <div className={'schema-name'}>
  118. <FormattedMessage id='ioobot case'/>
  119. </div>
  120. <div>
  121. {
  122. this.state.examplesIoobot.length === 0 ?
  123. <Spin/>
  124. :
  125. this.state.examplesIoobot.map((item, index) => {
  126. let exampleList = item.content;
  127. let gzh = exampleList.filter(case1 => case1.description === '微信公众号');
  128. let xcx = exampleList.filter(case1 => case1.description === '微信小程序');
  129. let value = exampleList[0];
  130. return (
  131. <Row key={index} className='card card-case' type="flex"
  132. justify="space-around" align="middle">
  133. <Col span={6} style={{padding: '20px'}}>
  134. <div className="wrap">
  135. <div className="case-name">{value.title}</div>
  136. <div className="wrapper">
  137. <div>
  138. <div>
  139. <div>模板简介:</div>
  140. <div>{value.detailDescription ? value.detailDescription : '暂无简介'}</div>
  141. </div>
  142. <br/>
  143. <div>
  144. {value.detailAttention ?
  145. <div>适用行业: &nbsp;&nbsp;
  146. <Tag
  147. color="blue">{value.detailAttention}</Tag>
  148. </div>
  149. :
  150. ''
  151. }
  152. </div>
  153. <br/>
  154. <div className="left-end">
  155. <div>
  156. <Icon type="mail"/>&nbsp;&nbsp;
  157. {
  158. value.user_id.email ? value.user_id.email : '该作者未留下联系方式'
  159. }
  160. </div>
  161. <div>
  162. <Icon type="github"/>&nbsp;&nbsp;
  163. {
  164. value.codeAddress ?
  165. <a href={value.codeAddress}>查看源码
  166. 可自行修改使用</a>
  167. :
  168. '该作者未留下代码仓库地址'
  169. }
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </Col>
  176. <Col span={9} style={{padding: '20px'}}>
  177. {gzh.length ?
  178. <CaseShowDetail caseContent={gzh}
  179. showCustom={this.showCustom}/>
  180. :
  181. <div>敬请期待</div>
  182. }
  183. </Col>
  184. <Col span={9} style={{padding: '20px'}}>
  185. {xcx.length ?
  186. <CaseShowDetail caseContent={xcx}
  187. showCustom={this.showCustom}/>
  188. :
  189. <div>敬请期待</div>
  190. }
  191. </Col>
  192. </Row>
  193. )
  194. })
  195. }
  196. </div>
  197. </div>
  198. :
  199. <UserCustom
  200. userID={userID}
  201. bucketName={this.schemaIDChangeBucket(chosenSchemaID)}
  202. history={this.props.history}
  203. backToMe={this.backToMe}
  204. />
  205. }
  206. </Layout>
  207. </div>
  208. )
  209. }
  210. }
  211. export default CaseShow;
  212. class CaseShowDetail extends Component {
  213. constructor(props) {
  214. super(props);
  215. this.state = {}
  216. }
  217. render() {
  218. let caseDetail = this.props.caseContent[0];
  219. // console.log('caseDetail',caseDetail);
  220. return (
  221. <div key={caseDetail.id}>
  222. <Query query={gql(SHOW_CASE)} variables={{id: caseDetail.id}}>
  223. {
  224. ({loading, error, data}) => {
  225. if (loading) {
  226. return <Spin/>
  227. }
  228. if (error) {
  229. return 'error!';
  230. }
  231. let thisCase = data.case_by_id;
  232. return (
  233. <div>
  234. <div className={'case-show-head'}>{caseDetail.description}</div>
  235. <div className={'wrapper'}>
  236. <div>
  237. <img
  238. key={thisCase.detailImages[0]}
  239. src={thisCase.detailImages[0]}
  240. alt=""
  241. height="500"
  242. />
  243. </div>
  244. <div className={'right'}>
  245. <div className="cl-center">
  246. <div className='cover-div'>
  247. <img
  248. className='cover-img'
  249. src={caseDetail.img}
  250. alt={caseDetail.title + '' + caseDetail.description}/>
  251. </div>
  252. </div>
  253. <div className="cl-center">
  254. 微信扫一扫立即体验
  255. </div>
  256. <div className="cl-center">
  257. <Button type="primary"
  258. style={{borderRadius: 30}}
  259. onClick={() => {
  260. this.props.showCustom(caseDetail.schema_id.id);
  261. }}><FormattedMessage id='Publish immediately'/></Button>
  262. </div>
  263. </div>
  264. </div>
  265. </div>
  266. )
  267. }
  268. }
  269. </Query>
  270. </div>
  271. )
  272. }
  273. }