TencentDeploy.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import React, {Component} from 'react';
  2. import {FormattedMessage} from 'react-intl';
  3. import {Alert, Icon, Spin, Row, Col, message, Button} from 'antd';
  4. import {
  5. SHOW_APIGROUP, UPDATE_APIGROUP
  6. } from "../../../gql";
  7. import copy from 'copy-to-clipboard';
  8. import axios from 'axios';
  9. import QRCode from 'qrcode.react';
  10. import {Query, Mutation} from "react-apollo";
  11. import gql from "graphql-tag";
  12. axios.defaults.withCredentials = true;
  13. class TencentDeploy extends Component {
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. userID: props.userID,
  18. url: props.url
  19. }
  20. }
  21. render() {
  22. let {userID, url} = this.state;
  23. return (
  24. <Query query={gql(SHOW_APIGROUP)} variables={{user_id: userID, status: ''}}>
  25. {
  26. ({loading, error, data}) => {
  27. if (loading) {
  28. return <Spin className='login-nickname'/>
  29. }
  30. if (error) {
  31. return 'error!';
  32. }
  33. let allDeployed = data.apiGWGroupbyprops;
  34. let deployed = allDeployed.filter(deployed =>
  35. deployed.cloud_id.cloudName === 'tencent'
  36. );
  37. return (
  38. <TencentDeployRender
  39. deployed={deployed}
  40. url={url}
  41. userID={userID}
  42. />
  43. )
  44. }
  45. }
  46. </Query>
  47. )
  48. }
  49. }
  50. class TencentDeployRender extends Component {
  51. constructor(props) {
  52. super(props);
  53. this.state = {
  54. userID: props.userID,
  55. url: props.url
  56. }
  57. }
  58. render() {
  59. let {userID, url} = this.state;
  60. let {deployed} = this.props;
  61. let regexp = new RegExp(userID + '_');
  62. return (
  63. <div>
  64. {
  65. userID === '' && !!url ?
  66. <Alert
  67. message="WARNING"
  68. description="it will be deleted soon, please login to deploy in your owm account"
  69. type="warning"
  70. />
  71. : ''
  72. }
  73. {
  74. !!url ?
  75. <div>
  76. <div className={'schema-name'}><FormattedMessage id='new'/></div>
  77. <div className={'schema-table-list-title'}>
  78. <Row>
  79. <Col span={15}><span className={'schema-table-title'}><FormattedMessage
  80. id='defaultDomain'/></span></Col>
  81. </Row>
  82. </div>
  83. <div className={'schema-table-list-content'}>
  84. <Row>
  85. <Col span={15}>
  86. <span className={'schema-table-content'}>{url} </span>
  87. <Icon type="copy" theme="twoTone" onClick={() => {
  88. copy(url);
  89. message.success('复制成功.');
  90. }}/>
  91. </Col>
  92. </Row>
  93. </div>
  94. </div>
  95. :
  96. ''
  97. }
  98. {
  99. userID === '' ?
  100. <div style={{marginTop: 50}}>
  101. <FormattedMessage id='go to deploy,then see more'/>
  102. </div>
  103. :
  104. <div>
  105. <div className={'schema-name'}><FormattedMessage id='service manage'/></div>
  106. <div className={'schema-table-list-title'}>
  107. <Row>
  108. <Col span={4}><span className={'schema-table-title'}><FormattedMessage
  109. id='groupName'/></span></Col>
  110. <Col span={10}><span className={'schema-table-title'}><FormattedMessage
  111. id='defaultDomain'/></span></Col>
  112. <Col span={6}><span className={'schema-table-title'}><FormattedMessage
  113. id='qrcode'/></span></Col>
  114. <Col span={4}><span className={'schema-table-title'}><FormattedMessage
  115. id='operation'/></span></Col>
  116. </Row>
  117. </div>
  118. <div className={'schema-table-list-content'}>
  119. {
  120. deployed.map(deploy => (
  121. <Row key={deploy.id}>
  122. <Col span={4}>
  123. <span
  124. className={'schema-table-content'}>{deploy.groupName.replace(regexp, '')}</span>
  125. </Col>
  126. <Col span={10}>
  127. <span
  128. className={'schema-table-content'}>{`http://${deploy.defaultDomain}/test/`} </span>
  129. <Icon type="copy" theme="twoTone" onClick={() => {
  130. copy(`http://${deploy.defaultDomain}/test/`);
  131. message.success('复制成功.');
  132. }}/>
  133. </Col>
  134. <Col span={6}>
  135. <QRCode
  136. value={deploy.userDomain ? `http://${deploy.userDomain}` : `http://${deploy.defaultDomain}/test/`}
  137. size={128}
  138. includeMargin={true}
  139. />
  140. </Col>
  141. <Col span={4}>
  142. <DeleteButton
  143. groupID={deploy.id}
  144. userID={userID}
  145. />
  146. </Col>
  147. </Row>
  148. ))
  149. }
  150. {
  151. deployed.length === 0 ?
  152. <Row>
  153. <Col span={15} offset={5}>
  154. <span className={'schema-table-content'}><FormattedMessage
  155. id='nothing'/> </span>
  156. </Col>
  157. </Row> :
  158. ''
  159. }
  160. </div>
  161. </div>
  162. }
  163. </div>
  164. )
  165. }
  166. }
  167. export default TencentDeploy;
  168. class DeleteButton extends Component {
  169. constructor(props) {
  170. super(props);
  171. this.state = {}
  172. }
  173. render() {
  174. let {groupID, userID} = this.props;
  175. return (
  176. <Mutation
  177. mutation={gql(UPDATE_APIGROUP)}
  178. refetchQueries={[{query: gql(SHOW_APIGROUP), variables: {user_id: userID, status: ''}}]}
  179. >
  180. {(update_apiGWGroup, {loading, error}) => {
  181. if (loading)
  182. return <Spin style={{marginLeft: 30, marginTop: 10}}/>;
  183. if (error)
  184. return 'error';
  185. let varObj = {
  186. id: groupID,
  187. status: 'deleted',
  188. updatedAt: new Date().getTime()
  189. };
  190. console.log(varObj);
  191. return (
  192. <Button type={'danger'} size={'small'} style={{marginTop: 10}} onClick={() => {
  193. update_apiGWGroup({variables: varObj})
  194. }}><FormattedMessage id='delete'/></Button>
  195. )
  196. }}
  197. </Mutation>
  198. )
  199. }
  200. }