/** * The panel to edit the filter * */ import React, { PropTypes } from 'react'; import ReactDOM from 'react-dom'; import ClassBind from 'classnames/bind'; import { connect } from 'react-redux'; import { message, Button, Spin } from 'antd'; import ResizablePanel from 'component/resizable-panel'; import { hideRootCA, updateIsRootCAExists } from 'action/globalStatusAction'; import { MenuKeyMap } from 'common/Constant'; import { getJSON, ajaxGet, postJSON } from 'common/ApiUtil'; import Style from './download-root-ca.less'; import CommonStyle from '../style/common.less'; class DownloadRootCA extends React.Component { constructor () { super(); this.state = { loadingCAQr: false, generatingCA: false }; this.onClose = this.onClose.bind(this); this.getQrCodeContent = this.getQrCodeContent.bind(this); } static propTypes = { dispatch: PropTypes.func, globalStatus: PropTypes.object } fetchData () { this.setState({ loadingCAQr: true }); getJSON('/api/getQrCode') .then((response) => { this.setState({ loadingCAQr: false, CAQrCodeImageDom: response.qrImgDom, isRootCAFileExists: response.isRootCAFileExists, url: response.url }); }) .catch((error) => { console.error(error); message.error(error.errorMsg || 'Failed to get the QR code of RootCA path.'); }); } onClose () { this.props.dispatch(hideRootCA()); } getQrCodeContent () { const imgDomContent = { __html: this.state.CAQrCodeImageDom }; const content = (
Scan to download rootCA to your Phone
); const spin = ; return this.state.loadingCAQr ? spin : content; } getGenerateRootCADiv () { const doToggleRemoteIntercept = () => { postJSON('/api/generateRootCA') .then((result) => { this.setState({ generateRootCA: false, isRootCAFileExists: true }); this.props.dispatch(updateIsRootCAExists(true)); }) .catch((error) => { this.setState({ generatingCA: false }); message.error('生成根证书失败,请重试'); }); }; return (
RootCA
Your RootCA has not been generated yet, please click the button to generate before you download it. Please install and trust the generated RootCA.
); } getDownloadDiv () { return (
RootCA
{this.getQrCodeContent()}
Or click the button to download.
); } componentDidMount () { this.fetchData(); } render() { const panelVisible = this.props.globalStatus.activeMenuKey === MenuKeyMap.ROOT_CA; return ( {this.props.globalStatus.isRootCAFileExists ? this.getDownloadDiv() : this.getGenerateRootCADiv()} ); } } function select (state) { return { globalStatus: state.globalStatus }; } export default connect(select)(DownloadRootCA);