ronds-metadata 1.0.37 → 1.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/comps/Editable/DataCell/Input.d.ts +5 -0
- package/es/comps/Editable/DataCell/Input.js +23 -0
- package/es/comps/Editable/DataCell/Number.d.ts +4 -0
- package/es/comps/Editable/DataCell/Number.js +23 -0
- package/es/comps/Editable/DataCell/Select.d.ts +5 -0
- package/es/comps/Editable/DataCell/Select.js +32 -0
- package/es/comps/Editable/DataCell/Switch.d.ts +4 -0
- package/es/comps/Editable/DataCell/Switch.js +24 -0
- package/es/comps/Editable/comps/EditableAction.d.ts +6 -0
- package/es/comps/Editable/comps/EditableAction.js +81 -0
- package/es/comps/Editable/comps/EditableCell.d.ts +4 -0
- package/es/comps/Editable/comps/EditableCell.js +31 -0
- package/es/comps/Editable/comps/EditableRow.d.ts +4 -0
- package/es/comps/Editable/comps/EditableRow.js +50 -0
- package/es/comps/Editable/index.d.ts +40 -0
- package/es/comps/Editable/index.js +225 -0
- package/es/comps/Editable/interface.d.ts +48 -0
- package/es/comps/Editable/interface.js +7 -0
- package/es/comps/Editable/utils.d.ts +2 -0
- package/es/comps/Editable/utils.js +24 -0
- package/es/comps/MetadataEditV2/components/MetaFieldsEdit.d.ts +6 -0
- package/es/comps/MetadataEditV2/components/MetaFieldsEdit.js +237 -0
- package/es/comps/MetadataEditV2/components/MetaPropsEdit.d.ts +12 -0
- package/es/comps/MetadataEditV2/components/MetaPropsEdit.js +367 -0
- package/es/comps/MetadataEditV2/constant/index.d.ts +24 -0
- package/es/comps/MetadataEditV2/constant/index.js +69 -0
- package/es/comps/MetadataEditV2/hooks/index.d.ts +4 -0
- package/es/comps/MetadataEditV2/hooks/index.js +46 -0
- package/es/comps/MetadataEditV2/index.css +11 -0
- package/es/comps/MetadataEditV2/index.d.ts +25 -0
- package/es/comps/MetadataEditV2/index.js +303 -0
- package/es/comps/MetadataEditV2/type.d.ts +20 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +3 -3
- package/package.json +5 -4
@@ -0,0 +1,23 @@
|
|
1
|
+
import "antd/es/form/style";
|
2
|
+
import _Form from "antd/es/form";
|
3
|
+
import "antd/es/input/style";
|
4
|
+
import _Input from "antd/es/input";
|
5
|
+
|
6
|
+
/*
|
7
|
+
* @Author: wangxian
|
8
|
+
* @Date: 2022-03-04 14:53:50
|
9
|
+
* @LastEditTime: 2022-03-04 15:56:22
|
10
|
+
*/
|
11
|
+
import React from 'react';
|
12
|
+
|
13
|
+
function Index(props) {
|
14
|
+
var dataIndex = props.dataIndex;
|
15
|
+
return /*#__PURE__*/React.createElement(_Form.Item, {
|
16
|
+
name: dataIndex,
|
17
|
+
style: {
|
18
|
+
margin: 0
|
19
|
+
}
|
20
|
+
}, /*#__PURE__*/React.createElement(_Input, null));
|
21
|
+
}
|
22
|
+
|
23
|
+
export default /*#__PURE__*/React.memo(Index);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import "antd/es/form/style";
|
2
|
+
import _Form from "antd/es/form";
|
3
|
+
import "antd/es/input-number/style";
|
4
|
+
import _InputNumber from "antd/es/input-number";
|
5
|
+
|
6
|
+
/*
|
7
|
+
* @Author: wangxian
|
8
|
+
* @Date: 2022-03-04 14:53:50
|
9
|
+
* @LastEditTime: 2022-03-04 14:57:57
|
10
|
+
*/
|
11
|
+
import React from 'react';
|
12
|
+
|
13
|
+
function Index(props) {
|
14
|
+
var dataIndex = props.dataIndex;
|
15
|
+
return /*#__PURE__*/React.createElement(_Form.Item, {
|
16
|
+
name: dataIndex,
|
17
|
+
style: {
|
18
|
+
margin: 0
|
19
|
+
}
|
20
|
+
}, /*#__PURE__*/React.createElement(_InputNumber, null));
|
21
|
+
}
|
22
|
+
|
23
|
+
export default /*#__PURE__*/React.memo(Index);
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import "antd/es/form/style";
|
2
|
+
import _Form from "antd/es/form";
|
3
|
+
import "antd/es/select/style";
|
4
|
+
import _Select from "antd/es/select";
|
5
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
6
|
+
var _excluded = ["dataIndex"];
|
7
|
+
|
8
|
+
/*
|
9
|
+
* @Author: wangxian
|
10
|
+
* @Date: 2022-03-04 14:53:50
|
11
|
+
* @LastEditTime: 2022-03-05 08:27:55
|
12
|
+
*/
|
13
|
+
import React from 'react';
|
14
|
+
|
15
|
+
function Index(props) {
|
16
|
+
var dataIndex = props.dataIndex,
|
17
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
18
|
+
|
19
|
+
return /*#__PURE__*/React.createElement(_Form.Item, {
|
20
|
+
name: dataIndex,
|
21
|
+
style: {
|
22
|
+
margin: 0
|
23
|
+
}
|
24
|
+
}, /*#__PURE__*/React.createElement(_Select, {
|
25
|
+
style: {
|
26
|
+
width: '100%'
|
27
|
+
},
|
28
|
+
options: restProps.enum
|
29
|
+
}));
|
30
|
+
}
|
31
|
+
|
32
|
+
export default /*#__PURE__*/React.memo(Index);
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import "antd/es/form/style";
|
2
|
+
import _Form from "antd/es/form";
|
3
|
+
import "antd/es/switch/style";
|
4
|
+
import _Switch from "antd/es/switch";
|
5
|
+
|
6
|
+
/*
|
7
|
+
* @Author: wangxian
|
8
|
+
* @Date: 2022-03-04 14:53:50
|
9
|
+
* @LastEditTime: 2022-03-05 08:53:21
|
10
|
+
*/
|
11
|
+
import React from 'react';
|
12
|
+
|
13
|
+
function Index(props) {
|
14
|
+
var dataIndex = props.dataIndex;
|
15
|
+
return /*#__PURE__*/React.createElement(_Form.Item, {
|
16
|
+
name: dataIndex,
|
17
|
+
valuePropName: "checked",
|
18
|
+
style: {
|
19
|
+
margin: 0
|
20
|
+
}
|
21
|
+
}, /*#__PURE__*/React.createElement(_Switch, null));
|
22
|
+
}
|
23
|
+
|
24
|
+
export default /*#__PURE__*/React.memo(Index);
|
@@ -0,0 +1,81 @@
|
|
1
|
+
import "antd/es/divider/style";
|
2
|
+
import _Divider from "antd/es/divider";
|
3
|
+
import "antd/es/button/style";
|
4
|
+
import _Button from "antd/es/button";
|
5
|
+
import { EditOutlined, CloseOutlined, CheckOutlined, DeleteOutlined } from '@ant-design/icons';
|
6
|
+
import React from 'react';
|
7
|
+
import { EditableContext } from '../interface';
|
8
|
+
|
9
|
+
var EditableAction = function EditableAction(props) {
|
10
|
+
var type = props.type,
|
11
|
+
record = props.record;
|
12
|
+
|
13
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
14
|
+
editableStream = _ref.editableStream,
|
15
|
+
editRowKey = _ref.editRowKey;
|
16
|
+
|
17
|
+
var onEdit = function onEdit() {
|
18
|
+
editableStream.next({
|
19
|
+
type: 'editRowKey',
|
20
|
+
payload: record
|
21
|
+
});
|
22
|
+
};
|
23
|
+
|
24
|
+
var onCancel = function onCancel() {
|
25
|
+
editableStream.next({
|
26
|
+
type: 'editRowKey',
|
27
|
+
payload: {
|
28
|
+
_rowkey_: undefined
|
29
|
+
}
|
30
|
+
});
|
31
|
+
};
|
32
|
+
|
33
|
+
var onSave = function onSave() {
|
34
|
+
editableStream.next({
|
35
|
+
type: 'onSingleSave',
|
36
|
+
payload: record
|
37
|
+
});
|
38
|
+
};
|
39
|
+
|
40
|
+
var onDelete = function onDelete() {
|
41
|
+
editableStream.next({
|
42
|
+
type: 'onDelete',
|
43
|
+
payload: record
|
44
|
+
});
|
45
|
+
};
|
46
|
+
|
47
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, type === 'single' && /*#__PURE__*/React.createElement(React.Fragment, null, editRowKey !== record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
|
48
|
+
type: "link",
|
49
|
+
disabled: (editRowKey || editRowKey === 0) && editRowKey !== record._rowKey_,
|
50
|
+
size: "small",
|
51
|
+
icon: /*#__PURE__*/React.createElement(EditOutlined, null),
|
52
|
+
onClick: onEdit,
|
53
|
+
title: '编辑'
|
54
|
+
}), /*#__PURE__*/React.createElement(_Divider, {
|
55
|
+
type: "vertical"
|
56
|
+
})), editRowKey === record._rowKey_ && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
|
57
|
+
type: "link",
|
58
|
+
size: "small",
|
59
|
+
icon: /*#__PURE__*/React.createElement(CheckOutlined, null),
|
60
|
+
onClick: onSave,
|
61
|
+
title: '确定'
|
62
|
+
}), /*#__PURE__*/React.createElement(_Divider, {
|
63
|
+
type: "vertical"
|
64
|
+
}), /*#__PURE__*/React.createElement(_Button, {
|
65
|
+
type: "link",
|
66
|
+
size: "small",
|
67
|
+
icon: /*#__PURE__*/React.createElement(CloseOutlined, null),
|
68
|
+
onClick: onCancel,
|
69
|
+
title: '取消'
|
70
|
+
}), /*#__PURE__*/React.createElement(_Divider, {
|
71
|
+
type: "vertical"
|
72
|
+
}))), /*#__PURE__*/React.createElement(_Button, {
|
73
|
+
type: "link",
|
74
|
+
size: "small",
|
75
|
+
icon: /*#__PURE__*/React.createElement(DeleteOutlined, null),
|
76
|
+
onClick: onDelete,
|
77
|
+
title: '删除'
|
78
|
+
}));
|
79
|
+
};
|
80
|
+
|
81
|
+
export default EditableAction;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2
|
+
var _excluded = ["editable", "editableType", "dataIndex", "rowIndex", "children"];
|
3
|
+
|
4
|
+
/*
|
5
|
+
* @Author: wangxian
|
6
|
+
* @Date: 2022-03-04 10:01:10
|
7
|
+
* @LastEditTime: 2022-03-07 13:40:57
|
8
|
+
*/
|
9
|
+
import React from 'react';
|
10
|
+
import { EditableContext } from '../interface';
|
11
|
+
import { getDataCell } from '../utils';
|
12
|
+
|
13
|
+
var EditableCell = function EditableCell(props) {
|
14
|
+
var editable = props.editable,
|
15
|
+
editableType = props.editableType,
|
16
|
+
dataIndex = props.dataIndex,
|
17
|
+
rowIndex = props.rowIndex,
|
18
|
+
children = props.children,
|
19
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
20
|
+
|
21
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
22
|
+
editRowKey = _ref.editRowKey;
|
23
|
+
|
24
|
+
if (editableType === 'single') {
|
25
|
+
return /*#__PURE__*/React.createElement("td", restProps, editable && editRowKey === rowIndex ? getDataCell(props) : children);
|
26
|
+
}
|
27
|
+
|
28
|
+
return /*#__PURE__*/React.createElement("td", restProps, editable ? getDataCell(props) : children);
|
29
|
+
};
|
30
|
+
|
31
|
+
export default EditableCell;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
import "antd/es/form/style";
|
2
|
+
import _Form from "antd/es/form";
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
4
|
+
import React from 'react';
|
5
|
+
import { EditableContext } from '../interface';
|
6
|
+
|
7
|
+
var EditableRow = function EditableRow(props) {
|
8
|
+
var record = props.record;
|
9
|
+
|
10
|
+
var _Form$useForm = _Form.useForm(),
|
11
|
+
_Form$useForm2 = _slicedToArray(_Form$useForm, 1),
|
12
|
+
form = _Form$useForm2[0];
|
13
|
+
|
14
|
+
var _ref = React.useContext(EditableContext) || undefined,
|
15
|
+
editableStream = _ref.editableStream;
|
16
|
+
|
17
|
+
React.useEffect(function () {
|
18
|
+
if (!form) return;
|
19
|
+
form.setFieldsValue(record);
|
20
|
+
}, [record]); // 编辑的时候初始化值
|
21
|
+
// React.useEffect(() => {
|
22
|
+
// const subscription = editableStream.pipe(filter((p: any) => p?.type === 'editRowKey')).subscribe((p: IEditableStream) => {
|
23
|
+
// form.setFieldsValue(p.payload);
|
24
|
+
// });
|
25
|
+
// return () => subscription.unsubscribe();
|
26
|
+
// }, [editableStream]);
|
27
|
+
|
28
|
+
var onValuesChange = function onValuesChange(values, allValues) {
|
29
|
+
if (editableStream) {
|
30
|
+
editableStream.next({
|
31
|
+
type: 'onValuesChange',
|
32
|
+
payload: {
|
33
|
+
rowIdx: record === null || record === void 0 ? void 0 : record._rowKey_,
|
34
|
+
values: values,
|
35
|
+
allValues: allValues
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Form, {
|
42
|
+
name: "editable_".concat(record === null || record === void 0 ? void 0 : record._rowKey_, "_"),
|
43
|
+
form: form,
|
44
|
+
initialValues: record,
|
45
|
+
onValuesChange: onValuesChange,
|
46
|
+
component: false
|
47
|
+
}, /*#__PURE__*/React.createElement("tr", props)));
|
48
|
+
};
|
49
|
+
|
50
|
+
export default EditableRow;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { TableProps } from 'antd';
|
2
|
+
import { EditColumnsType, IMultipleProps } from './interface';
|
3
|
+
interface IEditableProps<R = any> {
|
4
|
+
/**
|
5
|
+
* 单行编辑或多行编辑。
|
6
|
+
* 备注:
|
7
|
+
* type为multiple时,一定要设置defaultValue
|
8
|
+
*/
|
9
|
+
type?: 'single' | 'multiple';
|
10
|
+
/**
|
11
|
+
* 表格列的配置描述
|
12
|
+
*/
|
13
|
+
columns: EditColumnsType;
|
14
|
+
/**
|
15
|
+
* 当type为multiple的配置
|
16
|
+
*/
|
17
|
+
multipleProps?: IMultipleProps;
|
18
|
+
/**
|
19
|
+
* 数据数组
|
20
|
+
*/
|
21
|
+
dataSource: object[];
|
22
|
+
/**
|
23
|
+
* 只读
|
24
|
+
*/
|
25
|
+
readonly?: boolean;
|
26
|
+
/**
|
27
|
+
* antd自身的属性
|
28
|
+
*/
|
29
|
+
tableProps?: TableProps<R>;
|
30
|
+
/**
|
31
|
+
* 每行确认回调函数
|
32
|
+
*/
|
33
|
+
onRowConfirm: (record: any) => void;
|
34
|
+
/**
|
35
|
+
* 每行删除回调
|
36
|
+
*/
|
37
|
+
onRowDelete: (record: any) => void;
|
38
|
+
}
|
39
|
+
declare const Editable: (props: IEditableProps) => JSX.Element;
|
40
|
+
export default Editable;
|
@@ -0,0 +1,225 @@
|
|
1
|
+
import "antd/es/button/style";
|
2
|
+
import _Button from "antd/es/button";
|
3
|
+
import "antd/es/table/style";
|
4
|
+
import _Table from "antd/es/table";
|
5
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
6
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
7
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
8
|
+
import "antd/es/message/style";
|
9
|
+
import _message from "antd/es/message";
|
10
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
11
|
+
import React from 'react';
|
12
|
+
import { BehaviorSubject } from 'rxjs';
|
13
|
+
import { pick, isArray } from 'lodash';
|
14
|
+
import EditableCell from './comps/EditableCell';
|
15
|
+
import EditableRow from './comps/EditableRow';
|
16
|
+
import { EditableContext } from './interface';
|
17
|
+
import EditableAction from './comps/EditableAction';
|
18
|
+
|
19
|
+
var Editable = function Editable(props) {
|
20
|
+
var _props$type = props.type,
|
21
|
+
type = _props$type === void 0 ? 'single' : _props$type,
|
22
|
+
readonly = props.readonly,
|
23
|
+
columns = props.columns,
|
24
|
+
dataSource = props.dataSource,
|
25
|
+
_props$multipleProps = props.multipleProps,
|
26
|
+
multipleProps = _props$multipleProps === void 0 ? {
|
27
|
+
defaultValue: '',
|
28
|
+
addPosition: 'bottom'
|
29
|
+
} : _props$multipleProps,
|
30
|
+
tableProps = props.tableProps,
|
31
|
+
onRowConfirm = props.onRowConfirm,
|
32
|
+
onRowDelete = props.onRowDelete;
|
33
|
+
var defaultValue = multipleProps.defaultValue,
|
34
|
+
addPosition = multipleProps.addPosition;
|
35
|
+
|
36
|
+
var _React$useState = React.useState([]),
|
37
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
38
|
+
records = _React$useState2[0],
|
39
|
+
setRecords = _React$useState2[1]; // 当type为single的时候 只能编辑该行数据
|
40
|
+
|
41
|
+
|
42
|
+
var _React$useState3 = React.useState(),
|
43
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
44
|
+
editRowKey = _React$useState4[0],
|
45
|
+
setEditRowkey = _React$useState4[1];
|
46
|
+
|
47
|
+
var editRowKeyRef = React.useRef(); // 记录上一次发生改变的行值
|
48
|
+
|
49
|
+
var lastValueRef = React.useRef(); // 记录上一次的datasource
|
50
|
+
|
51
|
+
var lastDataSourceRef = React.useRef();
|
52
|
+
var firstLoadRef = React.useRef(true); // 定义处理编辑表格的数据流
|
53
|
+
|
54
|
+
var editableStream = React.useMemo(function () {
|
55
|
+
return new BehaviorSubject(undefined);
|
56
|
+
}, []);
|
57
|
+
var processStreamFactory = React.useCallback(function (data) {
|
58
|
+
switch (data === null || data === void 0 ? void 0 : data.type) {
|
59
|
+
case 'onValuesChange':
|
60
|
+
lastValueRef.current = data.payload;
|
61
|
+
break;
|
62
|
+
|
63
|
+
case 'editRowKey':
|
64
|
+
setEditRowkey(data.payload._rowKey_);
|
65
|
+
editRowKeyRef.current = data.payload._rowKey_;
|
66
|
+
break;
|
67
|
+
|
68
|
+
case 'onSingleSave':
|
69
|
+
if (lastValueRef.current && lastValueRef.current.rowIdx === data.payload._rowKey_) {
|
70
|
+
onRowConfirm && onRowConfirm(lastValueRef.current);
|
71
|
+
editRowKeyRef.current = undefined;
|
72
|
+
setEditRowkey(undefined);
|
73
|
+
} else {
|
74
|
+
_message.warn('当前值无修改');
|
75
|
+
}
|
76
|
+
|
77
|
+
break;
|
78
|
+
|
79
|
+
case 'onDelete':
|
80
|
+
if (type === 'single') {
|
81
|
+
// 如果删除的 是正在编辑的 重置状态
|
82
|
+
if (editRowKeyRef.current === data.payload._rowKey_) {
|
83
|
+
setEditRowkey(undefined);
|
84
|
+
editRowKeyRef.current = undefined;
|
85
|
+
}
|
86
|
+
|
87
|
+
onRowDelete && onRowDelete(data.payload);
|
88
|
+
}
|
89
|
+
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
}, []); // 定义内部的record
|
93
|
+
|
94
|
+
React.useEffect(function () {
|
95
|
+
if (dataSource) {
|
96
|
+
setRecords(_toConsumableArray(dataSource));
|
97
|
+
}
|
98
|
+
}, [dataSource]); // 集中处理数据流
|
99
|
+
|
100
|
+
React.useEffect(function () {
|
101
|
+
var subscription = editableStream.subscribe(function (p) {
|
102
|
+
processStreamFactory(p);
|
103
|
+
});
|
104
|
+
return function () {
|
105
|
+
return subscription.unsubscribe();
|
106
|
+
};
|
107
|
+
}, [editableStream, processStreamFactory]);
|
108
|
+
var getEditColumn = React.useCallback(function (column) {
|
109
|
+
var _column = _objectSpread(_objectSpread({}, column), {}, {
|
110
|
+
children: isArray(column === null || column === void 0 ? void 0 : column.children) ? column.children.map(getEditColumn) : undefined
|
111
|
+
});
|
112
|
+
|
113
|
+
if (column.editable && !readonly) {
|
114
|
+
_column.onCell = function (record, rowIndex) {
|
115
|
+
return _objectSpread(_objectSpread({
|
116
|
+
record: record,
|
117
|
+
editableType: type
|
118
|
+
}, pick(column, ['editable', 'title', 'dataIndex', 'type', 'enum'])), {}, {
|
119
|
+
rowIndex: rowIndex
|
120
|
+
});
|
121
|
+
};
|
122
|
+
}
|
123
|
+
|
124
|
+
return _column;
|
125
|
+
}, [readonly, type]); // 处理一下编辑表格的数据
|
126
|
+
|
127
|
+
var _columns = React.useMemo(function () {
|
128
|
+
var res = columns.map(getEditColumn);
|
129
|
+
|
130
|
+
if (!readonly) {
|
131
|
+
var _aciton_ = {
|
132
|
+
dataKey: '_aciton_',
|
133
|
+
title: '操作',
|
134
|
+
width: 60,
|
135
|
+
maxWidth: 60,
|
136
|
+
export: false,
|
137
|
+
minWidth: 60,
|
138
|
+
frozen: 'right',
|
139
|
+
render: function render(val, record) {
|
140
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditableAction, {
|
141
|
+
type: type,
|
142
|
+
record: record
|
143
|
+
}));
|
144
|
+
}
|
145
|
+
};
|
146
|
+
res.push(_aciton_);
|
147
|
+
}
|
148
|
+
|
149
|
+
return res;
|
150
|
+
}, [columns, readonly, type]); // 主要是自己加一层rowkey
|
151
|
+
|
152
|
+
|
153
|
+
var _dataSource = React.useMemo(function () {
|
154
|
+
var _lastDataSourceRef$cu;
|
155
|
+
|
156
|
+
var res = records.map(function (it, idx) {
|
157
|
+
return _objectSpread({
|
158
|
+
_rowKey_: idx
|
159
|
+
}, it);
|
160
|
+
}); // 判断是否是新加行,如果是single类型的编辑框置为新加的一行
|
161
|
+
|
162
|
+
if (type === 'single' && !firstLoadRef.current && res.length > ((_lastDataSourceRef$cu = lastDataSourceRef.current) === null || _lastDataSourceRef$cu === void 0 ? void 0 : _lastDataSourceRef$cu.length)) {
|
163
|
+
setEditRowkey(res[res.length - 1]._rowKey_);
|
164
|
+
editRowKeyRef.current = res[res.length - 1]._rowKey_;
|
165
|
+
}
|
166
|
+
|
167
|
+
if (res.length > 0) {
|
168
|
+
firstLoadRef.current = false;
|
169
|
+
}
|
170
|
+
|
171
|
+
lastDataSourceRef.current = res;
|
172
|
+
return res;
|
173
|
+
}, [records, type]);
|
174
|
+
|
175
|
+
var onAddRow = function onAddRow() {
|
176
|
+
if (defaultValue) {
|
177
|
+
var _records = records;
|
178
|
+
|
179
|
+
if (addPosition === 'top') {
|
180
|
+
_records.unshift(defaultValue);
|
181
|
+
} else {
|
182
|
+
_records.push(defaultValue);
|
183
|
+
}
|
184
|
+
|
185
|
+
setRecords(_toConsumableArray(_records));
|
186
|
+
}
|
187
|
+
};
|
188
|
+
|
189
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditableContext.Provider, {
|
190
|
+
value: {
|
191
|
+
editableStream: editableStream,
|
192
|
+
editRowKey: editRowKey
|
193
|
+
}
|
194
|
+
}, /*#__PURE__*/React.createElement(_Table, _extends({
|
195
|
+
bordered: true
|
196
|
+
}, tableProps, {
|
197
|
+
pagination: false,
|
198
|
+
rowKey: "_rowKey_",
|
199
|
+
size: "small",
|
200
|
+
columns: _columns,
|
201
|
+
dataSource: _dataSource,
|
202
|
+
components: {
|
203
|
+
body: {
|
204
|
+
row: EditableRow,
|
205
|
+
cell: EditableCell
|
206
|
+
}
|
207
|
+
},
|
208
|
+
onRow: function onRow(record, index) {
|
209
|
+
return {
|
210
|
+
record: record,
|
211
|
+
index: index
|
212
|
+
};
|
213
|
+
}
|
214
|
+
})), type === 'multiple' && /*#__PURE__*/React.createElement(_Button, {
|
215
|
+
block: true,
|
216
|
+
type: "dashed",
|
217
|
+
style: {
|
218
|
+
marginBottom: 16,
|
219
|
+
marginTop: 16
|
220
|
+
},
|
221
|
+
onClick: onAddRow
|
222
|
+
}, "\u6DFB\u52A0\u4E00\u884C")));
|
223
|
+
};
|
224
|
+
|
225
|
+
export default Editable;
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { ColumnsType } from 'antd/lib/table/interface';
|
2
|
+
import React from 'react';
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
4
|
+
export interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
|
5
|
+
title: any;
|
6
|
+
editable: boolean;
|
7
|
+
dataIndex: number;
|
8
|
+
rowIndex: number;
|
9
|
+
record: any;
|
10
|
+
type: InputType;
|
11
|
+
editableType: 'single' | 'multiple';
|
12
|
+
enum?: {
|
13
|
+
label: string;
|
14
|
+
value: string;
|
15
|
+
}[];
|
16
|
+
children: React.ReactNode;
|
17
|
+
}
|
18
|
+
export interface EditableRowProps extends React.HTMLAttributes<HTMLElement> {
|
19
|
+
rowIndex: number;
|
20
|
+
record?: any;
|
21
|
+
}
|
22
|
+
export declare type InputType = 'bool' | 'number' | 'text' | 'enum' | string;
|
23
|
+
export interface EditColumnsType extends ColumnsType<any> {
|
24
|
+
type?: InputType;
|
25
|
+
enum?: {
|
26
|
+
label: string;
|
27
|
+
value: string;
|
28
|
+
}[];
|
29
|
+
}
|
30
|
+
export interface IEditableStream {
|
31
|
+
type: string;
|
32
|
+
payload: any;
|
33
|
+
}
|
34
|
+
export interface IEditableContextProps {
|
35
|
+
editableStream: BehaviorSubject<IEditableStream | undefined>;
|
36
|
+
editRowKey: number;
|
37
|
+
}
|
38
|
+
export declare const EditableContext: React.Context<IEditableContextProps>;
|
39
|
+
export interface IMultipleProps {
|
40
|
+
/**
|
41
|
+
* 新增一列 默认的值
|
42
|
+
*/
|
43
|
+
defaultValue: any;
|
44
|
+
/**
|
45
|
+
* 添加行的位置
|
46
|
+
*/
|
47
|
+
addPosition?: 'top' | 'bottom';
|
48
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/*
|
2
|
+
* @Author: wangxian
|
3
|
+
* @Date: 2022-03-04 14:59:04
|
4
|
+
* @LastEditTime: 2022-03-04 15:28:47
|
5
|
+
*/
|
6
|
+
import React from 'react';
|
7
|
+
import Input from './DataCell/Input';
|
8
|
+
import Number from './DataCell/Number';
|
9
|
+
import Select from './DataCell/Select';
|
10
|
+
import Switch from './DataCell/Switch';
|
11
|
+
var DataCellMap = {
|
12
|
+
text: Input,
|
13
|
+
number: Number,
|
14
|
+
enum: Select,
|
15
|
+
bool: Switch
|
16
|
+
};
|
17
|
+
export function getDataCell(item) {
|
18
|
+
if (item.type && DataCellMap[item.type]) {
|
19
|
+
var Comm = DataCellMap[item.type];
|
20
|
+
return /*#__PURE__*/React.createElement(Comm, item);
|
21
|
+
}
|
22
|
+
|
23
|
+
return null;
|
24
|
+
}
|