CaseShow.jsx 15 KB

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