import { View, Textarea, InputProps } from "@tarojs/components"; import styleIndex from "./index.module.less"; import { useState, useRef, useEffect } from "react"; import { countCharacters, getStrByMaxLength } from "@/utils/index"; interface Props { placeholder?: string; value: string; cursorSpacing?: number; maxlength?: number; autoHeight?: boolean; disabled?: boolean; confirmType?: keyof InputProps.ConfirmType; extra?: () => JSX.Element | JSX.Element[] | undefined; prefix?: () => JSX.Element | JSX.Element[] | undefined; style?: React.CSSProperties; onInput?: (value: string) => void; onBlur?: (value: string) => void; bgColor?: string; autoFocus?: boolean; extraClass?: string; onConfirm?: (value: string) => void; placeholderStyle?: string; } let isInbox = false; const index = ({ value, bgColor, extraClass, style, disabled, confirmType, prefix, autoHeight, autoFocus = false, placeholder = "请输入...", onInput, onBlur, cursorSpacing, maxlength, extra, onConfirm, placeholderStyle, }: Props) => { const [focus, setFocus] = useState(false); const inputRef = useRef(null); // 创建一个 ref const handleFocus = () => { isInbox = false; setFocus(true); }; const handleBlur = () => { // console.log("textarea blur"); if (!isInbox) { setFocus(false); if (onBlur && inputRef.current) { onBlur(inputRef.current.value); } } }; const handleInput = (value: string) => { const len = countCharacters(value); if (maxlength && len > maxlength) { const r = getStrByMaxLength(value, maxlength); onInput && onInput(r); return; } onInput && onInput(value); }; return ( {prefix && prefix()}