xy 7 лет назад
Родитель
Сommit
e34326d808
1 измененных файлов с 114 добавлено и 67 удалено
  1. 114 67
      src/components/app/App.jsx

+ 114 - 67
src/components/app/App.jsx

@@ -15,12 +15,16 @@ import TrialCase from "../trialCase/TrialCase";
 import Login from "../login/Login";
 import '../common/graphql/index.css';
 import './index.css'
-import {DELETE_SCHEMA, SHOW_SCHEMA} from "../gql";
+import {SHOW_SCHEMA} from "../gql";
+import axios from 'axios';
+
+axios.defaults.withCredentials = true;
 
 const {SubMenu} = Menu;
 const {Header, Sider} = Layout;
 moment.locale('en');
 
+
 class App extends Component {
     constructor(props) {
         super(props);
@@ -31,7 +35,8 @@ class App extends Component {
             collapsed: false,
             inlineCollapsed: false,
             locale: undefined,
-            language: sessionStorage.getItem("language")
+            language: sessionStorage.getItem("language"),
+            userID: ''
         };
     }
 
@@ -112,7 +117,10 @@ class App extends Component {
                         switch (this.state.menuLevel1) {
                             case 'graphql-service':
                                 return (
-                                    <GraphqlSidebar collapsed={this.state.collapsed} onCollapse={this.onCollapse} inlineCollapsed={this.state.inlineCollapsed} sideBar={this.state.sideBar} switchMenu={this.switchMenu}/>
+                                    <GraphqlSidebar collapsed={this.state.collapsed} onCollapse={this.onCollapse}
+                                                    inlineCollapsed={this.state.inlineCollapsed}
+                                                    sideBar={this.state.sideBar} switchMenu={this.switchMenu}
+                                                    userID={this.state.userID}/>
                                 );
                             case 'wechat-service':
                                 return (
@@ -202,7 +210,10 @@ class App extends Component {
                                 );
                             default:
                                 return (
-                                    <GraphqlSidebar collapsed={this.state.collapsed} onCollapse={this.onCollapse} inlineCollapsed={this.state.inlineCollapsed} sideBar={this.state.sideBar} switchMenu={this.switchMenu}/>
+                                    <GraphqlSidebar collapsed={this.state.collapsed} onCollapse={this.onCollapse}
+                                                    inlineCollapsed={this.state.inlineCollapsed}
+                                                    sideBar={this.state.sideBar} switchMenu={this.switchMenu}
+                                                    userID={this.state.userID}/>
                                 );
                         }
                     })()}
@@ -229,69 +240,104 @@ class App extends Component {
 export default App;
 
 class GraphqlSidebar extends Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+            getID_url: 'http://123.206.193.98:8999/getuserid',
+            userID: '',
+            show: false
+        }
+    }
+
+
+    componentWillMount() {
+        let _this = this;
+        axios.get(this.state.getID_url)
+            .then((res) => {
+                console.log(res);
+                if (res.data !== '') {
+                    _this.setState({
+                        userID: res.data,
+                        show: true
+                    })
+                } else {
+                    _this.setState({
+                        show: true
+                    })
+                }
+            })
+            .catch((err) => {
+                console.log(err);
+            });
+    }
+
+
     render() {
-        let userID = 'ioobot';
         return (
-            <Query query={gql(SHOW_SCHEMA)} variables={{user_id: userID}}>
-                {
-                    ({loading, error, data}) => {
-                        if (loading) return <Spin style={{marginLeft: 3}}/>;
-                        if (error) return 'error!';
-                        return (
-                            <Sider
-                                width={200}
-                                style={{background: '#fff', marginTop: '64px', zIndex: '0'}}
-                                collapsible
-                                collapsed={this.props.collapsed}
-                                onCollapse={this.props.onCollapse}
-                            >
-                                <Menu
-                                    theme="dark"
-                                    mode="inline"
-                                    inlineCollapsed={this.props.inlineCollapsed}
-                                    defaultSelectedKeys={['e-commerce']}
-                                    defaultOpenKeys={['trial-case', 'my-create']}
-                                    // openKeys={['cloud-function']}
-                                    onClick={(e) => this.props.switchMenu('sideBar', e)}
-                                    selectedKeys={[this.props.sideBar]}
-                                    style={{
-                                        borderRight: 0,
-                                        overflow: 'auto',
-                                        height: '100vh',
-                                        left: '0',
-                                        width: '200px',
-                                        position: 'fixed'
-                                    }}
+            this.state.show ?
+                <Query query={gql(SHOW_SCHEMA)} variables={{user_id: this.state.userID}}>
+                    {
+                        ({loading, error, data}) => {
+                            if (loading) return <Spin style={{marginLeft: 3}}/>;
+                            if (error) return 'error!';
+                            return (
+                                <Sider
+                                    width={200}
+                                    style={{background: '#fff', marginTop: '64px', zIndex: '0'}}
+                                    collapsible
+                                    collapsed={this.props.collapsed}
+                                    onCollapse={this.props.onCollapse}
                                 >
-                                    <SubMenu key="trial-case"
-                                             title={<span><Icon type="appstore" theme="twoTone"/><span>Trial Case</span></span>}>
-                                        <Menu.Item key="e-commerce"><Link
-                                            to="/graphql-service/trial-case/e-commerce">e-commerce</Link></Menu.Item>
-                                        <Menu.Item key="keep accounts"><Link
-                                            to="/graphql-service/trial-case/keep accounts">keep accounts</Link></Menu.Item>
-                                        <Menu.Item key="appointment"><Link
-                                            to="/graphql-service/trial-case/appointment">appointment</Link></Menu.Item>
-                                    </SubMenu>
-
-                                    <Menu.Item key="1"><Icon type="edit" theme="twoTone"/><span>Create</span>
-                                        <Icon type="plus" style={{
-                                            position: 'absolute',
-                                            top: '35%',
-                                            right: '6px',
-                                            color: 'white'
-                                        }}/>
-                                    </Menu.Item>
-
-                                    <SubMenu key="my-create" title={<span><Icon type="user"
-                                                                                theme="outlined"/><span>My Create</span></span>}>
-                                        {
-                                            data.schema_by_props.map((schema) => <Menu.Item key={schema.schemaName}><Link
-                                                to={`/graphql-service/my-create/${schema.schemaName}`}>{schema.schemaName}</Link></Menu.Item>)
-                                        }
-                                    </SubMenu>
-                                </Menu>
-                            </Sider>
-                        )
+                                    <Menu
+                                        theme="dark"
+                                        mode="inline"
+                                        inlineCollapsed={this.props.inlineCollapsed}
+                                        defaultSelectedKeys={['e-commerce']}
+                                        defaultOpenKeys={['trial-case', 'my-create']}
+                                        // openKeys={['cloud-function']}
+                                        onClick={(e) => this.props.switchMenu('sideBar', e)}
+                                        selectedKeys={[this.props.sideBar]}
+                                        style={{
+                                            borderRight: 0,
+                                            overflow: 'auto',
+                                            height: '100vh',
+                                            left: '0',
+                                            width: '200px',
+                                            position: 'fixed'
+                                        }}
+                                    >
+                                        <SubMenu key="trial-case"
+                                                 title={<span><Icon type="appstore"
+                                                                    theme="twoTone"/><span>Trial Case</span></span>}>
+                                            <Menu.Item key="e-commerce"><Link
+                                                to="/graphql-service/trial-case/e-commerce">e-commerce</Link></Menu.Item>
+                                            <Menu.Item key="keep accounts"><Link
+                                                to="/graphql-service/trial-case/keep accounts">keep
+                                                accounts</Link></Menu.Item>
+                                            <Menu.Item key="appointment"><Link
+                                                to="/graphql-service/trial-case/appointment">appointment</Link></Menu.Item>
+                                        </SubMenu>
+
+                                        <Menu.Item key="1"><Icon type="edit" theme="twoTone"/><span>Create</span>
+                                            <Icon type="plus" style={{
+                                                position: 'absolute',
+                                                top: '35%',
+                                                right: '6px',
+                                                color: 'white'
+                                            }}/>
+                                        </Menu.Item>
+
+                                        <SubMenu key="my-create" title={<span><Icon type="user"
+                                                                                    theme="outlined"/><span>My Create</span></span>}>
+                                            {
+                                                data.schema_by_props.map((schema) => <Menu.Item
+                                                    key={schema.schemaName}><Link
+                                                    to={`/graphql-service/my-create/${schema.schemaName}`}>{schema.schemaName}</Link></Menu.Item>)
+                                            }
+                                        </SubMenu>
+                                    </Menu>
+                                </Sider>
+                            )
 
 
                             // <div key={schema.schemaName} className='title'
@@ -328,10 +374,11 @@ class GraphqlSidebar extends Component {
                             // </div>
 
 
-
+                        }
                     }
-                }
-            </Query>
+                </Query>
+                :
+                ''
         )
     }
 }