BlockDescWrap.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import React from 'react'
  2. import TextareaAutosize from 'react-autosize-textarea'
  3. import newEventActions from 'actions/newEvent'
  4. import newEventStores from 'stores/newEvent'
  5. import { getEventBlockByBid } from 'stores/funcs/newEvent'
  6. import { BLOCK_OP_TYPE } from 'const/const'
  7. import { shallowEqualImmutable } from 'utils/utils'
  8. export default class BlockDescWrap extends React.Component {
  9. constructor(props) {
  10. super(props)
  11. this.state = {
  12. desc: this.getDesc()
  13. }
  14. this.getDesc = this.getDesc.bind(this)
  15. this.onChange = this.onChange.bind(this)
  16. this.onBlur = this.onBlur.bind(this)
  17. }
  18. shouldComponentUpdate(nextProps, nextState) {
  19. return (
  20. !shallowEqualImmutable(this.props, nextProps) ||
  21. !shallowEqualImmutable(this.state, nextState)
  22. )
  23. }
  24. componentDidUpdate(preProps) {
  25. if (preProps.bid !== this.props.bid) {
  26. this.setState({
  27. desc: this.getDesc()
  28. })
  29. }
  30. }
  31. getDesc() {
  32. let result = ''
  33. let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  34. let block = getEventBlockByBid(this.props.bid, nodeId)
  35. if (block && block.type === BLOCK_OP_TYPE.BLOCK) {
  36. result = block.com || ''
  37. }
  38. return result
  39. }
  40. onChange(e) {
  41. let value = e && e.target ? e.target.value : e
  42. this.setState({
  43. desc: value
  44. })
  45. }
  46. onBlur() {
  47. if (this.getDesc() !== this.state.desc) {
  48. let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
  49. newEventActions.updateBlockProp({
  50. nodeId,
  51. blockId: this.props.bid,
  52. prop: 'com',
  53. value: this.state.desc
  54. })
  55. }
  56. }
  57. render() {
  58. let { desc } = this.state
  59. return (
  60. <div className="desc-wrap">
  61. {this.props.hasGroupExtraLine ? (
  62. <div className="group-desc-extra-line" />
  63. ) : null}
  64. <div className="input-wrap f--h">
  65. <button className="btn-clear btn-icon"/>
  66. <div className="input-area f--hlc">
  67. <TextareaAutosize
  68. value={desc || ''}
  69. placeholder={'分组详情'}
  70. onChange={this.onChange}
  71. onBlur={this.onBlur}
  72. className={'desc-textarea'}
  73. maxRows={4}
  74. async={true}
  75. />
  76. </div>
  77. </div>
  78. </div>
  79. )
  80. }
  81. }