Deploy.jsx 6.4 KB

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