import React, {Component} from 'react'; import {Input, Radio, Collapse, Button, Icon} from 'antd'; import {request} from 'graphql-request' import {ADD_APIGWPATH, UPDATE_APIGWPATH} from "../../../../gql"; import {idGen} from "../../../../func"; import {graphqlUrl} from "../../../../config"; import {manageUsers} from "../../../../config"; const Panel = Collapse.Panel; // 如需改变显示,请在此处 value 处更改 // 如需添加中文,请在此处 value 处添加 // eg: 'xxxx': const valueToKey = { 'apiGWName': 'Name', 'apiGWDesc': 'Description', 'requestMethod': 'Method' }; class APIPathCard extends Component { constructor(props) { super(props); let {apiGWName, apiGWDesc, requestMethod} = props.path; props.path !== '' ? this.state = { configs: ['apiGWName', 'apiGWDesc'], showOK: false, apiGWName, apiGWDesc, requestMethod: requestMethod } : this.state = { configs: ['apiGWName', 'apiGWDesc'], showOK: false, apiGWName: props.defalutName, apiGWDesc: '', requestMethod: 'GET' }; } componentWillReceiveProps(next) { if (next.path !== '') { let {apiGWName, apiGWDesc, requestMethod} = next.path; this.setState({ apiGWName, apiGWDesc, requestMethod }) } else { this.setState({ apiGWName: next.defalutName, apiGWDesc: '', requestMethod: 'GET' }); } }; switchConfig = (label) => { return (e) => { this.setState({ [label]: e.target.value }) }; }; ok = () => { let {apiGWName, apiGWDesc, requestMethod} = this.state; let varObj = { id: idGen('path'), user_id: this.props.userID, apiGWGroup_id: this.props.groupID, deploy_id: this.props.deployID, apiGWName, apiGWDesc, requestMethod, serviceType: 'SCF', apiGWPath: '/graphql', timeout: 300, apiId: '', createdAt: new Date().getTime(), updatedAt: '' }; if (this.props.path === '') { if(this.props.deployID !== '' && this.props.groupID!=='') { request(graphqlUrl, ADD_APIGWPATH, varObj).then( data => { if (data.create_apiGWPath !== null) { this.setState({ showOK: true }) } setTimeout(()=>{ this.setState({ showOK: false }) }, 1500) } ) } } else { let {apiGWName, apiGWDesc, requestMethod} = this.state; let varObj = { id: this.props.path.id, apiGWName, apiGWDesc, requestMethod, updatedAt: new Date().getTime() }; request(graphqlUrl, UPDATE_APIGWPATH, varObj).then( data => { if (data.update_apiGWPath !== null) { this.setState({ showOK: true }) } setTimeout(()=>{ this.setState({ showOK: false }) }, 1500) } ) } }; render() { const customPanelStyle = { background: '#f7f7f7', borderRadius: 4, marginBottom: 24, border: 0, overflow: 'hidden', }; return (
{ this.state.configs.map(config => (
{valueToKey[config]}:
)) }
{valueToKey['requestMethod']}: get post
{ manageUsers.includes(this.props.userID) ?
{ this.state.showOK === true? : '' }
: this.props.trialcase? '' :
{ this.state.showOK === true? : '' }
}
) } } export default APIPathCard;