Created
August 9, 2017 10:00
-
-
Save hzq1988a/675de9b5f6c2e85905eecb27df7ab680 to your computer and use it in GitHub Desktop.
函数包装方式的弹出框逻辑
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function (label = '加签'){ | |
let container = document.createElement('div') | |
document.body.appendChild(container) | |
let isDestroy = false; | |
var instance = null; | |
return new Promise(function(resolve, reject){ | |
function removeDom(){ | |
if(!isDestroy && instance){ | |
instance.setState({ | |
visible:false, | |
}) | |
ReactDom.unmountComponentAtNode(container) | |
container.parentNode.removeChild(container) | |
isDestroy = true; | |
} | |
} | |
function onOk(userCode){ | |
removeDom(); | |
resolve(userCode) | |
} | |
function onCancel(){ | |
removeDom(); | |
reject(); | |
} | |
ReactDom.render(<Dialog label={label} onOk={onOk} onCancel={onCancel}/>, container, function(){ | |
instance = this | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment