frame.jsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @author oldj
  3. * @blog http://oldj.net
  4. */
  5. 'use strict'
  6. import React from 'react'
  7. import Agent from '../Agent'
  8. import './frame.less'
  9. export default class MyFrame extends React.Component {
  10. constructor (props) {
  11. super(props)
  12. }
  13. componentDidMount () {
  14. Agent.on('esc', () => {
  15. this.onCancel()
  16. })
  17. }
  18. onOK () {
  19. this.props.onOK()
  20. }
  21. onCancel () {
  22. this.props.onCancel()
  23. }
  24. renderFootButtons () {
  25. let html = []
  26. let {lang} = this.props
  27. html.push(
  28. <div
  29. className="button btn-cancel"
  30. key="btn-cancel"
  31. onClick={this.onCancel.bind(this)}
  32. >
  33. {this.props.cancel_title || lang.cancel}
  34. </div>
  35. )
  36. html.push(
  37. <div
  38. className="button btn-ok btn-default"
  39. key="btn-ok"
  40. onClick={this.onOK.bind(this)}
  41. >
  42. {this.props.ok_title || lang.ok}
  43. </div>
  44. )
  45. return html
  46. }
  47. render () {
  48. if (!this.props.show) {
  49. return null
  50. }
  51. return (
  52. <div className="frame" ref="frame">
  53. <div className="overlay"/>
  54. <div className="prompt">
  55. <div className="head">{this.props.head}</div>
  56. <div className="body">{this.props.body}</div>
  57. <div className="foot">{this.renderFootButtons()}</div>
  58. </div>
  59. </div>
  60. )
  61. }
  62. }