Przeglądaj źródła

修改案例部分

Csy817 7 lat temu
rodzic
commit
889825e9ff

+ 84 - 86
src/components/app/App.jsx

@@ -18,8 +18,9 @@ import '../common/graphql/index.css';
 import './index.css'
 import './index.css'
 import Create from "../common/schema/Create";
 import Create from "../common/schema/Create";
 
 
-import {SHOW_SCHEMA} from "../gql";
+import {SHOW_ALL_SCHEMA} from "../gql";
 import axios from 'axios';
 import axios from 'axios';
+import {getCookie} from "../cookie";
 
 
 axios.defaults.withCredentials = true;
 axios.defaults.withCredentials = true;
 
 
@@ -255,8 +256,8 @@ class App extends Component {
                                 key={locale ? locale.locale : 'en'/* Have to refresh for production environment */}>
                                 key={locale ? locale.locale : 'en'/* Have to refresh for production environment */}>
                             <Switch>
                             <Switch>
                                 <Route path="/" exact component={TrialCase}/>
                                 <Route path="/" exact component={TrialCase}/>
-                                <Route path="/graphql-service/:sidebar/:caseId" component={TrialCase}/>
-                                <Route path="/wechat-service/:sidebar/:caseId" component={WechatService}/>
+                                <Route path="/graphql-service/:sidebar/:case" component={TrialCase}/>
+                                <Route path="/wechat-service/:sidebar/:case" component={WechatService}/>
                                 <Route path="/quant-service/" component={QuantService}/>
                                 <Route path="/quant-service/" component={QuantService}/>
                                 <Route path="/table/:name" component={Column}/>
                                 <Route path="/table/:name" component={Column}/>
                                 <Route path="/login" component={Login}/>
                                 <Route path="/login" component={Login}/>
@@ -276,102 +277,99 @@ class GraphqlSidebar extends Component {
     constructor(props) {
     constructor(props) {
         super(props);
         super(props);
         this.state = {
         this.state = {
-            getID_url: 'http://123.206.193.98:8999/getuserid',
-            userID: '',
+            // getID_url: 'http://123.206.193.98:8999/getuserid',
+            userID: getCookie('user_id'),
             show: false
             show: false
         }
         }
     }
     }
 
 
 
 
-    componentWillMount() {
-        let _this = this;
-        axios.get(this.state.getID_url)
-            .then((res) => {
-                if (res.data !== '') {
-                    _this.setState({
-                        userID: res.data,
-                        show: true
-                    })
-                } else {
-                    _this.setState({
-                        show: true
-                    })
-                }
-            })
-            .catch((err) => {
-                console.log(err);
-            });
-    }
+    // componentWillMount() {
+    //     let _this = this;
+    //     axios.get(this.state.getID_url)
+    //         .then((res) => {
+    //             if (res.data !== '') {
+    //                 _this.setState({
+    //                     userID: res.data,
+    //                     show: true
+    //                 })
+    //             } else {
+    //                 _this.setState({
+    //                     show: true
+    //                 })
+    //             }
+    //         })
+    //         .catch((err) => {
+    //             console.log(err);
+    //         });
+    // }
 
 
 
 
     render() {
     render() {
         console.log('userID',this.state.userID);
         console.log('userID',this.state.userID);
         return (
         return (
-            this.state.show ?
-                <Query query={gql(SHOW_SCHEMA)} variables={{user_id: this.state.userID}}>
-                    {
-                        ({loading, error, data}) => {
-                            console.log('schema data',data);
-                            if (loading) return <Spin style={{marginLeft: 3}}/>;
-                            if (error) return 'error!';
-                            return (
-                                <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>
+            <Query query={gql(SHOW_ALL_SCHEMA)} variables={{user_id: this.state.userID}}>
+                {
+                    ({loading, error, data}) => {
+                        console.log('user schema data',data);
+                        if (loading) return <Spin style={{marginLeft: 3}}/>;
+                        if (error) return 'error!';
+                        return (
+                            <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>}>
+                                    {
+                                        data.caseSchema.map((schema) =>
+                                            <Menu.Item key={schema.schemaName}>
+                                                <Link to={`/graphql-service/trial-case/${schema.schemaName}?id=${schema.id}`}>{schema.schemaName}</Link>
+                                            </Menu.Item>)
+                                    }
+                                </SubMenu>
 
 
-                                    <Menu.Item key="create-graphql" onClick={this.props.showModal}>
-                                        <Icon type="edit" theme="twoTone"/>
-                                        <span>Create</span>
-                                        <Icon type="plus" style={{
-                                            position: 'absolute',
-                                            top: '35%',
-                                            right: '6px',
-                                            color: 'white'
-                                        }}/>
-                                    </Menu.Item>
+                                <Menu.Item key="create-graphql" onClick={this.props.showModal}>
+                                    <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.id}`}>{schema.schemaName}</Link></Menu.Item>)
-                                        }
-                                    </SubMenu>
-                                </Menu>
+                                <SubMenu key="my-create" title={<span><Icon type="user" theme="outlined"/><span>My Create</span></span>}>
+                                    {
+                                        data.userSchema.map((schema) =>
+                                            <Menu.Item key={schema.schemaName}>
+                                                <Link to={`/graphql-service/my-create/${schema.schemaName}?id=${schema.id}`}>{schema.schemaName}</Link>
+                                            </Menu.Item>)
+                                    }
+                                </SubMenu>
+                            </Menu>
 
 
-                            )
-                        }
+                        )
                     }
                     }
-                </Query>
-                :
-                ''
+                }
+            </Query>
         )
         )
     }
     }
-}
+}
+
+// this.state.show ?
+// :''

+ 0 - 8
src/components/common/schema/Schema.jsx

@@ -7,14 +7,6 @@ import gql from "graphql-tag";
 import {SHOW_SCHEMA, DELETE_SCHEMA, SHOW_TABLE} from '../../gql'
 import {SHOW_SCHEMA, DELETE_SCHEMA, SHOW_TABLE} from '../../gql'
 import Table from "./Table";
 import Table from "./Table";
 
 
-
-const Search = Input.Search;
-
-const idGen = (kind) => {
-    return kind + '_' + Date.now() + '_' + Math.random().toString().slice(-8);
-};
-
-
 class Schema extends Component {
 class Schema extends Component {
     constructor(props) {
     constructor(props) {
         super(props);
         super(props);

+ 16 - 0
src/components/gql.js

@@ -60,6 +60,21 @@ const SHOW_SCHEMA = `
             }
             }
         `;
         `;
 
 
+const SHOW_ALL_SCHEMA = `
+            query SCHEMA($user_id: ID) {
+                userSchema:schema_by_props(user_id: $user_id) {
+                    schemaData
+                    schemaName
+                    id
+                }
+                caseSchema:schema_by_props(user_id: "ioobot") {
+                    schemaData
+                    schemaName
+                    id
+                }
+            }
+        `;
+
 const SEARCH_SCHEMA = `
 const SEARCH_SCHEMA = `
             query SCHEMA($id: ID!) {
             query SCHEMA($id: ID!) {
                 schema_by_id(id: $id) {
                 schema_by_id(id: $id) {
@@ -346,6 +361,7 @@ export {
     SEARCH_USER,
     SEARCH_USER,
     SEARCH_SCHEMA,
     SEARCH_SCHEMA,
     ADD_SCHEMA,
     ADD_SCHEMA,
+    SHOW_ALL_SCHEMA,
     SHOW_SCHEMA,
     SHOW_SCHEMA,
     UPDATE_SCHEMA,
     UPDATE_SCHEMA,
     DELETE_SCHEMA,
     DELETE_SCHEMA,

+ 7 - 31
src/components/trialCase/TrialCase.jsx

@@ -8,26 +8,21 @@ import Graphql from "../common/graphql/Graphql";
 import CaseMetabase from "../common/caseMetabase/CaseMetabase";
 import CaseMetabase from "../common/caseMetabase/CaseMetabase";
 import axios from 'axios';
 import axios from 'axios';
 
 
-
 axios.defaults.withCredentials = true;
 axios.defaults.withCredentials = true;
 
 
 const {Content} = Layout;
 const {Content} = Layout;
 
 
-
 class TrialCase extends Component {
 class TrialCase extends Component {
-    constructor() {
-        super();
-
+    constructor(props) {
+        super(props);
         this.state = {
         this.state = {
             menuLevel2: "schema",
             menuLevel2: "schema",
             // default user
             // default user
-            userID: 'ioobot',
+            userID: "ioobot",
             getID_url: 'http://123.206.193.98:8999/getuserid',
             getID_url: 'http://123.206.193.98:8999/getuserid',
-            schemaID: ''
         }
         }
     }
     }
 
 
-
     componentWillMount() {
     componentWillMount() {
         let _this = this;
         let _this = this;
         axios.get(this.state.getID_url)
         axios.get(this.state.getID_url)
@@ -43,27 +38,6 @@ class TrialCase extends Component {
             });
             });
     }
     }
 
 
-    componentWillReceiveProps(nextProps) {
-        let schemaID;
-        switch (nextProps.match.params.caseId) {
-            case 'e-commerce':
-                schemaID = 'schema_1542243424669_92094965';
-                break;
-            case 'keep-accounts':
-                schemaID = 'schema_1542257622953_79276889';
-                break;
-            case 'appointment':
-                schemaID = 'schema_1542246903496_97115305';
-                break;
-            default:
-                schemaID = nextProps.match.params.caseId || 'schema_1542243424669_92094965';
-        }
-        this.setState({
-            schemaID
-        });
-    }
-
-
     switchMenu = (menuName, e) => {
     switchMenu = (menuName, e) => {
         // console.log('menuName', menuName, 'e', e);
         // console.log('menuName', menuName, 'e', e);
         this.setState({
         this.setState({
@@ -73,6 +47,8 @@ class TrialCase extends Component {
 
 
 
 
     render() {
     render() {
+        let schemaID = this.props.location.search.substr(this.props.location.search.indexOf("=")+1) || "schema_1542243424669_92094965";
+        console.log('schemaID',schemaID);
         return (
         return (
             <div>
             <div>
                 <Menu
                 <Menu
@@ -96,9 +72,9 @@ class TrialCase extends Component {
                             (() => {
                             (() => {
                                 switch (this.state.menuLevel2) {
                                 switch (this.state.menuLevel2) {
                                     case 'schema':
                                     case 'schema':
-                                        return <Schema userID={this.state.userID} schemaID={this.state.schemaID}/>;
+                                        return <Schema userID={this.state.userID} schemaID={schemaID}/>;
                                     case 'deploy':
                                     case 'deploy':
-                                        return <Deploy userID={this.state.userID} schemaID={this.state.schemaID}/>;
+                                        return <Deploy userID={this.state.userID} schemaID={schemaID}/>;
                                     case 'graphql':
                                     case 'graphql':
                                         return <GenerateJs/>;
                                         return <GenerateJs/>;
                                     case 'graphiql':
                                     case 'graphiql':