import { Input, View } from '@tarojs/components' import { useEffect, useState } from 'react' import styles from './index.module.scss' export interface Param { show: boolean title: string onConfirm?: (val: string) => void onCancel?: () => void defaultValue?: string onClose?: () => void } export default (props: Param) => { const { show = false, title = '', onConfirm, onCancel, defaultValue = '', onClose } = props const [value, setValue] = useState('') const [openStatus, setOpenStatus] = useState(false) useEffect(() => { if (value !== defaultValue) { setValue(() => defaultValue) } }, [defaultValue]) useEffect(() => { if (show !== openStatus) { setOpenStatus(() => show) } }, [show]) const onInputEven = (e) => { const res = e.detail.value setValue(res) } const onCancelEven = () => { onCancel?.() onCloseEven() } const onCloseEven = () => { onClose?.() setOpenStatus(false) } const onConfirmEven = (val) => { onClose?.() onConfirm?.(val) } return ( <> {openStatus && {title} 取消 onConfirmEven(value)}>确认修改 } ) }