import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Input } from 'antd'
|
|
import './index.scss'
|
|
const { TextArea } = Input
|
|
class CustomTextArea extends Component {
|
static propTpyes = {
|
Item: PropTypes.bool, // 表单
|
onChange: PropTypes.func // 数据切换
|
}
|
|
state = {
|
value: '',
|
encryption: 'false'
|
}
|
|
UNSAFE_componentWillMount () {
|
let value = ''
|
let encryption = 'false'
|
|
if (this.props['data-__meta']) {
|
value = this.props['data-__meta'].initialValue || ''
|
}
|
|
if (this.props.Item && this.props.Item.encryption === 'true') {
|
encryption = 'true'
|
if (value) {
|
try {
|
value = window.decodeURIComponent(window.atob(value))
|
} catch {
|
value = this.props['data-__meta'].initialValue || ''
|
}
|
}
|
}
|
|
this.setState({
|
value,
|
encryption
|
})
|
}
|
|
onChange = (e) => {
|
const { encryption } = this.state
|
let val = e.target.value
|
|
this.setState({ value: val })
|
|
let _val = val
|
if (encryption === 'true') {
|
try {
|
_val = window.btoa(window.encodeURIComponent(_val))
|
} catch {
|
_val = val
|
}
|
}
|
this.props.onChange(_val)
|
}
|
|
render() {
|
const { Item } = this.props
|
const { value } = this.state
|
|
return (
|
<TextArea value={value} autoSize={{ minRows: 2, maxRows: Item.maxRows || 6 }} onChange={this.onChange} disabled={Item.readonly === 'true'} />
|
)
|
}
|
}
|
|
export default CustomTextArea
|