소스 검색

add wxconfig deploy

xy 7 년 전
부모
커밋
b4a33cf71c

+ 174 - 81
src/app/common/deploy/Deploy.jsx

@@ -6,7 +6,7 @@ import AliConfig from './ali/AliConfig';
 import AmazonConfig from './amazon/AmazonConfig';
 
 import './index.css';
-import {SHOW_FC, SEARCH_SCHEMA, SHOW_CLOUD} from "../../../gql";
+import {SHOW_FC_SCHEMA, SHOW_FC_CONFIG, SEARCH_SCHEMA, SHOW_CLOUD, SHOW_WXCONTENT} from "../../../gql";
 import {request} from 'graphql-request'
 
 const tabListNoTitle = [{
@@ -30,104 +30,197 @@ class Deploy extends Component {
             tencentCloudID: '',
             aliyunCloudID: '',
             amazonCloudID: '',
-            schemaName: '',
+            defalutName: '',
             tencentFC: '',
             aliyunFC: '',
             amazonFC: '',
-            schemaID: props.schemaID
+            schemaID: props.schemaID,
+            configID: props.configID,
+            kind: ''
         };
         this.fetch();
     }
 
     componentWillReceiveProps(next) {
         this.setState({
-            schemaID: next.schemaID
+            schemaID: next.schemaID,
+            configID: next.configID
         }, this.fetch)
     }
 
     fetch = () => {
-        request('http://123.206.193.98:3000/graphql', SHOW_FC, {schema_id: this.state.schemaID}).then(
-            // 根据 schemaID 查询 fc 是否成功
-            data => {
-                request('http://123.206.193.98:3000/graphql', SEARCH_SCHEMA, {id: this.state.schemaID}).then(
-                    // 根据 schemaID 查询 schemaName
-                    _data => {
-                        if (data.fc_by_props.length === 0) {
-                            // 如果没有 fc,根据 userID 查 cloudId
-                            request('http://123.206.193.98:3000/graphql', SHOW_CLOUD, {user_id: this.props.userID}).then(
-                                __data => {
-                                    __data.cloud_by_props.forEach(cloud => {
-                                        switch (cloud.cloudName) {
-                                            case 'tencent':
-                                                this.setState({
-                                                    tencentFC: false,
-                                                    tencentCloudID: cloud.id,
-                                                    schemaName: _data.schema_by_id.schemaName,
-                                                    show: true
-                                                });
-                                                break;
-                                            case 'aliyun':
-                                                this.setState({
-                                                    aliyunFC: false,
-                                                    aliyunCloudID: cloud.id,
-                                                    schemaName: _data.schema_by_id.schemaName,
-                                                    show: true
-                                                });
-                                                break;
-                                            case 'amazon':
-                                                this.setState({
-                                                    amazonFC: false,
-                                                    amazonCloudID: cloud.id,
-                                                    schemaName: _data.schema_by_id.schemaName,
-                                                    show: true
-                                                });
-                                                break;
-                                            default:
-                                                break;
-                                        }
-                                    })
-                                }
-                            );
-                        } else {
-                            // 如果有 fc, 则获取 cloudID
-                            data.fc_by_props.forEach(cloud => {
-                                switch (cloud.cloud_id.cloudName) {
-                                    case 'tencent':
-                                        this.setState({
-                                            tencentFC: true,
-                                            tencentCloudID: cloud.cloud_id.id,
-                                            show: true
-                                        });
-                                        break;
-                                    case 'aliyun':
-                                        this.setState({
-                                            aliyunFC: true,
-                                            aliyunCloudID: cloud.cloud_id.id,
-                                            show: true
-                                        });
-                                        break;
-                                    case 'amazon':
-                                        this.setState({
-                                            amazonFC: true,
-                                            amazonCloudID: cloud.cloud_id.id,
-                                            show: true
-                                        });
-                                        break;
-                                    default:
-                                        break;
-                                }
-                            })
+        if (this.state.schemaID !== '' && this.state.schemaID !== undefined) {
+            request('http://123.206.193.98:3000/graphql', SHOW_FC_SCHEMA, {schema_id: this.state.schemaID}).then(
+                // 根据 schemaID 查询 fc 是否成功
+                data => {
+                    request('http://123.206.193.98:3000/graphql', SEARCH_SCHEMA, {id: this.state.schemaID}).then(
+                        // 根据 schemaID 查询 schemaName
+                        _data => {
+                            if (data.fc_by_props.length === 0) {
+                                // 如果没有 fc,根据 userID 查 cloudId
+                                request('http://123.206.193.98:3000/graphql', SHOW_CLOUD, {user_id: this.props.userID}).then(
+                                    __data => {
+                                        __data.cloud_by_props.forEach(cloud => {
+                                            switch (cloud.cloudName) {
+                                                case 'tencent':
+                                                    this.setState({
+                                                        tencentFC: false,
+                                                        tencentCloudID: cloud.id,
+                                                        defalutName: _data.schema_by_id.schemaName,
+                                                        show: true,
+                                                        kind: 'graphql'
+                                                    });
+                                                    break;
+                                                case 'aliyun':
+                                                    this.setState({
+                                                        aliyunFC: false,
+                                                        aliyunCloudID: cloud.id,
+                                                        defalutName: _data.schema_by_id.schemaName,
+                                                        show: true,
+                                                        kind: 'graphql'
+                                                    });
+                                                    break;
+                                                case 'amazon':
+                                                    this.setState({
+                                                        amazonFC: false,
+                                                        amazonCloudID: cloud.id,
+                                                        defalutName: _data.schema_by_id.schemaName,
+                                                        show: true,
+                                                        kind: 'graphql'
+                                                    });
+                                                    break;
+                                                default:
+                                                    break;
+                                            }
+                                        })
+                                    }
+                                );
+                            } else {
+                                // 如果有 fc, 则获取 cloudID
+                                data.fc_by_props.forEach(cloud => {
+                                    switch (cloud.cloud_id.cloudName) {
+                                        case 'tencent':
+                                            this.setState({
+                                                tencentFC: true,
+                                                tencentCloudID: cloud.cloud_id.id,
+                                                show: true,
+                                                kind: 'graphql'
+                                            });
+                                            break;
+                                        case 'aliyun':
+                                            this.setState({
+                                                aliyunFC: true,
+                                                aliyunCloudID: cloud.cloud_id.id,
+                                                show: true,
+                                                kind: 'graphql'
+                                            });
+                                            break;
+                                        case 'amazon':
+                                            this.setState({
+                                                amazonFC: true,
+                                                amazonCloudID: cloud.cloud_id.id,
+                                                show: true,
+                                                kind: 'graphql'
+                                            });
+                                            break;
+                                        default:
+                                            break;
+                                    }
+                                })
+                            }
+                        }
+                    );
+                }
+            );
+        } else {
+            request('http://123.206.193.98:3000/graphql', SHOW_FC_CONFIG, {wxConfig_id: this.state.configID}).then(
+                // 根据 configID 查询 fc 是否成功
+                data => {
+                    request('http://123.206.193.98:3000/graphql', SHOW_WXCONTENT, {id: this.state.configID}).then(
+                        // 根据 configID 查询 appName
+                        _data => {
+                            if (data.fc_by_props.length === 0) {
+                                // 如果没有 fc,根据 userID 查 cloudId
+                                request('http://123.206.193.98:3000/graphql', SHOW_CLOUD, {user_id: this.props.userID}).then(
+                                    __data => {
+                                        __data.cloud_by_props.forEach(cloud => {
+                                            switch (cloud.cloudName) {
+                                                case 'tencent':
+                                                    this.setState({
+                                                        tencentFC: false,
+                                                        tencentCloudID: cloud.id,
+                                                        defalutName: _data.wxConfig_by_id.appName,
+                                                        show: true,
+                                                        kind: 'wx'
+                                                    });
+                                                    break;
+                                                case 'aliyun':
+                                                    this.setState({
+                                                        aliyunFC: false,
+                                                        aliyunCloudID: cloud.id,
+                                                        defalutName: _data.wxConfig_by_id.appName,
+                                                        show: true,
+                                                        kind: 'wx'
+                                                    });
+                                                    break;
+                                                case 'amazon':
+                                                    this.setState({
+                                                        amazonFC: false,
+                                                        amazonCloudID: cloud.id,
+                                                        defalutName: _data.wxConfig_by_id.appName,
+                                                        show: true,
+                                                        kind: 'wx'
+                                                    });
+                                                    break;
+                                                default:
+                                                    break;
+                                            }
+                                        })
+                                    }
+                                );
+                            } else {
+                                // 如果有 fc, 则获取 cloudID
+                                data.fc_by_props.forEach(cloud => {
+                                    switch (cloud.cloud_id.cloudName) {
+                                        case 'tencent':
+                                            this.setState({
+                                                tencentFC: true,
+                                                tencentCloudID: cloud.cloud_id.id,
+                                                show: true,
+                                                kind: 'wx'
+                                            });
+                                            break;
+                                        case 'aliyun':
+                                            this.setState({
+                                                aliyunFC: true,
+                                                aliyunCloudID: cloud.cloud_id.id,
+                                                show: true,
+                                                kind: 'wx'
+                                            });
+                                            break;
+                                        case 'amazon':
+                                            this.setState({
+                                                amazonFC: true,
+                                                amazonCloudID: cloud.cloud_id.id,
+                                                show: true,
+                                                kind: 'wx'
+                                            });
+                                            break;
+                                        default:
+                                            break;
+                                    }
+                                })
+                            }
                         }
-                    }
-                );
-            }
-        );
+                    );
+                }
+            );
+        }
     };
 
-
     render() {
         const contentListNoTitle = {
-            tencent: <TencentConfig cloudID={this.state.tencentCloudID} fc={this.state.tencentFC} schemaName={this.state.schemaName} userID={this.props.userID}/>,
+            tencent: <TencentConfig cloudID={this.state.tencentCloudID} fc={this.state.tencentFC} defalutName={this.state.defalutName} userID={this.props.userID} kind={this.state.kind}/>,
             aliyun: <AliConfig/>,
             amazon: <AmazonConfig/>,
         };

+ 2 - 2
src/app/common/deploy/tencent/APIPathCard.js

@@ -24,7 +24,7 @@ class APIPathCard extends Component {
             this.state = {
                 configs: ['apiGWName', 'apiGWDesc'],
                 showOK: false,
-                apiGWName: props.schemaName,
+                apiGWName: props.defalutName,
                 apiGWDesc: '',
                 requestMethod: 'GET'
             };
@@ -41,7 +41,7 @@ class APIPathCard extends Component {
             })
         } else {
             this.setState({
-                apiGWName: next.schemaName,
+                apiGWName: next.defalutName,
                 apiGWDesc: '',
                 requestMethod: 'GET'
             });

+ 4 - 4
src/app/common/deploy/tencent/DeployCard.js

@@ -31,10 +31,10 @@ class DeployCard extends Component {
                 configs: ['description', 'cosBucketName', 'cosObjectName', 'vpcId', 'subnetId'],
                 description: '',
                 showOK: false,
-                functionName: props.schemaName,
+                functionName: props.defalutName,
                 region: props.region,
                 cosBucketName: 'graphqlfc',
-                cosObjectName: props.schemaName,
+                cosObjectName: props.defalutName,
                 cosBucketRegion: props.region,
                 serviceName: '',
                 vpcId: '',
@@ -57,10 +57,10 @@ class DeployCard extends Component {
             })
         } else {
             this.setState({
-                functionName: next.schemaName,
+                functionName: next.defalutName,
                 region: next.region,
                 cosBucketName: 'graphqlfc',
-                cosObjectName: next.schemaName,
+                cosObjectName: next.defalutName,
                 cosBucketRegion: next.region,
                 serviceName: '',
                 vpcId: '',

+ 3 - 3
src/app/common/deploy/tencent/TencentConfig.js

@@ -96,9 +96,9 @@ class TencentConfig extends Component {
                 <div style={{padding: '30px'}}>
                     <Row gutter={16}>
                         <Col span={14}>
-                            <Card title="Deploy" style={{marginBottom: 10}}><DeployCard deploy={this.state.currentDeploy} switchRegion={this.switchRegion} region={this.state.region} schemaName={this.props.schemaName} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass}/></Card>
-                            <Card title="API Group" style={{marginBottom: 10}}><APIGroupCard group={this.state.currentGroup} switchRegion={this.switchRegion} region={this.state.region} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass}/></Card>
-                            <Card title="API Path" style={{marginBottom: 10}}><APIPathCard path={this.state.currentPath} schemaName={this.props.schemaName} userID={this.props.userID} deployID={this.state.currentDeploy? this.state.currentDeploy.id : this.state.deployIdPassToPath} groupID={this.state.currentGroup? this.state.currentGroup.id : this.state.groupIdPassToPath}/></Card>
+                            <Card title="Deploy" style={{marginBottom: 10}}><DeployCard deploy={this.state.currentDeploy} switchRegion={this.switchRegion} region={this.state.region} defalutName={this.props.defalutName} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass} kind={this.props.kind}/></Card>
+                            <Card title="API Group" style={{marginBottom: 10}}><APIGroupCard group={this.state.currentGroup} switchRegion={this.switchRegion} region={this.state.region} userID={this.props.userID} cloudID={this.props.cloudID} pass={this.pass} kind={this.props.kind}/></Card>
+                            <Card title="API Path" style={{marginBottom: 10}}><APIPathCard path={this.state.currentPath} defalutName={this.props.defalutName} userID={this.props.userID} deployID={this.state.currentDeploy? this.state.currentDeploy.id : this.state.deployIdPassToPath} groupID={this.state.currentGroup? this.state.currentGroup.id : this.state.groupIdPassToPath}/></Card>
                             <Card title="Notification"><NotificationCard userID={this.props.userID}/></Card>
                         </Col>
                         <Col offset={2} span={6}>

+ 1 - 1
src/app/graphqlService/TrialCase.jsx

@@ -59,7 +59,7 @@ class TrialCase extends Component {
                                     case 'schema':
                                         return <Schema trialcase={true} userID={this.state.userID} schemaName={schemaName} schemaID={schemaID} history={this.props.history} location={this.props.location}/>;
                                     case 'deploy':
-                                        return <Deploy userID={this.state.userID} schemaID={schemaID} schemaName={schemaName}/>;
+                                        return <Deploy userID={this.state.userID} schemaID={schemaID}/>;
                                     case 'graphiql':
                                         return <Graphql/>;
                                     case 'templeate':

+ 1 - 1
src/app/graphqlService/UserCreate.jsx

@@ -72,7 +72,7 @@ class UserCreate extends Component {
                                     case 'schema':
                                         return <Schema trialcase={false} userID={this.state.userID} schemaName={schemaName} schemaID={schemaID} history={this.props.history} location={this.props.location}/>;
                                     case 'deploy':
-                                        return <Deploy userID={this.state.userID} schemaID={schemaID} schemaName={schemaName}/>;
+                                        return <Deploy userID={this.state.userID} schemaID={schemaID}/>;
                                     case 'graphiql':
                                         return <Graphql/>;
                                     case 'template':

+ 5 - 3
src/app/wechatService/WxTrialCase.js

@@ -5,7 +5,6 @@ import {Layout, Menu} from 'antd';
 import WxConfig from "./wxConfig/WxConfig";
 import WxDeploy from "../common/deploy/Deploy";
 import WxResult from './wxResult/WxResult';
-import Schema from "../graphqlService/component/schema/Schema";
 
 const {Content} = Layout;
 
@@ -14,6 +13,7 @@ class WxTrialCase extends Component {
         super();
         this.state = {
             menuLevel3: "wechat-config",
+            userID: 'ioobot'
         }
     }
 
@@ -24,6 +24,8 @@ class WxTrialCase extends Component {
     };
 
     render() {
+        let configID = this.props.history.location.state ? this.props.history.location.state.configID : "ecommerce_wxConfigID";
+        let appName = this.props.history.location.state ? this.props.history.location.state.appName : "ecommerce";
         return (
             <div>
                 <Menu
@@ -50,9 +52,9 @@ class WxTrialCase extends Component {
                         {(() => {
                             switch (this.state.menuLevel3) {
                                 case 'wechat-config':
-                                    return <WxConfig defaultAppName={'ec... whatever'} defaultConfigID={'wxConfig_1543997888848_62199988'} trialcase={true} history={this.props.history} location={this.props.location}/>;
+                                    return <WxConfig defaultAppName={'ecommerce'} defaultConfigID={'ecommerce_wxConfigID'} trialcase={true} history={this.props.history} location={this.props.location}/>;
                                 case 'wechat-deploy':
-                                    return <WxDeploy/>;
+                                    return <WxDeploy userID={this.state.userID} configID={configID}/>;
                                 case 'wechat-result':
                                     return <WxResult/>;
                                 default:

+ 23 - 1
src/app/wechatService/WxUserCreate.js

@@ -5,6 +5,9 @@ import {Layout, Menu} from 'antd';
 import WxConfig from "./wxConfig/WxConfig";
 import WxDeploy from "../common/deploy/Deploy";
 import WxResult from './wxResult/WxResult';
+import axios from 'axios';
+
+axios.defaults.withCredentials = true;
 
 const {Content} = Layout;
 
@@ -13,9 +16,26 @@ class WxUserCreate extends Component {
         super();
         this.state = {
             menuLevel3: "wechat-config",
+            userID: '',
+            getID_url: 'http://123.206.193.98:8999/getuserid',
         }
     }
 
+    componentWillMount() {
+        let _this = this;
+        axios.get(this.state.getID_url)
+            .then((res) => {
+                if (res.data !== '') {
+                    _this.setState({
+                        userID: res.data
+                    })
+                }
+            })
+            .catch(function (err) {
+                console.log(err);
+            });
+    }
+
     switchMenu = (menuName, e) => {
         this.setState({
             [menuName]: e.key,
@@ -23,6 +43,8 @@ class WxUserCreate extends Component {
     };
 
     render() {
+        let configID = this.props.history.location.state ? this.props.history.location.state.configID : "ecommerce_wxConfigID";
+        let appName = this.props.history.location.state ? this.props.history.location.state.appName : "ecommerce";
         return (
             <div>
                 <Menu
@@ -51,7 +73,7 @@ class WxUserCreate extends Component {
                                 case 'wechat-config':
                                     return <WxConfig history={this.props.history} location={this.props.location}/>;
                                 case 'wechat-deploy':
-                                    return <WxDeploy/>;
+                                    return <WxDeploy userID={this.state.userID} configID={configID}/>;
                                 case 'wechat-result':
                                     return <WxResult/>;
                                 default:

+ 1 - 3
src/app/wechatService/wxConfig/WxConfig.jsx

@@ -36,7 +36,7 @@ class WxConfig extends Component {
                         if (error) {
                             return 'error!';
                         }
-                        let {history, location, defaultConfigID, defaultAppName, trialcase} = this.props;
+                        let {history, location, trialcase} = this.props;
                         let {appName, configID, configs} = this.state;
                         return (
                             <Display
@@ -45,8 +45,6 @@ class WxConfig extends Component {
                                 appName={appName}
                                 location={location}
                                 history={history}
-                                defaultConfigID={defaultConfigID}
-                                defaultAppName={defaultAppName}
                                 trialcase={trialcase}
                                 data={data.wxConfig_by_id}
                             />

+ 15 - 3
src/gql.js

@@ -364,7 +364,7 @@ const UPDATE_APIGWPATH = `
         `;
 
 
-const SHOW_FC = `
+const SHOW_FC_SCHEMA = `
             query FC($schema_id: ID!) {
                 fc_by_props(schema_id: $schema_id) {
                     cloud_id {
@@ -375,6 +375,17 @@ const SHOW_FC = `
             }
         `;
 
+const SHOW_FC_CONFIG = `
+            query FC($wxConfig_id: ID!) {
+                fc_by_props(wxConfig_id: $wxConfig_id) {
+                    cloud_id {
+                        id
+                        cloudName
+                    }
+                }
+            }
+        `;
+
 const SHOW_ALL_WXCONFIG = `
             query WXCONFIG($user_id: ID) {
                 userWxConfig:wxConfig_by_props(user_id: $user_id) {
@@ -552,11 +563,12 @@ export {
     SHOW_APIGWPATH,
     ADD_APIGWPATH,
     UPDATE_APIGWPATH,
-    SHOW_FC,
+    SHOW_FC_SCHEMA,
+    SHOW_FC_CONFIG,
     SHOW_ALL_WXCONFIG,
     SHOW_WXCONFIG,
     ADD_WXCONFIG,
     SHOW_WXCONTENT,
     UPDATE_WXCONFIG,
-    DELETE_WXCONFIG
+    DELETE_WXCONFIG,
 }