|
|
@@ -5,10 +5,14 @@ import React, { useState, useEffect, useRef } from 'react'
|
|
|
import './index.less'
|
|
|
|
|
|
const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType }) => {
|
|
|
+
|
|
|
const [editing, setEditing] = useState(false)
|
|
|
const inputRef = useRef(null)
|
|
|
const [val, setVal] = useState('')
|
|
|
useEffect(() => {
|
|
|
+ setVal('')
|
|
|
+ }, [])
|
|
|
+ useEffect(() => {
|
|
|
// 处于编辑状态自动聚焦
|
|
|
if (editing) {
|
|
|
inputRef.current.focus()
|
|
|
@@ -19,6 +23,12 @@ const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType
|
|
|
}
|
|
|
}, [record, editing])
|
|
|
|
|
|
+ // 单独设置一个依赖,防止dataId变化
|
|
|
+ useEffect(() => {
|
|
|
+ setVal(record)
|
|
|
+ }, [dataId])
|
|
|
+
|
|
|
+
|
|
|
const toggleEdit = () => {
|
|
|
setEditing(!editing)
|
|
|
}
|
|
|
@@ -61,7 +71,7 @@ const EditableFormItem = ({ label, dataIndex, record, dataId, span, editCellType
|
|
|
onPressEnter={save}
|
|
|
onBlur={save}
|
|
|
defaultValue={val}
|
|
|
- // onChange={handleOnChange}
|
|
|
+ // onChange={handleOnChange}
|
|
|
/>
|
|
|
)
|
|
|
break
|