Deploy.jsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import React, {Component} from 'react';
  2. import {Card, Spin} 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_SCHEMA, SHOW_FC_CONFIG, SEARCH_SCHEMA, SHOW_CLOUD, SHOW_WXCONTENT} from "../../../gql";
  8. import {request} from 'graphql-request'
  9. import {graphqlUrl} from "../../../config";
  10. const tabListNoTitle = [{
  11. key: 'tencent',
  12. tab: 'Tencent',
  13. }];
  14. // [{
  15. // key: 'tencent',
  16. // tab: 'Tencent',
  17. // }, {
  18. // key: 'aliyun',
  19. // tab: 'Aliyun',
  20. // }, {
  21. // key: 'amazon',
  22. // tab: 'AWS',
  23. // }];
  24. class Deploy extends Component {
  25. constructor(props) {
  26. super(props);
  27. this.state = {
  28. show: false,
  29. cloud: 'tencent',
  30. tencentCloudID: '',
  31. aliyunCloudID: '',
  32. amazonCloudID: '',
  33. defalutName: '',
  34. tencentFC: '',
  35. aliyunFC: '',
  36. amazonFC: '',
  37. schemaID: props.schemaID,
  38. configID: props.configID,
  39. kind: ''
  40. };
  41. this.fetch();
  42. }
  43. componentWillReceiveProps(next) {
  44. this.setState({
  45. schemaID: next.schemaID,
  46. configID: next.configID
  47. }, this.fetch)
  48. }
  49. fetch = () => {
  50. if (this.state.schemaID !== '' && this.state.schemaID !== undefined) {
  51. request(graphqlUrl, SHOW_FC_SCHEMA, {schema_id: this.state.schemaID}).then(
  52. // 根据 schemaID 查询 fc 是否成功
  53. data => {
  54. request(graphqlUrl, SEARCH_SCHEMA, {id: this.state.schemaID}).then(
  55. // 根据 schemaID 查询 schemaName
  56. _data => {
  57. if (data.fc_by_props.length === 0) {
  58. // 如果没有 fc,根据 userID 查 cloudId
  59. request(graphqlUrl, SHOW_CLOUD, {user_id: this.props.userID}).then(
  60. __data => {
  61. // 如果 user 未设置 cloudID
  62. if(__data.cloud_by_props.length === 0) {
  63. this.setState({
  64. tencentFC: false,
  65. aliyunFC: false,
  66. amazonFC: false,
  67. defalutName: _data.schema_by_id.schemaName,
  68. show: true,
  69. kind: 'graphql'
  70. });
  71. } else {
  72. __data.cloud_by_props.forEach(cloud => {
  73. switch (cloud.cloudName) {
  74. case 'tencent':
  75. this.setState({
  76. tencentFC: false,
  77. tencentCloudID: cloud.id,
  78. defalutName: _data.schema_by_id.schemaName,
  79. show: true,
  80. kind: 'graphql'
  81. });
  82. break;
  83. case 'aliyun':
  84. this.setState({
  85. aliyunFC: false,
  86. aliyunCloudID: cloud.id,
  87. defalutName: _data.schema_by_id.schemaName,
  88. show: true,
  89. kind: 'graphql'
  90. });
  91. break;
  92. case 'amazon':
  93. this.setState({
  94. amazonFC: false,
  95. amazonCloudID: cloud.id,
  96. defalutName: _data.schema_by_id.schemaName,
  97. show: true,
  98. kind: 'graphql'
  99. });
  100. break;
  101. default:
  102. break;
  103. }
  104. })
  105. }
  106. }
  107. );
  108. } else {
  109. // 如果有 fc, 则获取 cloudID
  110. data.fc_by_props.forEach(cloud => {
  111. switch (cloud.cloud_id.cloudName) {
  112. case 'tencent':
  113. this.setState({
  114. tencentFC: true,
  115. tencentCloudID: cloud.cloud_id.id,
  116. show: true,
  117. kind: 'graphql'
  118. });
  119. break;
  120. case 'aliyun':
  121. this.setState({
  122. aliyunFC: true,
  123. aliyunCloudID: cloud.cloud_id.id,
  124. show: true,
  125. kind: 'graphql'
  126. });
  127. break;
  128. case 'amazon':
  129. this.setState({
  130. amazonFC: true,
  131. amazonCloudID: cloud.cloud_id.id,
  132. show: true,
  133. kind: 'graphql'
  134. });
  135. break;
  136. default:
  137. break;
  138. }
  139. })
  140. }
  141. }
  142. );
  143. }
  144. );
  145. } else {
  146. request(graphqlUrl, SHOW_FC_CONFIG, {wxConfig_id: this.state.configID}).then(
  147. // 根据 configID 查询 fc 是否成功
  148. data => {
  149. request(graphqlUrl, SHOW_WXCONTENT, {id: this.state.configID}).then(
  150. // 根据 configID 查询 appName
  151. _data => {
  152. if (data.fc_by_props.length === 0) {
  153. // 如果没有 fc,根据 userID 查 cloudId
  154. request(graphqlUrl, SHOW_CLOUD, {user_id: this.props.userID}).then(
  155. __data => {
  156. // 如果 user 未设置 cloudID
  157. if(__data.cloud_by_props.length === 0) {
  158. this.setState({
  159. tencentFC: false,
  160. aliyunFC: false,
  161. amazonFC: false,
  162. defalutName: _data.wxConfig_by_id.appName,
  163. show: true,
  164. kind: 'wx'
  165. });
  166. } else {
  167. __data.cloud_by_props.forEach(cloud => {
  168. switch (cloud.cloudName) {
  169. case 'tencent':
  170. this.setState({
  171. tencentFC: false,
  172. tencentCloudID: cloud.id,
  173. defalutName: _data.wxConfig_by_id.appName,
  174. show: true,
  175. kind: 'wx'
  176. });
  177. break;
  178. case 'aliyun':
  179. this.setState({
  180. aliyunFC: false,
  181. aliyunCloudID: cloud.id,
  182. defalutName: _data.wxConfig_by_id.appName,
  183. show: true,
  184. kind: 'wx'
  185. });
  186. break;
  187. case 'amazon':
  188. this.setState({
  189. amazonFC: false,
  190. amazonCloudID: cloud.id,
  191. defalutName: _data.wxConfig_by_id.appName,
  192. show: true,
  193. kind: 'wx'
  194. });
  195. break;
  196. default:
  197. break;
  198. }
  199. })
  200. }
  201. }
  202. );
  203. } else {
  204. // 如果有 fc, 则获取 cloudID
  205. data.fc_by_props.forEach(cloud => {
  206. switch (cloud.cloud_id.cloudName) {
  207. case 'tencent':
  208. this.setState({
  209. tencentFC: true,
  210. tencentCloudID: cloud.cloud_id.id,
  211. show: true,
  212. kind: 'wx'
  213. });
  214. break;
  215. case 'aliyun':
  216. this.setState({
  217. aliyunFC: true,
  218. aliyunCloudID: cloud.cloud_id.id,
  219. show: true,
  220. kind: 'wx'
  221. });
  222. break;
  223. case 'amazon':
  224. this.setState({
  225. amazonFC: true,
  226. amazonCloudID: cloud.cloud_id.id,
  227. show: true,
  228. kind: 'wx'
  229. });
  230. break;
  231. default:
  232. break;
  233. }
  234. })
  235. }
  236. }
  237. );
  238. }
  239. );
  240. }
  241. };
  242. render() {
  243. const contentListNoTitle = {
  244. tencent: <TencentConfig cloudID={this.state.tencentCloudID} fc={this.state.tencentFC} defalutName={this.state.defalutName} userID={this.props.userID} kind={this.state.kind} trialcase={this.props.trialcase}/>,
  245. aliyun: <AliConfig/>,
  246. amazon: <AmazonConfig/>,
  247. };
  248. return (
  249. <div>
  250. <div>
  251. <Card
  252. style={{width: '100%'}}
  253. tabList={tabListNoTitle}
  254. activeTabKey={this.state.cloud}
  255. onTabChange={(cloud) => {
  256. this.setState({
  257. cloud
  258. })
  259. }}
  260. >
  261. {
  262. this.state.show ?
  263. contentListNoTitle[this.state.cloud]
  264. :
  265. <Spin/>
  266. }
  267. </Card>
  268. </div>
  269. </div>
  270. )
  271. }
  272. }
  273. export default Deploy;