king
2020-07-01 9a16cb432ed0a597caf9ba78c9dda63ad2134207
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, {Component} from 'react'
import PropTypes from 'prop-types'
// import { is, fromJS } from 'immutable'
import { Form, Icon, Popover, Input } from 'antd'
 
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import './index.scss'
 
class ContentUpdate extends Component {
  static propTpyes = {
    element: PropTypes.object,
    updateContent: PropTypes.func
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false
  }
 
  UNSAFE_componentWillMount () {
 
  }
 
  // shouldComponentUpdate (nextProps, nextState) {
  //   return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  // }
 
  onVisibleChange = (visible) => {
    const { element } = this.props
    let val = this.props.form.getFieldValue('content')
 
    this.setState({
      visible: visible
    })
 
    if (val && element.content !== val) {
      this.props.updateContent({...element, content: val})
    } else {
      this.props.form.setFieldsValue({content: element.content})
    }
  }
 
  handleSubmit = () => {
    const { element } = this.props
    let val = this.props.form.getFieldValue('content')
 
    this.setState({
      visible: false
    })
 
    if (val && element.content !== val) {
      this.props.updateContent({...element, content: val})
    } else {
      this.props.form.setFieldsValue({content: element.content})
    }
  }
 
  render () {
    const { element } = this.props
    const { getFieldDecorator } = this.props.form
    const { visible } = this.state
 
    return (
      <div className="mob-content-update">
        <Popover content={
          <div>
            {getFieldDecorator('content', {
              initialValue: element.content
            })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
          </div>
        } overlayClassName="mob-content-update-popover" placement="bottomRight" title="" visible={visible} trigger="click" onVisibleChange={this.onVisibleChange}>
          <Icon type="edit" />
        </Popover>
      </div>
    )
  }
}
 
export default Form.create()(ContentUpdate)