import React, {Component} from 'react'; import {Link} from 'react-router-dom'; import {deployAll, graphqlUrl, storeFile, copyCos} from "../../../config"; import {ADD_APIGROUP, ADD_APIGWPATH, ADD_DEPLOY, ADD_PROJECT, SHOW_CLOUD} from "../../../gql"; import {CloudConfig} from "../../../login/CloudConfig"; import {Button, message, Modal, Icon, Steps, Row, Col} from 'antd'; import {FormattedMessage} from 'react-intl'; import {request} from 'graphql-request' import {idGen} from "../../../func"; import axios from 'axios'; import './index.css'; const Step = Steps.Step; axios.defaults.withCredentials = true; class UserCustom extends Component { constructor(props) { super(props); this.state = { userID: props.userID, bucketName: props.bucketName, customName: '', cloudName: 'tencent', dbKind: 'fc-db', // mongodb fc-db disableDeployButton: false, deployFailed: false }; this.cloudState = { cloudID: '', secretID: '', secretKey: '', appId: '' } } getCloudDetail = (cloudID, secretID, secretKey, appId) => { this.cloudState = { cloudID, secretID, secretKey, appId } }; deploy = () => { this._isMounted = true; let _this = this; let {userID, dbKind, bucketName, customName} = this.state; let {cloudID} = this.cloudState; if (bucketName === '') { console.log('state, 没有传值'); } else { console.log('开始调用'); this.setState({ disableDeployButton: true }); let now = new Date().getTime(), functionName = userID + '_' + customName, serviceName = userID + '_' + customName, resources = [`${bucketName}/schema.edn`, `${bucketName}/resolve-map.edn`, `${bucketName}/${dbKind}/${userID}/deploy-conf.edn`, `${bucketName}/html/index.html`, `${bucketName}/wx-config.edn`]; if (dbKind === 'mongodb') { resources.push(`${bucketName}/${dbKind}/${userID}/mongo-config.edn`) } console.log('now', now, 'functionName', functionName, 'serviceName', serviceName, 'resources', resources); axios.post(deployAll, { 'fc-name': functionName, 'bucket': dbKind === 'mongodb' ? 'native-fc' : 'fcdb-deploy', 'object-file': 'fc-only.zip', 'res-bucket': 'case', 'resources': resources, 'service-name': serviceName, 'path': "/*" }) .then(function (response) { console.log('response', response); if (response['data']['apigw-result'] && response['data']['fc-result']) { // 处理数据 let result = response['data']['apigw-result']; let apiData = result['api-info']; let serviceData = result['service-info']; // 存数据 let pathID = idGen('path'), groupID = idGen('group'), deployID = idGen('deploy'), projectID = idGen('project'); let {apiId, path, method} = apiData; let {serviceName, serviceId, subDomain} = serviceData; let pathVarObj = { id: idGen('path'), user_id: userID, apiGWGroup_id: pathID, deploy_id: deployID, apiGWName: functionName, requestMethod: method, apiGWPath: path, apiId: apiId, apiGWDesc: '', serviceType: 'SCF', timeout: 300, createdAt: now, updatedAt: '' }; let projectVarObj = { id: projectID, projectType: 'case', cloud_id: cloudID, user_id: userID, projectName: functionName, database_id: '', apiGWGroup_id: '', deploy_id: '', case_id: '', wxConfig_id: '', schema_id: '', createdAt: now, updatedAt: '', projectStatus: 'deployed' }; let groupVarObj = { id: groupID, cloud_id: cloudID, user_id: userID, userStatus: '', userDomain: '', groupName: serviceName, frontType: '', region: '', environmentName: '', defaultDomain: subDomain, status: '', serviceId: serviceId, createdAt: now, updatedAt: '' }; let deployVarObj = { id: deployID, cloud_id: cloudID, functionName, cosObjectName: '', region: '', cosBucketRegion: '', description: '', cosBucketName: '', vpcId: '', subnetId: '', memorySize: 512, timeout: 300, handler: '', serviceName: "", fc_id: '', createdAt: now, updatedAt: '' }; let add_apigwpath = request(graphqlUrl, ADD_APIGWPATH, pathVarObj), add_project = request(graphqlUrl, ADD_PROJECT, projectVarObj), add_apigroup = request(graphqlUrl, ADD_APIGROUP, groupVarObj), add_deploy = request(graphqlUrl, ADD_DEPLOY, deployVarObj); Promise.all([add_apigwpath, add_project, add_apigroup, add_deploy]) .then(value => { console.log(value); // 展示数据 if (_this._isMounted) { _this.setState({ disableDeployButton: false }); } _this.props.history.push({ pathname: `/common/deploy`, state: { // 处理传回数据,直接拼接 url: `http://${subDomain}/test/` } }); }) .catch(err => { console.log(err); }); } else { console.log('deployAll 失败'); _this.setState({ deployFailed: true, disableDeployButton: false }) } }) .catch(function (error) { console.log('axios error', error); }); } }; componentWillMount() { this._isMounted = true; } componentWillUnmount() { this._isMounted = false; } render() { let {cloudName, customName, disableDeployButton, userID, check, dbKind, bucketName, deployFailed} = this.state; let {appId, secretID, secretKey} = this.cloudState; return (