|
@@ -1,19 +1,19 @@
|
|
|
-import { Input,Form } from 'antd'
|
|
|
|
|
|
|
+import { Input, Form } from 'antd'
|
|
|
import React, { useContext, useState, useEffect, useRef } from 'react'
|
|
import React, { useContext, useState, useEffect, useRef } from 'react'
|
|
|
import { connect } from 'dva'
|
|
import { connect } from 'dva'
|
|
|
|
|
|
|
|
-const EditableContext = React.createContext(null)
|
|
|
|
|
|
|
+// const EditableContext = React.createContext(null)
|
|
|
|
|
|
|
|
-const EditableRow = ({ index, ...props }) => {
|
|
|
|
|
- const [form] = Form.useForm()
|
|
|
|
|
- return (
|
|
|
|
|
- <Form form={form} component={false}>
|
|
|
|
|
- <EditableContext.Provider value={form}>
|
|
|
|
|
- <tr {...props} />
|
|
|
|
|
- </EditableContext.Provider>
|
|
|
|
|
- </Form>
|
|
|
|
|
- )
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// const EditableRow = ({ index, ...props }) => {
|
|
|
|
|
+// const [form] = Form.useForm()
|
|
|
|
|
+// return (
|
|
|
|
|
+// <Form form={form} component={false}>
|
|
|
|
|
+// <EditableContext.Provider value={form}>
|
|
|
|
|
+// <tr {...props} />
|
|
|
|
|
+// </EditableContext.Provider>
|
|
|
|
|
+// </Form>
|
|
|
|
|
+// )
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
const EditableCell = ({
|
|
const EditableCell = ({
|
|
|
title,
|
|
title,
|
|
@@ -26,7 +26,7 @@ const EditableCell = ({
|
|
|
}) => {
|
|
}) => {
|
|
|
const [editing, setEditing] = useState(false)
|
|
const [editing, setEditing] = useState(false)
|
|
|
const inputRef = useRef(null)
|
|
const inputRef = useRef(null)
|
|
|
- const form = useContext(EditableContext)
|
|
|
|
|
|
|
+ const [form] = Form.useForm()
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
if (editing) {
|
|
if (editing) {
|
|
|
inputRef.current.focus()
|
|
inputRef.current.focus()
|
|
@@ -42,6 +42,7 @@ const EditableCell = ({
|
|
|
|
|
|
|
|
const save = async () => {
|
|
const save = async () => {
|
|
|
try {
|
|
try {
|
|
|
|
|
+ form.validateFields([dataIndex])
|
|
|
const values = await form.validateFields()
|
|
const values = await form.validateFields()
|
|
|
toggleEdit()
|
|
toggleEdit()
|
|
|
handleSave({ ...record, ...values })
|
|
handleSave({ ...record, ...values })
|
|
@@ -53,28 +54,18 @@ const EditableCell = ({
|
|
|
let childNode = children
|
|
let childNode = children
|
|
|
if (editable) {
|
|
if (editable) {
|
|
|
childNode = editing ? (
|
|
childNode = editing ? (
|
|
|
- <Form.Item
|
|
|
|
|
- style={{
|
|
|
|
|
- margin: 0
|
|
|
|
|
- }}
|
|
|
|
|
- name={dataIndex}
|
|
|
|
|
- rules={[
|
|
|
|
|
- {
|
|
|
|
|
- required: true,
|
|
|
|
|
- message: `${title} is required.`
|
|
|
|
|
- }
|
|
|
|
|
- ]}
|
|
|
|
|
- >
|
|
|
|
|
- <Input ref={inputRef} onPressEnter={save} onBlur={save} />
|
|
|
|
|
- </Form.Item>
|
|
|
|
|
|
|
+ <Form form={form}>
|
|
|
|
|
+ <Form.Item name={dataIndex} rules={[{ required: true, message: `${title} is required.` }]}>
|
|
|
|
|
+ <Input ref={inputRef} onPressEnter={save} onBlur={save} />
|
|
|
|
|
+ </Form.Item>
|
|
|
|
|
+ </Form>
|
|
|
) : (
|
|
) : (
|
|
|
<div
|
|
<div
|
|
|
className="editable-cell-value-wrap"
|
|
className="editable-cell-value-wrap"
|
|
|
style={{
|
|
style={{
|
|
|
paddingRight: 24
|
|
paddingRight: 24
|
|
|
}}
|
|
}}
|
|
|
- onClick={toggleEdit}
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ onClick={toggleEdit}>
|
|
|
{children}
|
|
{children}
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
@@ -84,22 +75,13 @@ const EditableCell = ({
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const Editcell = props => {
|
|
const Editcell = props => {
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
- <Form
|
|
|
|
|
- name="basic"
|
|
|
|
|
- >
|
|
|
|
|
- <Form.Item
|
|
|
|
|
- label="Username"
|
|
|
|
|
- name="username"
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <Form name="basic">
|
|
|
|
|
+ <Form.Item label="Username" name="username">
|
|
|
<Input />
|
|
<Input />
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
- <Form.Item
|
|
|
|
|
- label="Password"
|
|
|
|
|
- name="Password"
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <Form.Item label="Password" name="Password">
|
|
|
<Input.Password />
|
|
<Input.Password />
|
|
|
</Form.Item>
|
|
</Form.Item>
|
|
|
</Form>
|
|
</Form>
|