Skip to content

Instantly share code, notes, and snippets.

@hzq1988a
Created August 9, 2017 10:00
Show Gist options
  • Save hzq1988a/675de9b5f6c2e85905eecb27df7ab680 to your computer and use it in GitHub Desktop.
Save hzq1988a/675de9b5f6c2e85905eecb27df7ab680 to your computer and use it in GitHub Desktop.
函数包装方式的弹出框逻辑
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