|
@@ -21,15 +21,18 @@ const EditableFormItem = ({
|
|
|
const [editing, setEditing] = useState(false)
|
|
const [editing, setEditing] = useState(false)
|
|
|
const iRef = useRef(null)
|
|
const iRef = useRef(null)
|
|
|
const [val, setVal] = useState('')
|
|
const [val, setVal] = useState('')
|
|
|
|
|
+ const [extraVal, setExtraVal] = useState('')
|
|
|
const { Option } = Select
|
|
const { Option } = Select
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
setVal('')
|
|
setVal('')
|
|
|
|
|
+ setExtraVal('')
|
|
|
}, [])
|
|
}, [])
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- // 处于编辑状态自动聚焦
|
|
|
|
|
- if (editing && editCellType !== 'cascader') {
|
|
|
|
|
|
|
+ // 处于编辑状态自动聚焦, 级联有问题暂无解决办法
|
|
|
|
|
+ if (editing && iRef.current) {
|
|
|
iRef.current.focus()
|
|
iRef.current.focus()
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// 对级联数据初始化, key一定要是district!!
|
|
// 对级联数据初始化, key一定要是district!!
|
|
|
if (editCellType === 'cascader' && record) {
|
|
if (editCellType === 'cascader' && record) {
|
|
|
dispatch({
|
|
dispatch({
|
|
@@ -68,12 +71,13 @@ const EditableFormItem = ({
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
const save = async e => {
|
|
const save = async e => {
|
|
|
- const { value } = e.currentTarget
|
|
|
|
|
|
|
+ const { value, local = '' } = e.currentTarget
|
|
|
if (value === record || !value) {
|
|
if (value === record || !value) {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- setVal(value)
|
|
|
|
|
await handleConfirm(value)
|
|
await handleConfirm(value)
|
|
|
|
|
+ local && setExtraVal(local)
|
|
|
|
|
+ setVal(value)
|
|
|
toggleEdit()
|
|
toggleEdit()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -94,10 +98,11 @@ const EditableFormItem = ({
|
|
|
case 'cascader':
|
|
case 'cascader':
|
|
|
cell = (
|
|
cell = (
|
|
|
<LazyCascader
|
|
<LazyCascader
|
|
|
- // ref={iRef}
|
|
|
|
|
|
|
+ ref={iRef}
|
|
|
defaultValue={val}
|
|
defaultValue={val}
|
|
|
className="zh-width-100P"
|
|
className="zh-width-100P"
|
|
|
- onChange={value => save({ currentTarget: { value } })}
|
|
|
|
|
|
|
+ onBlur={save}
|
|
|
|
|
+ onChange={(value, local) => save({ currentTarget: { value, local } })}
|
|
|
/>
|
|
/>
|
|
|
)
|
|
)
|
|
|
break
|
|
break
|
|
@@ -106,7 +111,7 @@ const EditableFormItem = ({
|
|
|
<Select
|
|
<Select
|
|
|
defaultValue={val}
|
|
defaultValue={val}
|
|
|
ref={iRef}
|
|
ref={iRef}
|
|
|
- // onBlur={save}
|
|
|
|
|
|
|
+ onBlur={save}
|
|
|
onChange={value => save({ currentTarget: { value } })}
|
|
onChange={value => save({ currentTarget: { value } })}
|
|
|
className="zh-width-100P">
|
|
className="zh-width-100P">
|
|
|
{options}
|
|
{options}
|
|
@@ -139,7 +144,7 @@ const EditableFormItem = ({
|
|
|
} else {
|
|
} else {
|
|
|
let content = val
|
|
let content = val
|
|
|
if (editCellType === 'cascader') {
|
|
if (editCellType === 'cascader') {
|
|
|
- content = dataSource.local
|
|
|
|
|
|
|
+ content = extraVal || dataSource.local
|
|
|
}
|
|
}
|
|
|
cell = (
|
|
cell = (
|
|
|
<div className="editable-cell-value-wrap" onClick={toggleEdit}>
|
|
<div className="editable-cell-value-wrap" onClick={toggleEdit}>
|