CommonDialog.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Created by Jacky.gao on 2016/5/27.
  3. */
  4. import React,{Component,PropTypes} from 'react';
  5. import ReactDOM from 'react-dom';
  6. export default class CommonDialog extends Component{
  7. componentDidMount(){
  8. const $dom=$(ReactDOM.findDOMNode(this));
  9. $dom.on('show.bs.modal',function () {
  10. let zIndex=1050;
  11. $(document).find('.modal').each(function (index,modal) {
  12. const zindex=$(modal).css('z-index');
  13. if(zindex && zindex!=='' && !isNaN(zindex)){
  14. const z=parseInt(zindex);
  15. if(z>zIndex){
  16. zIndex=z;
  17. }
  18. }
  19. });
  20. $dom.css('z-index',zIndex+1);
  21. });
  22. }
  23. render(){
  24. const buttons=[];
  25. this.props.buttons.forEach((btn,index)=>{
  26. buttons.push(<button type="button" key={index} className={btn.className} onClick={(e)=>{
  27. btn.click(this.props.dispatch);
  28. }}><i className={btn.icon}></i> {btn.name}</button>)
  29. });
  30. const large=this.props.large;
  31. const className='modal-dialog'+ (large ? ' modal-lg' : '');
  32. return (
  33. <div className='modal fade' tabIndex="-1" role="dialog" aria-hidden="true" style={{'overflow':'auto'}}>
  34. <div className={className}>
  35. <div className="modal-content">
  36. <div className="modal-header">
  37. <button type="button" className="close" data-dismiss="modal" aria-hidden="true">
  38. &times;
  39. </button>
  40. <h5 className="modal-title" id="myModalLabel">
  41. {this.props.title}
  42. <div className="text-danger" style={{fontSize:'12pt'}}>{this.props.info ? this.props.info : null}</div>
  43. </h5>
  44. </div>
  45. <div className="modal-body" style={{padding:'10px'}}>
  46. {this.props.body}
  47. </div>
  48. <div className="modal-footer">
  49. {buttons}
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. );
  55. }
  56. };