import React, {Component} from 'react'; import {Row, Col, Card, Button, Spin, Alert, Steps} from 'antd'; import axios from 'axios'; import APIGroupCard from './APIGroupCard'; import APIPathCard from './APIPathCard'; import DeployCard from './DeployCard'; import NotificationCard from './NotificationCard'; import {SHOW_APIGWPATH, GET_PROJECT} from "../../../../gql"; import {deployUrl} from "../../../../config"; import {FormattedMessage} from 'react-intl'; import gql from "graphql-tag"; import {Query} from "react-apollo"; const Step = Steps.Step; class TencentConfig extends Component { constructor(props) { super(props); this.state = { region: '', couldDeploy: false, deployIdPassToPath: '', groupIdPassToPath: '', pathIdPassToConfig: '', currentStep: 0 }; } componentWillReceiveProps(next) { this.setState({ couldDeploy: false, region: '', deployIdPassToPath: '', groupIdPassToPath: '', currentStep: 0 }); } switchRegion = (e) => { this.setState({ region: e.target.value }); }; pass = (value, kind) => { if (kind === 'deploy') this.setState({ deployIdPassToPath: value }); else if (kind === 'group') this.setState({ groupIdPassToPath: value }); else { this.setState({ pathIdPassToConfig: value }) } }; deployFC = (schema, deploy, api, group) => { console.log('schema', schema); console.log('deploy', deploy); console.log('api', api); console.log('group', group); if (schema && deploy && api && group) { console.log('deploying'); // axios.get(`${deployUrl}`, axios.get(`http://localhost:8999/graphql/deployall`, { // params: { // 'cloud-name': 'tencent', // schema: "ecommerce_schemaID", // deploy: "deploy_1544504304478_57468453", // api: "path_1544504334478_82625598", // group: "group_1544504325443_46750115" // } params: { 'cloud-name': 'tencent', schema, deploy, api, group } }) .then((res) => { console.log('deploy res', res); }) .catch((err) => { console.log('err', err); console.log('err.response', err.response); console.log('err.response.data', err.response.data); }); } }; stepByStep = (stepNum) => { this.setState({ currentStep: stepNum }) }; stepStatus = (value) => { if (this.state.currentStep === value) return '进行中'; else if (this.state.currentStep > value) return '完成'; else return '等待'; }; render() { let projectID = this.props.projectID ? this.props.projectID : 'ecommerce_projectID'; return ( { ({loading, error, data}) => { if (loading) { return } if (error) { return 'error!'; } let group = '', deploy = '', path = '', schemaID = '', configID = '', api = '', cloudID = 'tencent_CloudID'; let dataProject = data.project_by_id; let {cloud_id, apiGWGroup_id, deploy_id, projectType, schema_id, wxConfig_id, projectName} = dataProject; let defaultName = projectName; if (projectType === 'graphql') schemaID = schema_id.id; else configID = wxConfig_id.id; // 如果 cloud_id 没有存储,说明尚未部署,即新的 project,使用 '视图 2' // 旧的 project 使用 '视图 1' if (cloud_id !== null && cloud_id.cloudName === 'tencent') { group = apiGWGroup_id; deploy = deploy_id; cloudID = cloud_id.id; return (
{ projectType === 'graphql' ? schema_id.schemaState === 'ok' ? '' : this.props.trialcase ? '' :
: '' }
{ msg => } { msg => } { ({loading, error, data}) => { if (loading) { return } if (error) { return 'error!'; } if (data.apiGWPath_by_props.length > 0) path = data.apiGWPath_by_props[0]; return ( { msg => } ) } } { msg => } { this.props.trialcase ? '' : projectType === 'graphql' ? schema_id.schemaState === 'ok' ? : : }
) } else { return (
{ projectType === 'graphql' ? schema_id.schemaState === 'ok' ? '' : this.props.trialcase ? '' :
: '' }
{ this.state.currentStep === 0 ? { msg => } : '' } { this.state.currentStep === 1 ? { msg => } : '' } { this.state.currentStep === 2 ? { ({loading, error, data}) => { if (loading) { return } if (error) { return 'error!'; } if (data.apiGWPath_by_props.length > 0) path = data.apiGWPath_by_props[0]; return ( { msg => } ) } } : '' } { this.state.currentStep === 3 ? { msg => } : '' } { this.state.currentStep === 4 ? { this.props.trialcase ? '' : projectType === 'graphql' ? schema_id.schemaState === 'ok' ? : : } : '' }
) } } }
) } } export default TencentConfig;