Browse Source

修改登录顺序

kulley 7 năm trước cách đây
mục cha
commit
d98adb8de6

+ 60 - 5
src/app/basicVersion/exampleShow/DeployCloudChoose.js

@@ -1,18 +1,58 @@
 import React, {Component} from 'react';
-
-import {Layout, Button} from 'antd';
-
+import {Layout, Button, notification} from 'antd';
+import {getCookie} from "../../../cookie";
+import {graphqlUrl} from "../../../config";
+import {SHOW_CLOUD} from "../../../gql";
+import {request} from 'graphql-request'
 const {Content} = Layout;
 
 class DeployCloudChoose extends Component{
     constructor(){
         super();
         this.state={
+            userID: 'demo',
+            secretId: '',
+            secretKey: '',
+            appId: ''
+        }
+    }
+
+    componentWillMount() {
+        let userID = getCookie('user_id') || this.state.userID;
+        if (userID !== undefined && userID !== '') {
+            this.setState({
+                userID
+            });
 
+            // 查询是否设置 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':
+                                this.setState({
+                                    secretId: cloud.secretId,
+                                    secretKey: cloud.secretKey,
+                                    appId: cloud.appId
+                                });
+                                break;
+                            case 'aliyun':
+                                // 没写
+                                break;
+                            case 'amazon':
+                                // 没写
+                                break;
+                            default:
+                                break;
+                        }
+                    });
+                }
+            )
         }
     }
 
     render(){
+        let {userID} = this.state;
         return(
             <div className={'deploy-choose-cloud'}>
                 <Layout style={{ padding: '24px',minHeight:'300px' }}>
@@ -24,8 +64,23 @@ class DeployCloudChoose extends Component{
                             <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'>系统默认部署</Button>
-                            <Button className={'choose-cloud-button'} type='primary'>自定义参数设置</Button>
+                            <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: '后续使用,需要先登录',
+                                    });
+
+                                    this.props.history.push({
+                                        pathname: `/login`
+                                    })
+                                } else {
+                                    console.log('已经登录')
+                                }
+                            }}>自定义参数设置</Button>
                         </div>
                     </Content>
                 </Layout>

+ 5 - 63
src/app/basicVersion/exampleShow/ExampleShow.jsx

@@ -1,11 +1,7 @@
 import React, {Component} from 'react';
-import {Layout, Card, notification, Button, Avatar} from 'antd';
+import {Layout, Card, Button, Avatar} from 'antd';
 import lo from '../../../images/lo.png'
 import './index.css'
-import {getCookie} from "../../../cookie";
-import {SHOW_CLOUD} from '../../../gql';
-import {request} from 'graphql-request'
-import {graphqlUrl} from "../../../config";
 
 const {Content} = Layout;
 const {Meta} = Card;
@@ -13,44 +9,7 @@ const {Meta} = Card;
 class ExampleShow extends Component {
     constructor(props) {
         super(props);
-        this.state = {
-            userID: 'ioobot',
-            secretId: '',
-            secretKey: ''
-        }
-    }
-
-    componentWillMount() {
-        let userID = getCookie('user_id');
-        if (userID !== undefined && userID !== '') {
-            this.setState({
-                userID
-            });
-
-            // 查询是否设置 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':
-                                this.setState({
-                                    secretId: cloud.secretId,
-                                    secretKey: cloud.secretKey
-                                });
-                                break;
-                            case 'aliyun':
-                                // 没写
-                                break;
-                            case 'amazon':
-                                // 没写
-                                break;
-                            default:
-                                break;
-                        }
-                    });
-                }
-            )
-        }
+        this.state = {}
     }
 
     renderCard = () => {
@@ -97,26 +56,9 @@ class ExampleShow extends Component {
                         actions={[
                             <span>已部署: {item.deployedNum}</span>,
                             <Button type="primary" onClick={() => {
-                                if (userID) {
-                                    if(this.state.secretId && this.state.secretKey) {
-                                        // 调用接口
-
-                                    } else {
-                                        // 跳转
-                                        this.props.history.push({
-                                            pathname: `/common/deploy-cloud-choose`
-                                        })
-                                    }
-                                } else {
-                                    notification['warning']({
-                                        message: '需要登录',
-                                        description: '后续使用,需要先登录',
-                                    });
-
-                                    this.props.history.push({
-                                        pathname: `/login`
-                                    })
-                                }
+                                this.props.history.push({
+                                    pathname: `/common/deploy-cloud-choose`
+                                });
                             }}>部署</Button>
                         ]}
                     >