import {Textarea, View } from "@tarojs/components"; import { memo, useEffect, useMemo, useState } from "react"; import styles from './index.module.scss' import classnames from "classnames"; //其他说明 type Param = { title?: string, onChange?: (val: string) => void, placeholder?: string, defaultValue?: string, onlyRead?: false|true } export default memo(({onChange, title = '', placeholder = '请输入', defaultValue, onlyRead = false}:Param) => { const [descData, setDescData] = useState({ number: 0, value: '', count: 200, show: false }) const getDesc = (value = '') => { let res = value if(value.length > descData.count) { res = value.slice(0, descData.count) } setDescData({...descData, number:res.length, value: res}) onChange?.(res) } useEffect(() => { getDesc(defaultValue) }, [defaultValue]) const toggleShowRealTextarea = (show) => { setDescData({...descData, show:show}) } return ( {title} {(descData.show && !onlyRead)&&|| toggleShowRealTextarea(true)}>{descData.value||placeholder} } {descData.number +'/'+ descData.count} ) })