gateWay.jsx 2.64 KB
Newer Older
1 2 3 4 5
import React, { useEffect, useState } from 'react';
import { Card, Form, Switch, message, Divider, Row, Col, Spin } from 'antd';
import styles from './gateWay.less';
import { GetGateWay, UpdateGeteWay } from '@/services/platform/hostmanager';
import configuration from '../../../../assets/images/icons/消息.svg';
6 7

const GateConfig = () => {
8 9
  const [loading, setLoading] = useState(false); // 加载
  const [form] = Form.useForm();
10

11 12
  const [flag, setFlag] = useState(1);
  const [currentConfig, setCurrentConfig] = useState();
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  const OperateNginx = checked => {
    console.log(checked);
    UpdateGeteWay({ isUsed: checked }).then(res => {
      if (res.code === 0) {
        setFlag(flag + 1);
        message.success('设置成功');
      } else {
        message.error('设置失败');
      }
    });
  };
  useEffect(() => {
    if (currentConfig) {
      localStorage.setItem('panda-publish', 'getway');
    } else {
      localStorage.setItem('panda-publish', '');
30
    }
31
  }, [currentConfig]);
32

33 34 35 36 37 38 39 40 41
  useEffect(() => {
    GetGateWay().then(res => {
      if (res.code === 0) {
        setCurrentConfig(res.data);
        console.log(res.data);
        console.log(currentConfig);
      }
    });
  }, [flag]);
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
  return (
    <div className={styles.gateWay_container}>
      <Card style={{ width: '100%', height: 'calc(100vh - 130px)' }}>
        <Spin spinning={loading} tip="loading">
          <div
            style={{ display: 'flex', alignItems: 'center', marginTop: '40px' }}
          >
            <img src={configuration} style={{ height: '16px' }} alt="" />
            <span style={{ marginLeft: '10px', fontWeight: 'bold' }}>
              服务管理
            </span>
          </div>
          <Divider />
          <div className={styles.operate_container}>
            <Row
              gutter={[20, 25]}
              style={{ display: 'flex', alignItems: 'center' }}
            >
              <Col span={2}>
                <div
                  style={{
                    display: 'flex',
                    justifyContent: 'flex-end',
                    marginRight: '-10px',
                  }}
                >
                  服务运行
70
                </div>
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
              </Col>
              <Col span={22}>
                {console.log(currentConfig)}
                <Switch
                  checkedChildren="开启"
                  unCheckedChildren="关闭"
                  checked={currentConfig}
                  onChange={OperateNginx}
                  style={{ marginLeft: '30px' }}
                />
              </Col>
            </Row>
          </div>
        </Spin>
      </Card>
    </div>
  );
};
export default GateConfig;