import React, {Component} from 'react'; import {FormattedMessage} from 'react-intl'; import {Switch, Input, Icon, Spin, Row, Col, message} from 'antd'; import { DELETE_APIGWPATH, DELETE_APIGROUP, GET_PROJECT, SHOW_APIGWPATH, UPDATE_APIGROUP, UPDATE_PROJECT_ONLY_STATUS } from "../../../../gql"; import {request} from 'graphql-request' import gql from "graphql-tag"; import {Query, Mutation} from "react-apollo"; import copy from 'copy-to-clipboard'; import axios from 'axios'; import {removeAPI, graphqlUrl} from "../../../../config"; axios.defaults.withCredentials = true; class TencentResult extends Component { constructor(props) { super(props); this.state = {} } render() { let projectID = this.props.projectID ? this.props.projectID : this.props.kind === 'graphql' ? 'ecommerce_projectID' : 'ecommerce_projectID_wx'; return ( { ({loading, error, data}) => { if (loading) { return } if (error) { return 'error!'; } let group = data.project_by_id.apiGWGroup_id || {}; let projectType = data.project_by_id.projectType || 'graphql'; let projectStatus = data.project_by_id.projectStatus || 'created'; let cloudID = data.project_by_id.cloud_id || 'tencent_CloudID'; return (
{ projectStatus === 'deployed'?
{group.serviceId} {group.defaultDomain} { copy(group.defaultDomain); message.success('复制成功.'); }}/> {group.frontType} {group.environmentName} { this.props.trialcase? : }   { this.props.trialcase ? '' : }
: projectStatus === 'updated'? : }
) } }
) } } export default TencentResult; class SwitchStatus extends Component { constructor(props) { super(props); this.state = { checked: props.group.userStatus === 'open' } } componentWillReceiveProps(next) { this.setState({ checked: next.group.userStatus === 'open' }) } render() { let {group} = this.props; let {id, userDomain, groupName, frontType, region, environmentName} = group; return (
{ this.setState({ checked: data.update_apiGWGroup.userStatus === 'open' }) }} > {(update_apiGWGroup, {loading, error}) => { if (loading) return ; if (error) return 'error'; return ( { update_apiGWGroup({ variables: { id, userStatus: checked ? 'open' : 'close', userDomain, groupName, frontType, region, environmentName, updatedAt: new Date().getTime() } }) }}/> ) }}
) } } class APIGWPathResult extends Component { constructor(props) { super(props); this.state = {} } render() { let {group, projectType} = this.props; let {id} = group; return ( { ({loading, error, data}) => { if (loading) { return } if (error) { return 'error!'; } let paths = data.apiGWPath_by_props || []; return (
{ Object.keys(paths).length !== 0 ?
{ paths.map(path => (
{path.apiGWName} {path.apiGWPath} {path.requestMethod} {path.apiGWDesc} { projectType === 'graphql'? { this.props.switchMenu('menuLevel2', {key: 'graphiql'}); }}> : '' }   { this.props.trialcase? '' : }
)) }
: '路径不存在' }
) } }
) } } class DeletePathSpan extends Component { constructor(props) { super(props); this.state = { } } render() { return ( {(delete_apiGWPath, {loading, error}) => { if (error) return 'error'; if (loading) return ; return ( { let _this = this; axios.get(`${removeAPI}`, { params: { 'cloud-id': `${_this.props.cloudID}`, 'group-id': `${_this.props.groupID}`, 'api-id': `${_this.props.path.id}` } }) .then((res) => { console.log('delete api'); if (res.data !== '') { console.log('path id', _this.props.path.id, 'user id', _this.props.userID); delete_apiGWPath({variables: {id:_this.props.path.id, user_id: _this.props.userID}}); // 写回 project 状态 request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, { id: this.props.projectID, updatedAt: new Date().getTime(), projectStatus: 'grouped' }); console.log(res.data); } else { console.log('error'); } }) .catch((err) => { console.log(err); }); }} > 删除 ) }} ) } } class DeleteGroupSpan extends Component { constructor(props) { super(props); this.state = { } } render() { let {projectID, cloudID, groupID, userID} = this.props; return ( {(delete_apiGWGroup, {loading, error}) => { if (error) return 'error'; if (loading) return ; return ( { axios.get(`${removeAPI}`, { params: { 'cloud-id': `${cloudID}`, 'group-id': `${groupID}`, } }) .then((res) => { console.log('delete service'); if (res.data !== '') { delete_apiGWGroup({variables: {id: groupID, user_id: userID}}); // 写回 project 状态 request(graphqlUrl, UPDATE_PROJECT_ONLY_STATUS, { id: projectID, updatedAt: new Date().getTime(), projectStatus: 'functioned' }); console.log(res.data); } else { console.log('error'); } }) .catch((err) => { console.log(err); }); }} > 删除 ) }} ) } }