diff --git a/client/Application.js b/client/Application.js index d095a99e..09ed662f 100755 --- a/client/Application.js +++ b/client/Application.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import ReactDOM from 'react-dom'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Route, BrowserRouter as Router } from 'react-router-dom'; @@ -7,6 +8,7 @@ import User from './containers/User/User.js'; import Header from './components/Header/Header'; import Footer from './components/Footer/Footer'; import Loading from './components/Loading/Loading'; +import MyPopConfirm from './components/MyPopConfirm/MyPopConfirm'; import { checkLoginState } from './reducer/modules/user'; import { requireAuthentication } from './components/AuthenticatedComponent'; @@ -46,7 +48,13 @@ export default class App extends Component { return ; } else { r = ( - + { + let container = document.createElement('div'); + document.body.appendChild(container); + ReactDOM.render(( + + ), container); + }}> {this.props.loginState !== 1 ? : null} diff --git a/client/components/MyPopConfirm/MyPopConfirm.js b/client/components/MyPopConfirm/MyPopConfirm.js new file mode 100644 index 00000000..30287f04 --- /dev/null +++ b/client/components/MyPopConfirm/MyPopConfirm.js @@ -0,0 +1,50 @@ +import React, { Component } from 'react'; +import { Modal, Button } from 'antd'; +import PropTypes from 'prop-types'; + +// 嵌入到 BrowserRouter 内部,覆盖掉默认的 window.confirm +// http://reacttraining.cn/web/api/BrowserRouter/getUserConfirmation-func +class MyPopConfirm extends Component { + constructor(props) { + super(props); + this.state = { + visible: true + }; + } + static propTypes = { + msg: PropTypes.string, + callback: PropTypes.func + }; + + yes = () => { + this.props.callback(true); + this.setState({ visible: false }); + } + + no = () => { + this.props.callback(false); + this.setState({ visible: false }); + } + + componentWillReceiveProps() { + this.setState({ visible: true }); + } + + render() { + if (!this.state.visible) { + return null; + } + return (取 消, + 确 定 + ]} + > + {this.props.msg} + ); + } +} + +export default MyPopConfirm; diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceContent.js b/client/containers/Project/Interface/InterfaceList/InterfaceContent.js index c44caa51..26715588 100755 --- a/client/containers/Project/Interface/InterfaceList/InterfaceContent.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceContent.js @@ -135,7 +135,8 @@ class Content extends Component { { - this.showModal(); + // this.showModal(); + console.log('e'); return '离开页面会丢失当前编辑的内容,确定要离开吗?'; }} />
{this.props.msg}