|
@@ -1,81 +0,0 @@
|
|
|
-import { Input, Form } from 'antd'
|
|
|
|
|
-import React, { useState, useEffect, useRef } from 'react'
|
|
|
|
|
-import { connect } from 'dva'
|
|
|
|
|
-
|
|
|
|
|
-const EditableCell = ({
|
|
|
|
|
- title,
|
|
|
|
|
- editable,
|
|
|
|
|
- children,
|
|
|
|
|
- dataIndex,
|
|
|
|
|
- record,
|
|
|
|
|
- handleSave,
|
|
|
|
|
- ...restProps
|
|
|
|
|
-}) => {
|
|
|
|
|
- const [editing, setEditing] = useState(false)
|
|
|
|
|
- const inputRef = useRef(null)
|
|
|
|
|
- const [form] = Form.useForm()
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (editing) {
|
|
|
|
|
- inputRef.current.focus()
|
|
|
|
|
- }
|
|
|
|
|
- }, [editing])
|
|
|
|
|
-
|
|
|
|
|
- const toggleEdit = () => {
|
|
|
|
|
- setEditing(!editing)
|
|
|
|
|
- form.setFieldsValue({
|
|
|
|
|
- [dataIndex]: record[dataIndex]
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const save = async () => {
|
|
|
|
|
- try {
|
|
|
|
|
- const values = await form.validateFields()
|
|
|
|
|
- toggleEdit()
|
|
|
|
|
- handleSave({ ...record, ...values })
|
|
|
|
|
- } catch (errInfo) {
|
|
|
|
|
- console.log('Save failed:', errInfo)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let childNode = children
|
|
|
|
|
- if (editable) {
|
|
|
|
|
- childNode = editing ? (
|
|
|
|
|
- <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
|
|
|
|
|
- className="editable-cell-value-wrap"
|
|
|
|
|
- style={{
|
|
|
|
|
- paddingRight: 24
|
|
|
|
|
- }}
|
|
|
|
|
- onClick={toggleEdit}>
|
|
|
|
|
- {children}
|
|
|
|
|
- </div>
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return <td {...restProps}>{childNode}</td>
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const Editcell = props => {
|
|
|
|
|
- return (
|
|
|
|
|
- <div>
|
|
|
|
|
- <Form name="basic">
|
|
|
|
|
- <Form.Item label="Username" name="username">
|
|
|
|
|
- <Input />
|
|
|
|
|
- </Form.Item>
|
|
|
|
|
- <Form.Item label="Password" name="Password">
|
|
|
|
|
- <Input.Password />
|
|
|
|
|
- </Form.Item>
|
|
|
|
|
- </Form>
|
|
|
|
|
- </div>
|
|
|
|
|
- )
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-export default connect(({ district, loading }) => ({
|
|
|
|
|
- options: district.data,
|
|
|
|
|
- loadingDistrict: loading.effects['district/fetch']
|
|
|
|
|
-}))(Editcell)
|
|
|