Răsfoiți Sursa

调用不成功

kulley 7 ani în urmă
părinte
comite
1586586b63

+ 22 - 1
src/app/basicVersion/BasicVersion.jsx

@@ -90,7 +90,28 @@ class BasicVersion extends Component {
         }
     };
 
+    changeTabBar = (menu) => {
+        this.setState({
+            menuLevel1: menu
+        })
+    };
+
     render() {
+        let ownProps = {
+            changeTabBar: this.changeTabBar
+        };
+
+        let ownPropsUser = {
+            changeLocale: this.changeLocale,
+            languageButton: this.state.languageButton
+        };
+
+        const PrivateRoute = ({component: Component, ownProps, ...rest}) => (
+            <Route {...rest} render={(props) => {
+                return <Component {...ownProps} {...props}/>
+            }}/>
+        );
+
         return (
             <Layout style={{minHeight: '100vh'}}>
                 <Header className="header" style={{position: 'fixed', zIndex: 1, width: '100%'}}>
@@ -140,7 +161,7 @@ class BasicVersion extends Component {
                         <Route path="/common/example" exact component={ExampleShow}/>
                         <Route path="/common/deploy" component={MyDeploy}/>
                         <Route path="/common/communication" component={Communication}/>
-                        <Route path="/common/deploy-cloud-choose" component={DeployCloudChoose}/>
+                        <PrivateRoute path="/common/deploy-cloud-choose" component={DeployCloudChoose} ownProps={ownProps}/>
                     </Switch>
                 </Layout>
 

+ 92 - 29
src/app/basicVersion/exampleShow/DeployCloudChoose.js

@@ -1,19 +1,23 @@
 import React, {Component} from 'react';
-import {Layout, Button, notification} from 'antd';
+import {Layout, Button, notification, Spin} from 'antd';
 import {getCookie} from "../../../cookie";
 import {graphqlUrl} from "../../../config";
 import {SHOW_CLOUD} from "../../../gql";
 import {request} from 'graphql-request'
+import axios from 'axios';
+
 const {Content} = Layout;
+axios.defaults.withCredentials = true;
 
-class DeployCloudChoose extends Component{
-    constructor(){
+class DeployCloudChoose extends Component {
+    constructor() {
         super();
-        this.state={
+        this.state = {
             userID: 'demo',
             secretId: '',
             secretKey: '',
-            appId: ''
+            appId: '',
+            disabled: false
         }
     }
 
@@ -26,7 +30,6 @@ class DeployCloudChoose extends Component{
 
             // 查询是否设置 cloud
             request(graphqlUrl, SHOW_CLOUD, {user_id: userID}).then(data => {
-                    console.log(data.cloud_by_props);
                     data.cloud_by_props.forEach(cloud => {
                         switch (cloud.cloudName) {
                             case 'tencent':
@@ -51,36 +54,96 @@ class DeployCloudChoose extends Component{
         }
     }
 
-    render(){
-        let {userID} = this.state;
-        return(
+    deploy() {
+        let bucketName = '';
+        if (this.props.location && this.props.location.state) {
+            switch (this.props.location.state.schemaID) {
+                case 'order_schemaID':
+                    bucketName = 'order';
+                    break;
+                case 'ecommerce_schemaID':
+                    bucketName = 'ec';
+                    break;
+                default:
+                    break;
+            }
+        }
+        if (bucketName === '') {
+            console.log('state, 没有传值');
+        } else {
+            // 开始调用
+            console.log('开始调用');
+            this.setState({
+                disabled: true
+            });
+            let _this = this;
+            axios.post('http://deploy.ioobot.cn/api/deploy-all',
+                {
+                    'fc-name': this.state.userID + new Date().getTime(),
+                    'bucket': 'native-fc',
+                    'object-file': 'fc-only.zip',
+                    'res-bucket': 'case',
+                    'resources': '["appointment/schema.edn" "appointment/resolve-map.edn" "appointment/mongodb/mongo-config.edn"  "appointment/mongodb/deploy-conf.edn"]',
+                    'service-name': this.state.userID + new Date().getTime(),
+                    'path': "/*"
+                })
+                .then(function (response) {
+                    _this.setState({
+                        disabled: false
+                    });
+                    _this.props.changeTabBar('my-deploy');
+                    _this.props.history.push({
+                        pathname: `/common/deploy`,
+                        state: {}
+                    });
+
+
+                })
+                .catch(function (error) {
+                    console.log(error);
+                });
+        }
+    }
+
+    render() {
+        let {userID, disabled} = this.state;
+        return (
             <div className={'deploy-choose-cloud'}>
-                <Layout style={{ padding: '24px',minHeight:'300px' }}>
-                    <Content style={{ padding: '20px 50px', background: '#fff' }}>
+                <Layout style={{padding: '24px', minHeight: '300px'}}>
+                    <Content style={{padding: '20px 50px', background: '#fff'}}>
                         <div className={'choose-cloud'}>
-                            <span className={'choose-cloud-title'}>系统默认设置</span><span className={'choose-cloud-content'}>部署在系统云服务商,部署成功后返回结果</span>
+                            <span className={'choose-cloud-title'}>系统默认设置</span><span
+                            className={'choose-cloud-content'}>部署在系统云服务商,部署成功后返回结果</span>
                         </div>
                         <div className={'choose-cloud'}>
-                            <span className={'choose-cloud-title'}>自定义设置</span><span className={'choose-cloud-content'}>部署在自有云服务商,部署成功后返回结果,可登陆云服务商后台查看部署结果</span>
+                            <span className={'choose-cloud-title'}>自定义设置</span><span
+                            className={'choose-cloud-content'}>部署在自有云服务商,部署成功后返回结果,可登陆云服务商后台查看部署结果</span>
                         </div>
                         <div className={'choose-cloud-button-group'}>
-                            <Button className={'choose-cloud-button'} type='primary' onClick={()=>{
-                                console.log('默认')
-                            }}>系统默认部署</Button>
-                            <Button className={'choose-cloud-button'} type='primary' onClick={()=>{
-                                if(userID === 'demo') {
-                                    notification['warning']({
-                                        message: '需要登录',
-                                        description: '后续使用,需要先登录',
-                                    });
+                            {
+                                disabled ?
+                                    <Spin/>
+                                    :
+                                    <div>
+                                        <Button className={'choose-cloud-button'} type='primary' onClick={() => {
+                                            this.deploy();
+                                        }}>系统默认部署</Button>
+                                        <Button className={'choose-cloud-button'} type='primary' onClick={() => {
+                                            if (userID === 'demo') {
+                                                notification['warning']({
+                                                    message: '需要登录',
+                                                    description: '后续使用,需要先登录',
+                                                });
 
-                                    this.props.history.push({
-                                        pathname: `/login`
-                                    })
-                                } else {
-                                    console.log('已经登录')
-                                }
-                            }}>自定义参数设置</Button>
+                                                this.props.history.push({
+                                                    pathname: `/login`
+                                                })
+                                            } else {
+                                                this.deploy();
+                                            }
+                                        }}>自定义参数设置</Button>
+                                    </div>
+                            }
                         </div>
                     </Content>
                 </Layout>

+ 52 - 60
src/app/basicVersion/exampleShow/ExampleShow.jsx

@@ -1,7 +1,11 @@
 import React, {Component} from 'react';
-import {Layout, Card, Button, Avatar} from 'antd';
+import {Layout, Card, Button, Avatar, Spin} from 'antd';
 import lo from '../../../images/lo.png'
 import './index.css'
+import {graphqlUrl} from "../../../config";
+import {SHOW_CASE} from "../../../gql";
+
+import {request} from 'graphql-request'
 
 const {Content} = Layout;
 const {Meta} = Card;
@@ -9,75 +13,63 @@ const {Meta} = Card;
 class ExampleShow extends Component {
     constructor(props) {
         super(props);
-        this.state = {}
+        this.state = {
+            examples: []
+        }
     }
 
-    renderCard = () => {
-        let examples = [
-            {
-                schemaID: '',
-                title: '预约',
-                description: '小程序',
-                img: 'https://order-img-1254337200.cos.ap-shanghai.myqcloud.com/gh_09a69a242b5a_258.jpg',
-                deployedNum: 100
-            },
-            {
-                schemaID: '',
-                title: '预约',
-                description: '公众号',
-                img: 'https://order-img-1254337200.cos.ap-shanghai.myqcloud.com/qrcode_for_gh_abcdd8e08f94_258.jpg',
-                deployedNum: 90
-            },
-            {
-                schemaID: '',
-                title: '电商',
-                description: '小程序',
-                img: 'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png',
-                deployedNum: 120
-            },
-            {
-                schemaID: '',
-                title: '电商',
-                description: '公众号',
-                img: 'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png',
-                deployedNum: 105
+    componentWillMount() {
+        request(graphqlUrl, SHOW_CASE, {user_id: 'ioobot'}).then(data => {
+                if (Object.prototype.toString.call(data.case_by_props).split(' ')[1].slice(0, -1).toLowerCase() === 'array') {
+                    this.setState({
+                        examples: data.case_by_props
+                    })
+                }
             }
-        ];
-
-        let {userID} = this.state;
+        )
+    }
 
-        return examples.map((item, index) => (
-            <span key={index} style={{padding: '10px 0'}}>
-                    <Card
-                        key={index}
-                        style={{width: 300}}
-                        cover={<div className='cover-div'><img className='cover-img' src={item.img}
-                                                               alt={item.title + '' + item.description}/></div>}
-                        actions={[
-                            <span>已部署: {item.deployedNum}</span>,
-                            <Button type="primary" onClick={() => {
-                                this.props.history.push({
-                                    pathname: `/common/deploy-cloud-choose`
-                                });
-                            }}>部署</Button>
-                        ]}
-                    >
-                        <Meta
-                            avatar={<Avatar src={lo}/>}
-                            title={item.title}
-                            description={item.description}
-                        />
-                    </Card>
-            </span>
-        ))
-    };
 
     render() {
         return (
             <div id="example-show">
                 <Layout style={{padding: '24px', minHeight: '300px'}}>
                     <Content className="content">
-                        {this.renderCard()}
+
+                        {
+                            this.state.examples.length === 0 ?
+                                <Spin />
+                                :
+                                this.state.examples.map((item, index) => (
+                                    <span key={index} style={{padding: '10px 0'}}>
+                                        <Card
+                                            key={index}
+                                            style={{width: 300}}
+                                            cover={<div className='cover-div'><img className='cover-img' src={item.img}
+                                                                                   alt={item.title + '' + item.description}/>
+                                            </div>}
+                                            actions={[
+                                                <span>已部署: {item.deployedNum}</span>,
+                                                <Button type="primary" onClick={() => {
+                                                    this.props.history.push({
+                                                        pathname: `/common/deploy-cloud-choose`,
+                                                        state: {
+                                                            schemaID: item.schema_id.id,
+                                                            caseID: item.id
+                                                        }
+                                                    });
+                                                }}>部署</Button>
+                                            ]}
+                                        >
+                                            <Meta
+                                                avatar={<Avatar src={lo}/>}
+                                                title={item.title}
+                                                description={item.description}
+                                            />
+                                        </Card>
+                                    </span>
+                                ))
+                        }
                     </Content>
                 </Layout>
             </div>

+ 1 - 0
src/app/developVersion/DevelopVersion.jsx

@@ -143,6 +143,7 @@ class DevelopVersion extends Component {
         // console.log('app language',language);
         let changeLanguage = language === "中文" ? "English" : "中文";
         let local = language === "中文" ? undefined : zhCN;
+        console.log(language);
         let languageButton = language === "中文" ? "中文" : "English";
 
         sessionStorage.setItem("language", changeLanguage);

+ 1 - 1
src/app/developVersion/graphqlService/component/generateJs/GenerateJs.jsx

@@ -59,7 +59,7 @@ class GenerateJs extends Component {
         this._isMounted = true;
         let _this = this;
         let {schemaID} = this.state;
-        // axios.get(`${genJsUrl}?schema=${'schema_1544405636137_14283164'}`)
+        // axios.get(`${genJsUrl}?schema=${'onlineSchema'}`)
         axios.get(`${genJsUrl}?schema=${schemaID}`)
             .then((res) => {
                 if(this._isMounted){

+ 1 - 1
src/config.js

@@ -7,7 +7,7 @@ const graphqlEnvironment = '';
 
 // 基础配置
 const localIP = 'http://localhost';
-const serverIP = 'https://123.206.193.98';
+const serverIP = 'http://123.206.193.98';
 const backendPort = '8999';
 const graphqlPort = '3000';
 

+ 18 - 1
src/gql.js

@@ -982,6 +982,22 @@ const UPDATE_NOTIFICATION = `
             }
         `;
 
+const SHOW_CASE = `
+            query CASE($user_id: ID!) {
+                case_by_props(user_id: $user_id) {
+                    id
+                    img
+                    schema_id {
+                        id
+                    }   
+                    img
+                    deployedNum
+                    title
+                    description
+                }
+            }
+        `;
+
 
 
 export {
@@ -1029,5 +1045,6 @@ export {
     UPDATE_PROJECT_DEPLOY_AND_CLOUD,
     UPDATE_PROJECT_ONLY_STATUS,
     ADD_NOTIFICATION,
-    UPDATE_NOTIFICATION
+    UPDATE_NOTIFICATION,
+    SHOW_CASE
 }

+ 16 - 8
src/index.js

@@ -25,12 +25,12 @@ addLocaleData([...en, ...zh]);
 
 
 const client = new ApolloClient({
-    // uri: "http://service-eucrnpse-1254337200.ap-guangzhou.apigateway.myqcloud.com/release/graphql"
     uri: graphqlUrl
 });
 
 let browserLanguage = (navigator.language || navigator.browserLanguage).toLowerCase().split('-')[0];
-let language = browserLanguage === 'zh'? "中文" : "English";
+let language = browserLanguage === 'zh' ? "中文" : "English";
+
 
 class MainApp extends Component {
     constructor() {
@@ -71,17 +71,25 @@ class MainApp extends Component {
     render() {
         let {language} = this.state;
         let {locale, messages} = this.chooseLocale(language);
+        let ownProps = {
+            language,
+            changeLanguage: this.changeLanguage
+        };
+        const PrivateRoute = ({component: Component, ownProps, ...rest}) => (
+            <Route {...rest} render={(props) => {
+                return <Component {...ownProps} {...props}/>
+            }}/>
+        );
         return (
             <ApolloProvider client={client}>
                 <IntlProvider locale={locale} messages={messages}>
                     <Router>
                         <Switch>
-                            <Route exact path="/" component={App} />
-                            <Route path="/developer" component={DevelopVersion} />
-                            {/*<Route path="/developer" component={<App language={language} changeLanguage={this.changeLanguage}/>} />*/}
-                            <Route path="/common" component={BasicVersion} />
-                            <Route path="/login" component={Login} />
-                            <Route path="/ticket" component={Ticket} />
+                            <Route exact path="/" component={App}/>
+                            <PrivateRoute path="/developer" ownProps={ownProps} component={DevelopVersion}/>
+                            <PrivateRoute path="/common" ownProps={ownProps} component={BasicVersion}/>
+                            <Route path="/login" component={Login}/>
+                            <Route path="/ticket" component={Ticket}/>
                         </Switch>
                     </Router>
                 </IntlProvider>