BlockLoopConItem.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import React from 'react'
  2. import ConItem from '../ConItem'
  3. import { Menu, Dropdown } from 'antd'
  4. import cls from 'classnames'
  5. import { layerWidth } from 'stores/funcs/newEvent'
  6. import FormulaEditor from 'src/components/common/formulaEditor/EventFormulaEditor'
  7. const MenuItem = Menu.Item
  8. export default class BlockLoopConItem extends ConItem {
  9. constructor(props) {
  10. super(props)
  11. }
  12. getValueWidth() {
  13. const groupLayer = this.props.groupLayer > 0 ? this.props.groupLayer : 0
  14. const nestingLayer =
  15. this.props.nestGroupLayer > 0 ? this.props.nestGroupLayer - 1 : 0
  16. const extraGapGroupLayer =
  17. this.props.extraGapGroupLayer > 0
  18. ? (this.props.extraGapGroupLayer - 1) * 2
  19. : 0
  20. let originWidth =
  21. 224.5 - ((groupLayer + nestingLayer) * 2) / 2 - extraGapGroupLayer / 2
  22. let width = layerWidth({
  23. originWidth: originWidth + this.state.widthDelta / 2,
  24. decreaseFactor: 10.5,
  25. layer: this.props.layer
  26. })
  27. return {
  28. width: width + 'px'
  29. }
  30. }
  31. render() {
  32. let conFlagsMenu = () => {
  33. return (
  34. <Menu className="loop-con-flag-select-menu" onClick={this.onChangeFlag}>
  35. {this.state.conFlags.map(option => {
  36. return (
  37. <MenuItem
  38. key={option}
  39. className={cls({
  40. selected: this.isSelectedFlag(option)
  41. })}
  42. >
  43. {this.getOptionName(option)}
  44. </MenuItem>
  45. )
  46. })}
  47. </Menu>
  48. )
  49. }
  50. let conOperatorsMenu = () => {
  51. return (
  52. <Menu
  53. className="loop-con-operator-select-menu"
  54. onClick={this.onChangeOperator}
  55. >
  56. {this.state.conOperatorOptions.map(option => {
  57. return (
  58. <MenuItem
  59. key={option}
  60. className={cls({
  61. selected: this.isSelectedOperator(option)
  62. })}
  63. >
  64. {option}
  65. </MenuItem>
  66. )
  67. })}
  68. </Menu>
  69. )
  70. }
  71. return (
  72. <div className="con-item f--hlc">
  73. {this.props.index === 0 ? (
  74. <React.Fragment>
  75. <div className="item-enable" />
  76. <div className="item-flag">{this.getConItemFlagName()}</div>
  77. </React.Fragment>
  78. ) : (
  79. <React.Fragment>
  80. <div className="item-enable" />
  81. <Dropdown
  82. trigger={['click']}
  83. getPopupContainer={triggerNode => triggerNode.parentNode}
  84. overlayClassName={'loop-con-flag-dropdown'}
  85. overlay={conFlagsMenu()}
  86. >
  87. <div className="loop-con-flag-select f--hlc">
  88. <input
  89. value={this.getConItemFlagName()}
  90. readOnly={true}
  91. className="ant-dropdown-input"
  92. />
  93. <div className="ant-dropdown-icon" />
  94. </div>
  95. </Dropdown>
  96. </React.Fragment>
  97. )}
  98. <div className="item-value-wrap f--h" style={this.getValueWidth()}>
  99. <FormulaEditor
  100. className="loop-formula-editor"
  101. uid={this.props.bid + 'value1'}
  102. bid={this.props.bid}
  103. value={this.state.conItem.value1}
  104. onChangeCode={this.onChangeValue.bind(this, 'value1')}
  105. />
  106. </div>
  107. <Dropdown
  108. trigger={['click']}
  109. getPopupContainer={triggerNode => triggerNode.parentNode}
  110. overlayClassName={'loop-con-operator-dropdown'}
  111. overlay={conOperatorsMenu()}
  112. >
  113. <div className="loop-con-operator-select f--hlc">
  114. <input
  115. value={this.state.conItem.operator}
  116. readOnly={true}
  117. className="ant-dropdown-input"
  118. />
  119. <div className="ant-dropdown-icon" />
  120. </div>
  121. </Dropdown>
  122. <div className="item-value-wrap f--h" style={this.getValueWidth()}>
  123. <FormulaEditor
  124. className="loop-formula-editor"
  125. uid={this.props.bid + 'value2'}
  126. bid={this.props.bid}
  127. value={this.state.conItem.value2}
  128. params={this.formulaExtraParams()}
  129. onChangeCode={this.onChangeValue.bind(this, 'value2')}
  130. />
  131. </div>
  132. <button
  133. className="btn-clear btn-con-item-del btn-loop-con-item-del"
  134. onClick={this.onDeleteCon}
  135. />
  136. {this.props.index === 0 ? (
  137. <button className="btn-clear btn-add-con" onClick={this.onAddCon}>
  138. <div className="btn-icon">
  139. <span className="horizon" />
  140. <span className="vertical" />
  141. </div>
  142. </button>
  143. ) : null}
  144. </div>
  145. )
  146. }
  147. }