Deploy.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import React, {Component} from 'react';
  2. import {Card, Input} from 'antd';
  3. import TencentConfig from './tencent/TencentConfig';
  4. import AliConfig from './ali/AliConfig';
  5. import AmazonConfig from './amazon/AmazonConfig';
  6. import './index.css';
  7. import {SHOW_FC, SEARCH_SCHEMA, SHOW_CLOUD} from "../../../gql";
  8. import {request} from 'graphql-request'
  9. const tabListNoTitle = [{
  10. key: 'tencent',
  11. tab: 'Tencent',
  12. }, {
  13. key: 'aliyun',
  14. tab: 'Aliyun',
  15. }, {
  16. key: 'amazon',
  17. tab: 'AWS',
  18. }];
  19. class Deploy extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. show: false,
  24. cloud: 'tencent',
  25. tencentCloudID: '',
  26. aliyunCloudID: '',
  27. amazonCloudID: '',
  28. schemaName: '',
  29. tencentFC: '',
  30. aliyunFC: '',
  31. amazonFC: '',
  32. schemaID: props.schemaID
  33. };
  34. this.fetch();
  35. }
  36. componentWillReceiveProps(next) {
  37. this.setState({
  38. schemaID: next.schemaID
  39. }, this.fetch)
  40. }
  41. fetch = () => {
  42. request('http://123.206.193.98:3000/graphql', SHOW_FC, {schema_id: this.state.schemaID}).then(
  43. // 根据 schemaID 查询 fc 是否成功
  44. data => {
  45. request('http://123.206.193.98:3000/graphql', SEARCH_SCHEMA, {id: this.state.schemaID}).then(
  46. // 根据 schemaID 查询 schemaName
  47. _data => {
  48. if (data.fc_by_props.length === 0) {
  49. // 如果没有 fc,根据 userID 查 cloudId
  50. request('http://123.206.193.98:3000/graphql', SHOW_CLOUD, {user_id: this.props.userID}).then(
  51. __data => {
  52. __data.cloud_by_props.forEach(cloud => {
  53. switch (cloud.cloudName) {
  54. case 'tencent':
  55. this.setState({
  56. tencentFC: false,
  57. tencentCloudID: cloud.id,
  58. schemaName: _data.schema_by_id.schemaName,
  59. show: true
  60. });
  61. break;
  62. case 'aliyun':
  63. this.setState({
  64. aliyunFC: false,
  65. aliyunCloudID: cloud.id,
  66. schemaName: _data.schema_by_id.schemaName,
  67. show: true
  68. });
  69. break;
  70. case 'amazon':
  71. this.setState({
  72. amazonFC: false,
  73. amazonCloudID: cloud.id,
  74. schemaName: _data.schema_by_id.schemaName,
  75. show: true
  76. });
  77. break;
  78. default:
  79. break;
  80. }
  81. })
  82. }
  83. );
  84. } else {
  85. // 如果有 fc, 则获取 cloudID
  86. data.fc_by_props.forEach(cloud => {
  87. switch (cloud.cloud_id.cloudName) {
  88. case 'tencent':
  89. this.setState({
  90. tencentFC: true,
  91. tencentCloudID: cloud.cloud_id.id,
  92. show: true
  93. });
  94. break;
  95. case 'aliyun':
  96. this.setState({
  97. aliyunFC: true,
  98. aliyunCloudID: cloud.cloud_id.id,
  99. show: true
  100. });
  101. break;
  102. case 'amazon':
  103. this.setState({
  104. amazonFC: true,
  105. amazonCloudID: cloud.cloud_id.id,
  106. show: true
  107. });
  108. break;
  109. default:
  110. break;
  111. }
  112. })
  113. }
  114. }
  115. );
  116. }
  117. );
  118. };
  119. render() {
  120. const contentListNoTitle = {
  121. tencent: <TencentConfig cloudID={this.state.tencentCloudID} fc={this.state.tencentFC} schemaName={this.state.schemaName} userID={this.props.userID}/>,
  122. aliyun: <AliConfig/>,
  123. amazon: <AmazonConfig/>,
  124. };
  125. return (
  126. <div>
  127. <div>
  128. <Card
  129. style={{width: '100%'}}
  130. tabList={tabListNoTitle}
  131. activeTabKey={this.state.cloud}
  132. onTabChange={(cloud) => {
  133. this.setState({
  134. cloud
  135. })
  136. }}
  137. >
  138. {
  139. this.state.show ?
  140. contentListNoTitle[this.state.cloud]
  141. :
  142. "waiting, if long, checkout your internet or did u forget cloud id and secret config when login"
  143. }
  144. </Card>
  145. </div>
  146. </div>
  147. )
  148. }
  149. }
  150. export default Deploy;