浏览代码

new event view

lianghuang 4 年之前
父节点
当前提交
ea308fee4e

+ 164 - 0
coms/jenga/block/base/action/BlockActionDelay.jsx

@@ -0,0 +1,164 @@
+import React from 'react'
+import cls from 'classnames'
+import i18n from 'i18next'
+import { InputNumber } from 'antd'
+import onClickOutside from 'react-onclickoutside'
+import newEventActions from 'actions/newEvent'
+import newEventStores from 'stores/newEvent'
+import { getEventNodeById, getEventBlockByBid } from 'stores/funcs/newEvent'
+import { isServerRootNode } from 'stores/funcs/event/methodUtils'
+import { shallowEqualImmutable } from 'utils/utils'
+import iconStrObj from 'src/assets/icons/iconsStr'
+
+class BlockActionDelay extends React.Component {
+  constructor(props) {
+    super(props)
+    this.state = {
+      showPopUp: false,
+      delayTime: this.getTime()
+    }
+
+    this.onEventChange = this.onEventChange.bind(this)
+
+    this.delayInput = React.createRef()
+    this.getTime = this.getTime.bind(this)
+    this.onFocus = this.onFocus.bind(this)
+    this.onChange = this.onChange.bind(this)
+    this.showPopUp = this.showPopUp.bind(this)
+    this.showDelay = this.showDelay.bind(this)
+  }
+
+  componentDidMount() {
+    this.unsubscribe = newEventStores.listen(this.onEventChange)
+  }
+
+  componentWillUnmount() {
+    this.unsubscribe()
+  }
+
+  shouldComponentUpdate(nextProps, nextState) {
+    return (
+      !shallowEqualImmutable(this.props, nextProps) ||
+      !shallowEqualImmutable(this.state, nextState)
+    )
+  }
+
+  componentDidUpdate(preProps) {
+    if (preProps.bid !== this.props.bid) {
+      this.setState({
+        showPopUp: false,
+        delayTime: this.getTime()
+      })
+    }
+  }
+
+  onEventChange(status) {
+    if (
+      status.types.includes('updateBlockProp') &&
+      this.props.bid === status.data.affectBlockId &&
+      status.data.prop === 'delay'
+    ) {
+      this.onChange(this.getTime(), true)
+    }
+  }
+
+  getTime() {
+    let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
+    let block = getEventBlockByBid(this.props.bid, nodeId)
+    return block.delay || 0
+  }
+
+  onFocus(e) {
+    e.target.select()
+  }
+
+  onChange(value, stopUpdateInStore) {
+    let result = value
+    if (value === '') {
+      result = 0
+    } else if (!isNaN(value)) {
+      result = parseFloat(value) || 0
+    } else {
+      result = this.state.delayTime || 0
+    }
+    if (result !== this.state.delayTime) {
+      this.setState(
+        {
+          delayTime: result
+        },
+        () => {
+          if (!stopUpdateInStore) {
+            let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
+            newEventActions.updateBlockProp({
+              nodeId,
+              blockId: this.props.bid,
+              prop: 'delay',
+              value: result
+            })
+          }
+          this.props.changeDelay && this.props.changeDelay()
+        }
+      )
+    }
+  }
+
+  showPopUp() {
+    this.setState(
+      {
+        showPopUp: !this.state.showPopUp
+      },
+      () => {
+        if (
+          this.state.showPopUp &&
+          this.delayInput &&
+          this.delayInput.current
+        ) {
+          this.delayInput.current.inputNumberRef.input.select()
+        }
+      }
+    )
+  }
+
+  handleClickOutside(evt) {
+    this.setState({
+      showPopUp: false
+    })
+  }
+
+  showDelay() {
+    let nodeId = this.props.eventNodeId || newEventStores.curEventNodeId
+    let isServer = isServerRootNode(getEventNodeById(nodeId))
+    return !isServer
+  }
+
+  render() {
+    return (
+      <div className={cls('action-delay f--h', { hidden: !this.showDelay() })}>
+        <button
+          className="btn-clear btn-action-delay"
+          onClick={this.showPopUp}
+          dangerouslySetInnerHTML={{ __html: iconStrObj.delayIcon }}
+        />
+        {this.state.showPopUp ? (
+          <div className="action-delay-popup">
+            <div className="delay-title">
+              {i18n.t('EventView.jenga_action_block.delaySetting')}
+            </div>
+            <div className="delay-input-wrap">
+              <InputNumber
+                ref={this.delayInput}
+                min={0}
+                className="normal"
+                value={this.state.delayTime}
+                onChange={this.onChange}
+                onFocus={this.onFocus}
+              />
+            </div>
+          </div>
+        ) : null}
+      </div>
+    )
+  }
+}
+
+export default onClickOutside(BlockActionDelay)

+ 2 - 2
coms/jenga/block/base/action/BlockActionObject.jsx

@@ -165,7 +165,7 @@ export default class BlockActionObject extends React.Component {
     let nodeId = this.props.eventNodeId || this.curEventNodeId
     let node = getEventNodeById(nodeId)
     // 对象改变
-    let preObj = getBlockObj(block)
+    let preObj = getBlockObj({ block })
     let preObject = getActionBlockObjNode({
       obj: preObj,
       nodeId
@@ -327,7 +327,7 @@ export default class BlockActionObject extends React.Component {
     let nodeId = this.props.eventNodeId || this.curEventNodeId
     let curBlock = getEventBlockByBid(this.props.bid, nodeId)
     if (curBlock) {
-      _obj = getBlockObj(curBlock)
+      _obj = getBlockObj({ block: curBlock })
     }
     return _obj
   }

+ 20 - 0
coms/jenga/block/base/action/BlockActionReload.jsx

@@ -0,0 +1,20 @@
+import React from 'react'
+import iconStrObj from 'src/assets/icons/iconsStr'
+
+export default class BlockActionReload extends React.Component {
+  constructor(props) {
+    super(props)
+  }
+
+  render() {
+    return (
+      <div className="action-reload f--h">
+        <button
+          className="btn-clear btn-action-reload"
+          onClick={this.props.reload}
+          dangerouslySetInnerHTML={{ __html: iconStrObj.updateIcon }}
+        />
+      </div>
+    )
+  }
+}

+ 4 - 2
coms/jenga/nav/JengaTypeBlockOperator.jsx

@@ -9,7 +9,8 @@ import {
   nodeIsDbPayment,
   nodeIsFunctionGroup,
   nodeIsService,
-  nodeIsIotMessage
+  nodeIsIotMessage,
+  nodeIsMq
 } from 'stores/funcs/nodeType'
 import { EVENT_BLOCK_TYPE, BLOCK_OP_TYPE } from 'const/const'
 
@@ -139,7 +140,8 @@ export default class JengaTypeBlockOperator extends React.Component {
         (nodeIsService(curEventNode.type) &&
           nodeIsIotMessage(curEventNode.type))) &&
       !nodeIsFunctionGroup(curEventNode.type) &&
-      !nodeIsDbPayment(curEventNode.type)
+      !nodeIsDbPayment(curEventNode.type) &&
+      !nodeIsMq(curEventNode.type)
     result[EVENT_BLOCK_TYPE.COMMENT] = false
     result[EVENT_BLOCK_TYPE.GROUP] = false
     if (this.curBlockId) {