NodeFuncGroup.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react'
  2. import i18n from 'i18next'
  3. import { Switch } from 'antd'
  4. import treeActions from 'actions/tree'
  5. import { getEventNodeById } from 'stores/funcs/newEvent'
  6. export default class NodeFuncGroup extends React.Component {
  7. constructor(props) {
  8. super(props)
  9. this.state = {
  10. isSync: this.getIsSync()
  11. }
  12. this.getIsSync = this.getIsSync.bind(this)
  13. this.onChangeIsSync = this.onChangeIsSync.bind(this)
  14. }
  15. componentDidUpdate(preProps) {
  16. if (this.props.nodeId !== preProps.nodeId) {
  17. this.setState({
  18. isSync: this.getIsSync()
  19. })
  20. }
  21. }
  22. getIsSync() {
  23. let isSync = false
  24. let node = getEventNodeById(this.props.nodeId)
  25. if (node) {
  26. // 默认为false
  27. isSync = node.props.sync || isSync
  28. }
  29. return isSync
  30. }
  31. onChangeIsSync(e) {
  32. let props = {
  33. sync: e
  34. }
  35. this.setState({ isSync: props.sync }, () => {
  36. treeActions.changeNodeProps({
  37. nodeId: this.props.nodeId,
  38. props: props
  39. })
  40. })
  41. }
  42. render() {
  43. return (
  44. <div className="jenga-node-func-group f--hlc">
  45. <div className="title">{i18n.t('EventView.jenga_extra.func-sync')}</div>
  46. <Switch
  47. checked={this.state.isSync}
  48. onChange={this.onChangeIsSync}
  49. className="sync-switch"
  50. />
  51. </div>
  52. )
  53. }
  54. }