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
import React, { useState, useEffect, useMemo } from 'react'
import { Input } from 'antd'
import styles from './index.less'
import { urlRegExp } from '../../../../utils'
const TextArea = (props) => {
const { value, onChange, schema, addons } = props
const { disabled, placeholder, presetValue, maxLength, rows, otherValue } = schema
useEffect(() => {
if (addons) {
addons.setValueByPath(addons.dataPath, presetValue)
} else {
onChange(presetValue)
}
}, [presetValue])
useEffect(() => {
if (otherValue) {
onChange(otherValue)
}
}, [otherValue])
const handleChange = (e) => {
onChange(e.target.value)
}
if (disabled && urlRegExp.test(value)) {
return <div className={styles.areaUrl} onClick={() => window.open(value)}>{value}</div>
}
return (
<Input.TextArea
maxLength={maxLength}
disabled={disabled}
value={value}
rows={rows}
placeholder={disabled ? (placeholder || '') : (placeholder || '请输入内容')}
onChange={handleChange}
/>
)
}
export default TextArea