index.js 1.07 KB
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