BlockGroup.jsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import React from 'react'
  2. import LazyLoad from 'react-lazyload'
  3. import cls from 'classnames'
  4. import Block from './base/Block'
  5. import BlockChildren from './base/BlockChildren'
  6. import BlockOrder from './base/BlockOrder'
  7. import BlockDel from './base/BlockDel'
  8. import BlockDescWrap from './base/group/BlockDescWrap'
  9. import BlockEnable from './base/BlockEnable'
  10. export default class BlockGroup extends Block {
  11. constructor(props) {
  12. super(props)
  13. }
  14. render() {
  15. let jengaContent = document.getElementsByClassName('jenga-content')[0]
  16. let getRelChildComs = () => {
  17. return this.state.hasChildren ? (
  18. <div className="f--h">
  19. <div
  20. className={cls(
  21. 'btn-clear btn-toggle-sub btn-toggle-sub-empty',
  22. 'btn-toggle-sub-empty-' + this.getLineColor(),
  23. 'btn-toggle-sub-empty-small'
  24. )}
  25. style={{ marginTop: '9px' }}
  26. />
  27. <button
  28. className={cls('btn-clear btn-toggle-sub btn-toggle-group f--hcc')}
  29. onClick={this.onToggleBlockExpand}
  30. >
  31. <div className={cls('icon', { collpase: !this.state.isExpand })} />
  32. </button>
  33. </div>
  34. ) : (
  35. <div
  36. className={cls(
  37. 'btn-clear btn-toggle-sub btn-toggle-sub-empty',
  38. 'btn-toggle-sub-empty-' + this.getLineColor()
  39. )}
  40. />
  41. )
  42. }
  43. let extraLineCom = () => {
  44. return (
  45. this.state.isExpand &&
  46. this.state.hasChildren && (
  47. <div
  48. style={{
  49. left: -this.getGapLeft() + 'px',
  50. marginLeft: this.getGapLeft() - 1 + 'px'
  51. }}
  52. className={cls(
  53. 'index-line',
  54. 'index-extra-children',
  55. 'index-line-' + this.getLineColor()
  56. )}
  57. />
  58. )
  59. )
  60. }
  61. return (
  62. <LazyLoad height={26} overflow={true} scrollContainer={jengaContent}>
  63. <div
  64. className={cls(
  65. 'block-wrap block-wrap-group f--h',
  66. `block-wrap-group-${this.getGroupColor()}`
  67. )}
  68. >
  69. <span
  70. className={cls('index-line', 'index-line-' + this.getLineColor(), {
  71. 'index-last-line': this.props.isLast,
  72. 'index-virtual-layer': this.props.virtualLayer
  73. })}
  74. style={this.indexLeftStyle()}
  75. />
  76. <div
  77. className={cls('flex-1 block-wrapper-inner', {
  78. 'flex-wrap-disabled': !this.state.isEnable
  79. })}
  80. >
  81. <div
  82. className={cls('block-item block-group f--h', {
  83. 'block-active': this.state.isActive
  84. })}
  85. // onDragOver={this.onDragOver}
  86. // onDrop={this.onDrop}
  87. onClick={this.onSelectBlock}
  88. onContextMenu={this.onContextMenu}
  89. >
  90. <BlockDel
  91. isActive={this.state.isActive}
  92. layer={this.props.layer}
  93. bid={this.props.bid}
  94. />
  95. <BlockOrder
  96. layer={this.props.layer}
  97. bid={this.props.bid}
  98. eventNodeId={this.props.eventNodeId}
  99. extraGapGroupLayer={this.extraGapGroupLayer()}
  100. />
  101. <div
  102. className="block-gap"
  103. style={{
  104. left: -this.getGapLeft() + 'px',
  105. padding: '0 ' + this.getGapLeft() / 2 + 'px'
  106. }}
  107. />
  108. {extraLineCom()}
  109. {getRelChildComs()}
  110. <div
  111. id={'block-main-' + this.props.bid}
  112. className="block-main flex-1 f--h"
  113. style={this.blockMainStyle()}
  114. draggable={true}
  115. onDragStart={this.onDragStart}
  116. onDragEnd={this.onDragEnd}
  117. >
  118. <div
  119. id={'over-cover-' + this.props.bid}
  120. className="over-cover"
  121. />
  122. <BlockEnable
  123. className="btn-toggle-con-enable"
  124. bid={this.props.bid}
  125. isEnable={this.state.isEnable}
  126. eventNodeId={this.props.eventNodeId}
  127. />
  128. <BlockDescWrap
  129. bid={this.props.bid}
  130. hasGroupExtraLine={
  131. this.props.groupLayer === 0 && this.state.hasChildren
  132. }
  133. />
  134. </div>
  135. </div>
  136. {/*group 不需要设置layer+1*/}
  137. {this.state.isExpand ? (
  138. <BlockChildren
  139. loops={this.getLoops()}
  140. layer={this.props.layer}
  141. groupLayer={this.props.groupLayer + 1}
  142. nestGroupLayer={this.props.nestGroupLayer + 1}
  143. offspringInNestGroupLayer={this.props.nestGroupLayer + 1}
  144. extraGapGroupLayer={this.extraGapGroupLayer()}
  145. parentBid={this.props.bid}
  146. eventNodeId={this.props.eventNodeId}
  147. visibleBlockIds={this.props.visibleBlockIds}
  148. virtualLayer={this.props.layer}
  149. />
  150. ) : null}
  151. </div>
  152. </div>
  153. </LazyLoad>
  154. )
  155. }
  156. }