xy преди 7 години
родител
ревизия
16def0d7ae
променени са 4 файла, в които са добавени 167 реда и са изтрити 50 реда
  1. 15 0
      src/app/graphqlService/TrialCase.jsx
  2. 116 42
      src/app/graphqlService/component/schema/Schema.jsx
  3. 32 7
      src/app/graphqlService/component/schema/Table.js
  4. 4 1
      src/config.js

+ 15 - 0
src/app/graphqlService/TrialCase.jsx

@@ -8,6 +8,7 @@ import Graphql from "./component/graphql/Graphql";
 import CaseMetabase from "./component/caseMetabase/CaseMetabase";
 import Application from "./component/application/Application";
 import axios from 'axios';
+import {getIdUrl} from "../../config";
 
 axios.defaults.withCredentials = true;
 
@@ -29,6 +30,20 @@ class TrialCase extends Component {
         });
     };
 
+    componentWillMount() {
+        let _this = this;
+        axios.get(getIdUrl)
+            .then((res) => {
+                if (res.data !== '') {
+                    _this.setState({
+                        userID: res.data
+                    })
+                }
+            })
+            .catch(function (err) {
+                console.log(err);
+            });
+    }
 
     render() {
         let schemaID = this.props.history.location.state ? this.props.history.location.state.schemaID : "ecommerce_schemaID";

+ 116 - 42
src/app/graphqlService/component/schema/Schema.jsx

@@ -18,6 +18,7 @@ import {request} from 'graphql-request'
 import {getCookie} from "../../../../cookie";
 import {idGen} from "../../../../func";
 import {graphqlUrl} from "../../../../config";
+import {manageUsers} from "../../../../config";
 
 const confirm = Modal.confirm;
 const Search = Input.Search;
@@ -40,7 +41,7 @@ class Schema extends Component {
         };
     }
 
-    shouldComponentUpdate(nextProps,nextState) {
+    shouldComponentUpdate(nextProps, nextState) {
         return true;
     }
 
@@ -111,11 +112,10 @@ class Schema extends Component {
             return new Promise((resolve, reject) => {
                 request(graphqlUrl, SEARCH_SCHEMA, {id: referenceID}).then(
                     data => {
-                        console.log(data);
                         if (data.schema_by_id !== null) {
-                            localStorage.setItem('ecommerce', data.caseSchema.find(obj=>obj.schemaName==='ecommerce').schemaData);
-                            localStorage.setItem('subscribe', data.caseSchema.find(obj=>obj.schemaName==='subscribe').schemaData);
-                            localStorage.setItem('bills', data.caseSchema.find(obj=>obj.schemaName==='bills').schemaData);
+                            localStorage.setItem('ecommerce', data.caseSchema.find(obj => obj.schemaName === 'ecommerce').schemaData);
+                            localStorage.setItem('subscribe', data.caseSchema.find(obj => obj.schemaName === 'subscribe').schemaData);
+                            localStorage.setItem('bills', data.caseSchema.find(obj => obj.schemaName === 'bills').schemaData);
                             resolve(data.schema_by_id.schemaData);
                         }
                     }
@@ -126,9 +126,9 @@ class Schema extends Component {
     };
 
     receiveDataFromTable = (data) => {
-      this.setState({
-          data
-      })
+        this.setState({
+            data
+        })
     };
 
     componentWillReceiveProps(next) {
@@ -156,14 +156,12 @@ class Schema extends Component {
                             return 'error!';
                         }
 
-                        // let schemaName = data.schema_by_id.schemaName;
-
                         let copy;
-                        if(this.props.location.state)
+                        if (this.props.location.state)
                             copy = this.props.location.state.copy;
 
                         // 找到 copy 一定几率不显示的 问题原因,异步导致的未存先取
-                        if (data.schema_by_id === null && copy!==true) data = [];
+                        if (data.schema_by_id === null && copy !== true) data = [];
                         else {
                             let reference = data.schema_by_id ? data.schema_by_id.reference : this.props.location.state.reference;
                             data = data.schema_by_id ? JSON.parse(data.schema_by_id.schemaData) : [];
@@ -200,9 +198,7 @@ class Schema extends Component {
                                                     <div className={'schema'}>
                                                         <span className={'schema-name'}>{this.state.schemaName}</span>
                                                         {
-                                                            trialcase ?
-                                                                ''
-                                                                :
+                                                            userID.indexOf(manageUsers) > -1 ?
                                                                 <Icon style={{marginLeft: 15}}
                                                                       type="edit"
                                                                       theme="twoTone"
@@ -212,6 +208,19 @@ class Schema extends Component {
                                                                           }
                                                                       }
                                                                 />
+                                                                :
+                                                                trialcase ?
+                                                                    ''
+                                                                    :
+                                                                    <Icon style={{marginLeft: 15}}
+                                                                          type="edit"
+                                                                          theme="twoTone"
+                                                                          onClick={
+                                                                              () => {
+                                                                                  this.setState({editSchemaName: this.state.schemaName})
+                                                                              }
+                                                                          }
+                                                                    />
                                                         }
                                                     </div>
                                             }
@@ -224,9 +233,7 @@ class Schema extends Component {
                                                         className={'schema-table-title'}>Remark</span></Col>
                                                     <Col span={2} offset={2}>
                                                         {
-                                                            trialcase ?
-                                                                ''
-                                                                :
+                                                            userID.indexOf(manageUsers) > -1 ?
                                                                 <span
                                                                     className={'schema-table-title'}
                                                                     onClick={() => {
@@ -236,6 +243,19 @@ class Schema extends Component {
                                                                     }}>
                                                                     <Icon type="plus"/>
                                                                 </span>
+                                                                :
+                                                                trialcase ?
+                                                                    ''
+                                                                    :
+                                                                    <span
+                                                                        className={'schema-table-title'}
+                                                                        onClick={() => {
+                                                                            this.setState({
+                                                                                currentTable: 'add'
+                                                                            })
+                                                                        }}>
+                                                                    <Icon type="plus"/>
+                                                                </span>
                                                         }
 
                                                     </Col>
@@ -263,9 +283,7 @@ class Schema extends Component {
 
                                                                         <span className={'schema-table-content'}>
                                                                             {
-                                                                                trialcase ?
-                                                                                    ''
-                                                                                    :
+                                                                                userID.indexOf(manageUsers) > -1 ?
                                                                                     <DeleteTableButton
                                                                                         currentTable={table.name}
                                                                                         schemaData={data}
@@ -277,8 +295,22 @@ class Schema extends Component {
                                                                                         fetchData={this.fetchData}
                                                                                         location={this.props.location}
                                                                                     />
+                                                                                    :
+                                                                                    trialcase ?
+                                                                                        ''
+                                                                                        :
+                                                                                        <DeleteTableButton
+                                                                                            currentTable={table.name}
+                                                                                            schemaData={data}
+                                                                                            schemaID={this.state.schemaID}
+                                                                                            userID={userID}
+                                                                                            showTablePagination={this.showTablePagination}
+                                                                                            page={this.state.page}
+                                                                                            pageSize={this.state.pageSize}
+                                                                                            fetchData={this.fetchData}
+                                                                                            location={this.props.location}
+                                                                                        />
                                                                             }
-
                                                                         </span>
                                                                     </Col>
                                                                 </Row>
@@ -303,9 +335,7 @@ class Schema extends Component {
                                                                     <Col span={2} offset={2}>
                                                                 <span className={'schema-table-content'}>
                                                                     {
-                                                                        trialcase ?
-                                                                            ''
-                                                                            :
+                                                                        userID.indexOf(manageUsers) > -1 ?
                                                                             <DeleteTableButton
                                                                                 currentTable={table.name}
                                                                                 schemaData={data}
@@ -317,6 +347,21 @@ class Schema extends Component {
                                                                                 fetchData={this.fetchData}
                                                                                 location={this.props.location}
                                                                             />
+                                                                            :
+                                                                            trialcase ?
+                                                                                ''
+                                                                                :
+                                                                                <DeleteTableButton
+                                                                                    currentTable={table.name}
+                                                                                    schemaData={data}
+                                                                                    schemaID={this.state.schemaID}
+                                                                                    showTablePagination={this.showTablePagination}
+                                                                                    page={this.state.page}
+                                                                                    pageSize={this.state.pageSize}
+                                                                                    userID={userID}
+                                                                                    fetchData={this.fetchData}
+                                                                                    location={this.props.location}
+                                                                                />
                                                                     }
                                                                 </span>
                                                                     </Col>
@@ -330,22 +375,51 @@ class Schema extends Component {
                                                 <Row>
                                                     <Col span={4}>
                                                         {
-                                                            trialcase ?
-                                                                <div className={'delete-schema'}>
-                                                                    <CopySchemaButton
-                                                                        userID={userID}
-                                                                        history={this.props.history}
-                                                                        schemaName={this.state.schemaName}
-                                                                    />
-                                                                </div>
+                                                            userID.indexOf(manageUsers) > -1 ?
+                                                                trialcase ?
+                                                                    <div>
+                                                                        <div style={{display: 'inline-block'}}
+                                                                             className={'delete-schema'}>
+                                                                            <CopySchemaButton
+                                                                                userID={userID}
+                                                                                history={this.props.history}
+                                                                                schemaName={this.state.schemaName}
+                                                                            />
+                                                                        </div>
+                                                                        <div style={{display: 'inline-block'}}
+                                                                             className={'delete-schema'}>
+                                                                            <DeleteSchemaButton
+                                                                                userID={userID}
+                                                                                schemaName={this.state.schemaName}
+                                                                                history={this.props.history}
+                                                                            />
+                                                                        </div>
+                                                                    </div>
+                                                                    :
+                                                                    <div className={'delete-schema'}>
+                                                                        <DeleteSchemaButton
+                                                                            userID={userID}
+                                                                            schemaName={this.state.schemaName}
+                                                                            history={this.props.history}
+                                                                        />
+                                                                    </div>
                                                                 :
-                                                                <div className={'delete-schema'}>
-                                                                    <DeleteSchemaButton
-                                                                        userID={userID}
-                                                                        schemaName={this.state.schemaName}
-                                                                        history={this.props.history}
-                                                                    />
-                                                                </div>
+                                                                trialcase ?
+                                                                    <div className={'delete-schema'}>
+                                                                        <CopySchemaButton
+                                                                            userID={userID}
+                                                                            history={this.props.history}
+                                                                            schemaName={this.state.schemaName}
+                                                                        />
+                                                                    </div>
+                                                                    :
+                                                                    <div className={'delete-schema'}>
+                                                                        <DeleteSchemaButton
+                                                                            userID={userID}
+                                                                            schemaName={this.state.schemaName}
+                                                                            history={this.props.history}
+                                                                        />
+                                                                    </div>
                                                         }
                                                     </Col>
                                                     <Col span={4} offset={16}>
@@ -387,8 +461,8 @@ class Schema extends Component {
                                             <Table
                                                 currentTable={this.state.currentTable}
                                                 schemaData={data}
-                                                columns={this.findColumns(data.length !== 0? data : this.state.data)}
-                                                remark={this.findRemark(data.length !== 0? data : this.state.data)}
+                                                columns={this.findColumns(data.length !== 0 ? data : this.state.data)}
+                                                remark={this.findRemark(data.length !== 0 ? data : this.state.data)}
                                                 schemaID={this.state.schemaID}
                                                 schemaName={this.state.schemaName}
                                                 userID={userID}

+ 32 - 7
src/app/graphqlService/component/schema/Table.js

@@ -6,6 +6,7 @@ import gql from "graphql-tag";
 
 import {Mutation, Query} from "react-apollo";
 import {getCookie} from "../../../../cookie";
+import {manageUsers} from "../../../../config";
 
 const Option = Select.Option;
 const {Content} = Layout;
@@ -178,16 +179,21 @@ class Table extends Component {
                                             onChange={this.handleDescChange(index)}>
                                             {
                                                 this.state.descriptions.map((value) =>
-                                                    <Option key={Math.random() + 'descriptions'} value={value.toLowerCase()}>{value}</Option>
+                                                    <Option key={Math.random() + 'descriptions'}
+                                                            value={value.toLowerCase()}>{value}</Option>
                                                 )
                                             }
                                         </Select>
                                         {
-                                            trialcase ?
-                                                ''
-                                                :
+                                            userID.indexOf(manageUsers) > -1 ?
                                                 <Icon type="delete" theme="twoTone" style={{cursor: 'pointer'}}
                                                       onClick={this.handleColDelete(index)}/>
+                                                :
+                                                trialcase ?
+                                                    ''
+                                                    :
+                                                    <Icon type="delete" theme="twoTone" style={{cursor: 'pointer'}}
+                                                          onClick={this.handleColDelete(index)}/>
                                         }
                                     </div>
                                 )
@@ -214,9 +220,7 @@ class Table extends Component {
                         </div>
 
                         {
-                            trialcase ?
-                                ''
-                                :
+                            userID.indexOf(manageUsers) > -1 ?
                                 <div style={{marginTop: 20}}>
                                     <UpdateTableButton
                                         currentTable={this.state.currentTable}
@@ -234,6 +238,27 @@ class Table extends Component {
                                         add={this.props.add}
                                     />
                                 </div>
+                                :
+                                trialcase ?
+                                    ''
+                                    :
+                                    <div style={{marginTop: 20}}>
+                                        <UpdateTableButton
+                                            currentTable={this.state.currentTable}
+                                            columns={this.state.columns}
+                                            remark={this.state.remark}
+                                            schemaID={schemaID}
+                                            userID={userID}
+                                            schemaData={this.props.schemaData}
+                                            fetchData={this.props.fetchData}
+                                            showTablePagination={this.props.showTablePagination}
+                                            page={this.props.page}
+                                            pageSize={this.props.pageSize}
+                                            history={this.props.history}
+                                            schemaName={schemaName}
+                                            add={this.props.add}
+                                        />
+                                    </div>
                         }
 
                     </Content>

+ 4 - 1
src/config.js

@@ -13,4 +13,7 @@ const getIdUrl = backend + '/getuserid';
 const loginUrl = backend +  '/login';
 const registerUrl = backend + '/resetpassword';
 
-export {requestUrl, getIdUrl, loginUrl, registerUrl, graphqlUrl}
+// 管理员配置
+const manageUsers = ['xy_1_je9{d\'\'_32sD+'];
+
+export {requestUrl, getIdUrl, loginUrl, registerUrl, graphqlUrl, manageUsers}