import React, {Component} from 'react'; import {FormattedMessage} from 'react-intl'; import {Button, Input, Spin, Icon, Row, Col} from 'antd'; import {SHOW_CLOUD, ADD_CLOUD, UPDATE_CLOUD} from "../gql"; import {request} from 'graphql-request' import {getCookie} from '../cookie'; import {idGen} from "../func"; import {graphqlUrl, storeFile} from "../config"; import axios from 'axios'; class CloudConfig extends Component { constructor(props) { super(props); this.state = { show: false, showOK: '', showNotOK: '', tencentCLoudID: '', tenAppID: '', tenID: '', tenKey: '', aliyunCLoudID: '', aliAppID: '', aliID: '', aliKey: '', awsCLoudID: '', awsAppID: '', awsID: '', awsKey: '', userID: getCookie('user_id'), }; request(graphqlUrl, SHOW_CLOUD, {user_id: this.state.userID}).then( data => { let tencent = data.cloud_by_props.find(cloud => cloud.cloudName === 'tencent'); let aliyun = data.cloud_by_props.find(cloud => cloud.cloudName === 'aliyun'); let amazon = data.cloud_by_props.find(cloud => cloud.cloudName === 'amazon'); this.setState({ show: true, tencentCLoudID: tencent ? tencent.id : '', tenAppID: tencent ? tencent.appId : '', tenID: tencent ? tencent.secretId : '', tenKey: tencent ? tencent.secretKey : '', aliyunCLoudID: aliyun ? aliyun.id : '', aliAppID: aliyun ? aliyun.appId : '', aliID: aliyun ? aliyun.secretId : '', aliKey: aliyun ? aliyun.secretKey : '', awsCLoudID: amazon ? amazon.id : '', awsAppID: amazon ? amazon.appId : '', awsID: amazon ? amazon.secretId : '', awsKey: amazon ? amazon.secretKey : '' }); } ); } inputChange = (kind) => { return (e) => { this.setState({ [kind]: e.target.value }) } }; submit = (id, cloudName, secretId, secretKey, appId) => { return () => { if (id === '') { let varObj = { id: idGen('cloud'), user_id: this.state.userID, appId, cloudName, secretId, secretKey, createdAt: new Date().getTime(), updatedAt: '' }; // store data to database request(graphqlUrl, ADD_CLOUD, varObj).then( data => { if (data.create_cloud.length !== null) { this.setState({ showOK: cloudName }); setTimeout(() => { this.setState({ showOK: '' }); this.props.history.push({ pathname: '/' }) }, 1500) } else { this.setState({ showNotOK: cloudName }); setTimeout(() => { this.setState({ showNotOK: '' }); }, 1500) } } ); } else { let varObj = { id, secretId, secretKey, appId, updatedAt: new Date().getTime() }; request(graphqlUrl, UPDATE_CLOUD, varObj).then( data => { if (data.update_cloud !== null) { this.setState({ showOK: cloudName }); setTimeout(() => { this.setState({ showOK: '' }); }, 1500) } else { this.setState({ showNotOK: cloudName }); setTimeout(() => { this.setState({ showNotOK: '' }); }, 1500) } } ); } } }; render() { return ( this.state.userID !== '' ? this.state.show ?
{ this.props.history.push({ pathname: '/login', }) }}>
:
APPID:
SecretId:
SecretKey:
{ this.state.showOK === 'tencent' ? : this.state.showNotOK === 'tencent' ? not ok : "" }
{/*
*/} {/*: */} {/*
*/} {/*
*/} {/*
*/} {/*ID:*/} {/**/} {/*
*/} {/*
*/} {/*Key:*/} {/**/} {/*
*/} {/*{*/} {/*this.state.showOK === 'aliyun' ?*/} {/**/} {/*:*/} {/*this.state.showNotOK === 'aliyun' ?*/} {/*not ok*/} {/*:*/} {/*""*/} {/*}*/} {/*
*/} {/**/} {/*
*/} {/*
*/} {/*
*/} {/*: */} {/*
*/} {/*
*/} {/*
*/} {/*ID:*/} {/**/} {/*
*/} {/*
*/} {/*Key:*/} {/**/} {/*
*/} {/*{*/} {/*this.state.showOK === 'amazon' ?*/} {/**/} {/*:*/} {/*this.state.showNotOK === 'amazon' ?*/} {/*not ok*/} {/*:*/} {/*""*/} {/*}*/} {/*
*/} {/**/} {/*
*/} {/*
*/}
: :
{ this.props.history.push({ pathname: '/login', }) }}>
你还没有登录
) } } export default CloudConfig;