Pārlūkot izejas kodu

判断 user 是否已经填写 cloud

kulley 7 gadi atpakaļ
vecāks
revīzija
1c0ad7c210
1 mainītis faili ar 71 papildinājumiem un 11 dzēšanām
  1. 71 11
      src/app/basicVersion/exampleShow/ExampleShow.jsx

+ 71 - 11
src/app/basicVersion/exampleShow/ExampleShow.jsx

@@ -3,6 +3,9 @@ import {Layout, Card, notification, 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;
@@ -11,7 +14,9 @@ class ExampleShow extends Component {
     constructor(props) {
         super(props);
         this.state = {
-            userID: ''
+            userID: 'ioobot',
+            secretId: '',
+            secretKey: ''
         }
     }
 
@@ -20,16 +25,64 @@ class ExampleShow extends Component {
         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;
+                        }
+                    });
+                }
+            )
         }
     }
 
     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}
+            {
+                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
+            }
         ];
 
         let {userID} = this.state;
@@ -39,14 +92,21 @@ class ExampleShow extends Component {
                     <Card
                         key={index}
                         style={{width: 300}}
-                        cover={<div className='cover-div'><img className='cover-img' src={item.img} alt={item.title+''+item.description}/></div>}
+                        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={() => {
-                                if(userID) {
-                                    this.props.history.push({
-                                        pathname: `/common/deploy-cloud-choose`
-                                    })
+                                if (userID) {
+                                    if(this.state.secretId && this.state.secretKey) {
+                                        // 调用接口
+
+                                    } else {
+                                        // 跳转
+                                        this.props.history.push({
+                                            pathname: `/common/deploy-cloud-choose`
+                                        })
+                                    }
                                 } else {
                                     notification['warning']({
                                         message: '需要登录',