ExampleDetail.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import React, {Component} from 'react';
  2. import {Layout, Button, notification, Row, Col, Icon, message, Radio} from 'antd';
  3. import {getCookie} from "../../../cookie";
  4. import {graphqlUrl} from "../../../config";
  5. import {SEARCH_APIGROUP} from "../../../gql";
  6. import {request} from 'graphql-request'
  7. import {FormattedMessage} from 'react-intl';
  8. import copy from 'copy-to-clipboard';
  9. import UserCustom from './UserCustom';
  10. const {Content} = Layout;
  11. class ExampleDetail extends Component {
  12. constructor() {
  13. super();
  14. this.state = {
  15. userID: '',
  16. bucketName: '',
  17. domain: '',
  18. showCustom: false
  19. };
  20. }
  21. componentWillMount() {
  22. this._isMounted = true;
  23. // 查询是否登录
  24. let userID = getCookie('user_id');
  25. if (userID !== undefined && userID !== '') {
  26. this.setState({
  27. userID
  28. });
  29. }
  30. // 查询跳转来的案例,转成 apigroup id
  31. let groupID = '';
  32. if (this.props.location && this.props.location.state) {
  33. switch (this.props.location.state.schemaID) {
  34. case 'order_schemaID':
  35. this.setState({
  36. bucketName: 'appointment'
  37. });
  38. groupID = 'order';
  39. break;
  40. case 'ecommerce_schemaID':
  41. this.setState({
  42. bucketName: 'e-commerce'
  43. });
  44. groupID = 'ecommerce';
  45. break;
  46. case 'bills_schemaID':
  47. this.setState({
  48. bucketName: 'bills'
  49. });
  50. groupID = 'bills';
  51. break;
  52. default:
  53. break;
  54. }
  55. }
  56. // 查询该案例的 domain
  57. request(graphqlUrl, SEARCH_APIGROUP, {id: groupID}).then(res => {
  58. let caseDeploy = res.apiGWGroupbyid;
  59. let domain = caseDeploy.defaultDomain;
  60. if (this._isMounted) {
  61. this.setState({
  62. domain
  63. })
  64. }
  65. })
  66. }
  67. componentWillUnmount() {
  68. this._isMounted = false;
  69. }
  70. backToMe = () => {
  71. this.setState({
  72. showCustom: false
  73. })
  74. };
  75. render() {
  76. let {userID, bucketName, domain, showCustom} = this.state;
  77. return (
  78. <div className={'deploy-choose-cloud'}>
  79. <Layout style={{padding: '24px', minHeight: '300px'}}>
  80. <Content style={{padding: '20px 50px', background: '#fff'}}>
  81. {
  82. !showCustom ?
  83. <div>
  84. <div>
  85. <div className={'schema-name'}><FormattedMessage id='case graphql domain'/>
  86. </div>
  87. <div className={'schema-table-list-title'}>
  88. <Row>
  89. <Col span={15}><span className={'schema-table-title'}><FormattedMessage
  90. id='defaultDomain'/></span></Col>
  91. </Row>
  92. </div>
  93. <div className={'schema-table-list-content'}>
  94. <Row>
  95. <Col span={15}>
  96. <span className={'schema-table-content'}>{domain} </span>
  97. <Icon type="copy" theme="twoTone" onClick={() => {
  98. copy(domain);
  99. message.success('复制成功.');
  100. }}/>
  101. </Col>
  102. </Row>
  103. </div>
  104. </div>
  105. <div style={{marginTop: 20, fontSize: 20}}>
  106. <div className={'schema-name'}><FormattedMessage id='detail'/></div>
  107. 这里巴拉巴拉
  108. </div>
  109. <div style={{marginTop: 20}}>
  110. <div className={'choose-cloud-button-group'}>
  111. <Button className={'choose-cloud-button'} type='primary' onClick={() => {
  112. if (userID === '') {
  113. notification['warning']({
  114. message: '需要登录',
  115. description: '后续使用,需要先登录',
  116. });
  117. this.props.history.push({
  118. pathname: `/login`
  119. })
  120. } else {
  121. this.setState({
  122. showCustom: true
  123. })
  124. }
  125. }}>自定义参数设置</Button>
  126. </div>
  127. </div>
  128. </div>
  129. :
  130. <UserCustom
  131. userID={userID}
  132. bucketName={bucketName}
  133. history={this.props.history}
  134. backToMe={this.backToMe}
  135. />
  136. }
  137. </Content>
  138. </Layout>
  139. </div>
  140. )
  141. }
  142. }
  143. export default ExampleDetail