@hzab/form-render 1.4.1-beta → 1.4.1
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/CHANGELOG.md +1 -1
- package/package.json +2 -2
- package/src/components/Upload/index.tsx +2 -23
- package/src/components/index.tsx +0 -2
- package/src/components/ArrayCards/index.tsx +0 -158
- package/src/components/ArrayCards/style.less +0 -15
- package/src/components/ArrayCards/style.ts +0 -4
- package/src/components/ArrayTable/index.tsx +0 -413
- package/src/components/ArrayTable/style.less +0 -53
- package/src/components/ArrayTable/style.ts +0 -7
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
@@ -4,35 +4,14 @@ import { useGlobalPropsContext } from "../../common/global-props-context";
|
|
4
4
|
export const Upload = (props) => {
|
5
5
|
// 组件外部传入的 props
|
6
6
|
const globalProps = useGlobalPropsContext() || {};
|
7
|
-
const { field = {}, onChange, value } = props;
|
8
|
-
const { name, mode, componentProps = {} } = field;
|
9
|
-
const { multiple } = componentProps;
|
10
|
-
|
11
|
-
async function onUploadChange(files) {
|
12
|
-
let _files = files;
|
13
|
-
if (field?.autoUpload && props.fieldsConf[name]?.onUpload) {
|
14
|
-
_files = await props.fieldsConf[name]?.onUpload(files);
|
15
|
-
if (!_files) {
|
16
|
-
return;
|
17
|
-
}
|
18
|
-
}
|
19
|
-
// 若单选模式,默认只返回对应数据,而非嵌套一层数组
|
20
|
-
if (!multiple && _files && _files.length === 1) {
|
21
|
-
_files = _files[0];
|
22
|
-
}
|
23
|
-
onChange && onChange(_files);
|
24
|
-
}
|
25
7
|
|
26
8
|
const _props = {
|
27
|
-
mode: mode,
|
28
|
-
...props,
|
29
|
-
value: typeof value === "string" ? [value] : value,
|
30
9
|
axios: globalProps?.axios,
|
31
10
|
axiosConf: globalProps?.axiosConf,
|
32
|
-
...
|
11
|
+
...props,
|
33
12
|
};
|
34
13
|
|
35
|
-
return <UploaderCom {..._props}
|
14
|
+
return <UploaderCom {..._props} />;
|
36
15
|
};
|
37
16
|
|
38
17
|
export default Upload;
|
package/src/components/index.tsx
CHANGED
@@ -1,158 +0,0 @@
|
|
1
|
-
import React, { useMemo } from "react";
|
2
|
-
import { Card, Empty } from "antd";
|
3
|
-
import { CardProps } from "antd/lib/card";
|
4
|
-
import { ArrayField } from "@formily/core";
|
5
|
-
import { useField, observer, useFieldSchema, RecursionField } from "@formily/react";
|
6
|
-
import cls from "classnames";
|
7
|
-
import { ISchema } from "@formily/json-schema";
|
8
|
-
import { usePrefixCls } from "c-formily-antd/lib/__builtins__";
|
9
|
-
import { ArrayBase, ArrayBaseMixins, IArrayBaseProps } from "c-formily-antd/lib/array-base";
|
10
|
-
import { nanoid } from "nanoid";
|
11
|
-
type ComposedArrayCards = React.FC<React.PropsWithChildren<CardProps & IArrayBaseProps>> & ArrayBaseMixins;
|
12
|
-
|
13
|
-
const isAdditionComponent = (schema: ISchema) => {
|
14
|
-
return schema["x-component"]?.indexOf("Addition") > -1;
|
15
|
-
};
|
16
|
-
|
17
|
-
const isIndexComponent = (schema: ISchema) => {
|
18
|
-
return schema["x-component"]?.indexOf?.("Index") > -1;
|
19
|
-
};
|
20
|
-
|
21
|
-
const isRemoveComponent = (schema: ISchema) => {
|
22
|
-
return schema["x-component"]?.indexOf?.("Remove") > -1;
|
23
|
-
};
|
24
|
-
|
25
|
-
const isCopyComponent = (schema: ISchema) => {
|
26
|
-
return schema["x-component"]?.indexOf?.("Copy") > -1;
|
27
|
-
};
|
28
|
-
|
29
|
-
const isMoveUpComponent = (schema: ISchema) => {
|
30
|
-
return schema["x-component"]?.indexOf?.("MoveUp") > -1;
|
31
|
-
};
|
32
|
-
|
33
|
-
const isMoveDownComponent = (schema: ISchema) => {
|
34
|
-
return schema["x-component"]?.indexOf?.("MoveDown") > -1;
|
35
|
-
};
|
36
|
-
|
37
|
-
const isOperationComponent = (schema: ISchema) => {
|
38
|
-
return (
|
39
|
-
isAdditionComponent(schema) ||
|
40
|
-
isRemoveComponent(schema) ||
|
41
|
-
isCopyComponent(schema) ||
|
42
|
-
isMoveDownComponent(schema) ||
|
43
|
-
isMoveUpComponent(schema)
|
44
|
-
);
|
45
|
-
};
|
46
|
-
|
47
|
-
export const ArrayCards: ComposedArrayCards = observer((props) => {
|
48
|
-
const field = useField<ArrayField>();
|
49
|
-
const schema = useFieldSchema();
|
50
|
-
const prefixCls = usePrefixCls("formily-array-cards", props);
|
51
|
-
const { onAdd, onCopy, onRemove, onMoveDown, onMoveUp } = props;
|
52
|
-
const dataSource = useMemo(() => {
|
53
|
-
return Array.isArray(field.value)
|
54
|
-
? field.value?.map((item) => {
|
55
|
-
return {
|
56
|
-
...item,
|
57
|
-
_key: item?.id || nanoid(),
|
58
|
-
};
|
59
|
-
})
|
60
|
-
: [];
|
61
|
-
}, [field.value?.length]);
|
62
|
-
if (!schema) throw new Error("can not found schema object");
|
63
|
-
const renderItems = () => {
|
64
|
-
return dataSource?.map((item, index) => {
|
65
|
-
const items = Array.isArray(schema.items) ? schema.items[index] || schema.items[0] : schema.items;
|
66
|
-
const title = (
|
67
|
-
<span>
|
68
|
-
<RecursionField
|
69
|
-
schema={items}
|
70
|
-
name={index}
|
71
|
-
filterProperties={(schema) => {
|
72
|
-
if (!isIndexComponent(schema)) return false;
|
73
|
-
return true;
|
74
|
-
}}
|
75
|
-
onlyRenderProperties
|
76
|
-
/>
|
77
|
-
{props.title || field.title}
|
78
|
-
</span>
|
79
|
-
);
|
80
|
-
const extra = (
|
81
|
-
<span>
|
82
|
-
<RecursionField
|
83
|
-
schema={items}
|
84
|
-
name={index}
|
85
|
-
filterProperties={(schema) => {
|
86
|
-
if (!isOperationComponent(schema)) return false;
|
87
|
-
return true;
|
88
|
-
}}
|
89
|
-
onlyRenderProperties
|
90
|
-
/>
|
91
|
-
{props.extra}
|
92
|
-
</span>
|
93
|
-
);
|
94
|
-
|
95
|
-
const content = (
|
96
|
-
<RecursionField
|
97
|
-
schema={items}
|
98
|
-
name={index}
|
99
|
-
filterProperties={(schema) => {
|
100
|
-
if (isIndexComponent(schema)) return false;
|
101
|
-
if (isOperationComponent(schema)) return false;
|
102
|
-
return true;
|
103
|
-
}}
|
104
|
-
/>
|
105
|
-
);
|
106
|
-
return (
|
107
|
-
<ArrayBase.Item key={item?._key} index={index} record={() => field.value?.[index]}>
|
108
|
-
<Card
|
109
|
-
{...props}
|
110
|
-
onChange={() => {}}
|
111
|
-
className={cls(`${prefixCls}-item`, props.className)}
|
112
|
-
title={title}
|
113
|
-
extra={extra}
|
114
|
-
>
|
115
|
-
{content}
|
116
|
-
</Card>
|
117
|
-
</ArrayBase.Item>
|
118
|
-
);
|
119
|
-
});
|
120
|
-
};
|
121
|
-
|
122
|
-
const renderAddition = () => {
|
123
|
-
return schema.reduceProperties((addition, schema, key) => {
|
124
|
-
if (isAdditionComponent(schema)) {
|
125
|
-
return <RecursionField schema={schema} name={key} />;
|
126
|
-
}
|
127
|
-
return addition;
|
128
|
-
}, null);
|
129
|
-
};
|
130
|
-
|
131
|
-
const renderEmpty = () => {
|
132
|
-
if (dataSource?.length) return;
|
133
|
-
return (
|
134
|
-
<Card
|
135
|
-
{...props}
|
136
|
-
onChange={() => {}}
|
137
|
-
className={cls(`${prefixCls}-item`, props.className)}
|
138
|
-
title={props.title || field.title}
|
139
|
-
>
|
140
|
-
<Empty />
|
141
|
-
</Card>
|
142
|
-
);
|
143
|
-
};
|
144
|
-
|
145
|
-
return (
|
146
|
-
<ArrayBase onAdd={onAdd} onCopy={onCopy} onRemove={onRemove} onMoveUp={onMoveUp} onMoveDown={onMoveDown}>
|
147
|
-
{renderEmpty()}
|
148
|
-
{renderItems()}
|
149
|
-
{renderAddition()}
|
150
|
-
</ArrayBase>
|
151
|
-
);
|
152
|
-
});
|
153
|
-
|
154
|
-
ArrayCards.displayName = "ArrayCards";
|
155
|
-
|
156
|
-
ArrayBase.mixin(ArrayCards);
|
157
|
-
|
158
|
-
export default ArrayCards;
|
@@ -1,15 +0,0 @@
|
|
1
|
-
@root-entry-name: 'default';
|
2
|
-
@import (reference) '~antd/es/style/themes/index.less';
|
3
|
-
|
4
|
-
@array-base-prefix-cls: ~'@{ant-prefix}-formily-array-base';
|
5
|
-
@array-cards-prefix-cls: ~'@{ant-prefix}-formily-array-cards';
|
6
|
-
|
7
|
-
.@{array-cards-prefix-cls}-item {
|
8
|
-
margin-bottom: 10px !important;
|
9
|
-
}
|
10
|
-
|
11
|
-
.ant-card-extra {
|
12
|
-
.@{array-base-prefix-cls}-copy {
|
13
|
-
margin-left: 6px;
|
14
|
-
}
|
15
|
-
}
|
@@ -1,413 +0,0 @@
|
|
1
|
-
import React, { Fragment, useState, useRef, useEffect, createContext, useContext, useCallback, useMemo } from "react";
|
2
|
-
import { Table, Pagination, Space, Select, Badge } from "antd";
|
3
|
-
import { PaginationProps } from "antd/lib/pagination";
|
4
|
-
import { TableProps, ColumnProps } from "antd/lib/table";
|
5
|
-
import { SelectProps } from "antd/lib/select";
|
6
|
-
import cls from "classnames";
|
7
|
-
import { GeneralField, FieldDisplayTypes, ArrayField } from "@formily/core";
|
8
|
-
import { useField, observer, useFieldSchema, RecursionField, ReactFC } from "@formily/react";
|
9
|
-
import { isArr, isBool, isFn } from "@formily/shared";
|
10
|
-
import { Schema } from "@formily/json-schema";
|
11
|
-
import { usePrefixCls, SortableContainer, SortableElement } from "c-formily-antd/lib/__builtins__";
|
12
|
-
import { ArrayBase, ArrayBaseMixins, IArrayBaseProps } from "c-formily-antd/lib/array-base";
|
13
|
-
import { nanoid } from "nanoid";
|
14
|
-
|
15
|
-
interface ObservableColumnSource {
|
16
|
-
field: GeneralField;
|
17
|
-
columnProps: ColumnProps<any>;
|
18
|
-
schema: Schema;
|
19
|
-
display: FieldDisplayTypes;
|
20
|
-
name: string;
|
21
|
-
}
|
22
|
-
interface IArrayTablePaginationProps extends PaginationProps {
|
23
|
-
dataSource?: any[];
|
24
|
-
showPagination?: boolean;
|
25
|
-
children?: (
|
26
|
-
dataSource: any[],
|
27
|
-
pagination: React.ReactNode,
|
28
|
-
options: {
|
29
|
-
startIndex: number;
|
30
|
-
},
|
31
|
-
) => React.ReactElement;
|
32
|
-
}
|
33
|
-
|
34
|
-
interface IStatusSelectProps extends SelectProps<any> {
|
35
|
-
pageSize?: number;
|
36
|
-
}
|
37
|
-
|
38
|
-
type ComposedArrayTable = React.FC<React.PropsWithChildren<TableProps<any> & IArrayBaseProps>> &
|
39
|
-
ArrayBaseMixins & {
|
40
|
-
Column?: React.FC<React.PropsWithChildren<ColumnProps<any>>>;
|
41
|
-
};
|
42
|
-
|
43
|
-
interface PaginationAction {
|
44
|
-
totalPage?: number;
|
45
|
-
pageSize?: number;
|
46
|
-
showPagination?: boolean;
|
47
|
-
changePage?: (page: number) => void;
|
48
|
-
}
|
49
|
-
|
50
|
-
const SortableRow = SortableElement((props: any) => <tr {...props} />);
|
51
|
-
const SortableBody = SortableContainer((props: any) => <tbody {...props} />);
|
52
|
-
|
53
|
-
const isColumnComponent = (schema: Schema) => {
|
54
|
-
return schema["x-component"]?.indexOf("Column") > -1;
|
55
|
-
};
|
56
|
-
|
57
|
-
const isOperationsComponent = (schema: Schema) => {
|
58
|
-
return schema["x-component"]?.indexOf("Operations") > -1;
|
59
|
-
};
|
60
|
-
|
61
|
-
const isAdditionComponent = (schema: Schema) => {
|
62
|
-
return schema["x-component"]?.indexOf("Addition") > -1;
|
63
|
-
};
|
64
|
-
|
65
|
-
const useArrayTableSources = () => {
|
66
|
-
const arrayField = useField();
|
67
|
-
const schema = useFieldSchema();
|
68
|
-
const parseSources = (schema: Schema): ObservableColumnSource[] => {
|
69
|
-
if (isColumnComponent(schema) || isOperationsComponent(schema) || isAdditionComponent(schema)) {
|
70
|
-
if (!schema["x-component-props"]?.["dataIndex"] && !schema["name"]) return [];
|
71
|
-
const name = schema["x-component-props"]?.["dataIndex"] || schema["name"];
|
72
|
-
const field = arrayField.query(arrayField.address.concat(name)).take();
|
73
|
-
const columnProps = field?.component?.[1] || schema["x-component-props"] || {};
|
74
|
-
const display = field?.display || schema["x-display"] || "visible";
|
75
|
-
return [
|
76
|
-
{
|
77
|
-
name,
|
78
|
-
display,
|
79
|
-
field,
|
80
|
-
schema,
|
81
|
-
columnProps,
|
82
|
-
},
|
83
|
-
];
|
84
|
-
} else if (schema.properties) {
|
85
|
-
return schema.reduceProperties((buf, schema) => {
|
86
|
-
return buf.concat(parseSources(schema));
|
87
|
-
}, []);
|
88
|
-
}
|
89
|
-
};
|
90
|
-
|
91
|
-
const parseArrayItems = (schema: Schema["items"]) => {
|
92
|
-
if (!schema) return [];
|
93
|
-
const sources: ObservableColumnSource[] = [];
|
94
|
-
const items = isArr(schema) ? schema : [schema];
|
95
|
-
return items.reduce((columns, schema) => {
|
96
|
-
const item = parseSources(schema);
|
97
|
-
if (item) {
|
98
|
-
return columns.concat(item);
|
99
|
-
}
|
100
|
-
return columns;
|
101
|
-
}, sources);
|
102
|
-
};
|
103
|
-
|
104
|
-
if (!schema) throw new Error("can not found schema object");
|
105
|
-
|
106
|
-
return parseArrayItems(schema.items);
|
107
|
-
};
|
108
|
-
|
109
|
-
const useArrayTableColumns = (
|
110
|
-
dataSource: any[],
|
111
|
-
field: ArrayField,
|
112
|
-
sources: ObservableColumnSource[],
|
113
|
-
): TableProps<any>["columns"] => {
|
114
|
-
return sources.reduce((buf, { name, columnProps, schema, display }, key) => {
|
115
|
-
if (display !== "visible") return buf;
|
116
|
-
if (!isColumnComponent(schema)) return buf;
|
117
|
-
return buf.concat({
|
118
|
-
...columnProps,
|
119
|
-
key,
|
120
|
-
dataIndex: name,
|
121
|
-
render: (value: any, record: any) => {
|
122
|
-
const index = dataSource?.indexOf(record);
|
123
|
-
const children = (
|
124
|
-
<ArrayBase.Item index={index} record={() => field?.value?.[index]}>
|
125
|
-
<RecursionField schema={schema} name={index} onlyRenderProperties />
|
126
|
-
</ArrayBase.Item>
|
127
|
-
);
|
128
|
-
return children;
|
129
|
-
},
|
130
|
-
});
|
131
|
-
}, []);
|
132
|
-
};
|
133
|
-
|
134
|
-
const useAddition = () => {
|
135
|
-
const schema = useFieldSchema();
|
136
|
-
return schema.reduceProperties((addition, schema, key) => {
|
137
|
-
if (isAdditionComponent(schema)) {
|
138
|
-
return <RecursionField schema={schema} name={key} />;
|
139
|
-
}
|
140
|
-
return addition;
|
141
|
-
}, null);
|
142
|
-
};
|
143
|
-
|
144
|
-
const schedulerRequest = {
|
145
|
-
request: null,
|
146
|
-
};
|
147
|
-
|
148
|
-
const StatusSelect: ReactFC<IStatusSelectProps> = observer(
|
149
|
-
(props) => {
|
150
|
-
const field = useField<ArrayField>();
|
151
|
-
const prefixCls = usePrefixCls("formily-array-table");
|
152
|
-
const errors = field.errors;
|
153
|
-
const parseIndex = (address: string) => {
|
154
|
-
return Number(address.slice(address.indexOf(field.address.toString()) + 1).match(/(\d+)/)?.[1]);
|
155
|
-
};
|
156
|
-
const options = props.options?.map(({ label, value }) => {
|
157
|
-
const val = Number(value);
|
158
|
-
const hasError = errors.some(({ address }) => {
|
159
|
-
const currentIndex = parseIndex(address);
|
160
|
-
const startIndex = (val - 1) * props.pageSize;
|
161
|
-
const endIndex = val * props.pageSize;
|
162
|
-
return currentIndex >= startIndex && currentIndex <= endIndex;
|
163
|
-
});
|
164
|
-
return {
|
165
|
-
label: hasError ? <Badge dot>{label}</Badge> : label,
|
166
|
-
value,
|
167
|
-
};
|
168
|
-
});
|
169
|
-
|
170
|
-
const width = String(options?.length).length * 15;
|
171
|
-
|
172
|
-
return (
|
173
|
-
<Select
|
174
|
-
value={props.value}
|
175
|
-
onChange={props.onChange}
|
176
|
-
options={options}
|
177
|
-
virtual
|
178
|
-
style={{
|
179
|
-
width: width < 60 ? 60 : width,
|
180
|
-
}}
|
181
|
-
className={cls(`${prefixCls}-status-select`, {
|
182
|
-
"has-error": errors?.length,
|
183
|
-
})}
|
184
|
-
/>
|
185
|
-
);
|
186
|
-
},
|
187
|
-
{
|
188
|
-
scheduler: (update) => {
|
189
|
-
clearTimeout(schedulerRequest.request);
|
190
|
-
schedulerRequest.request = setTimeout(() => {
|
191
|
-
update();
|
192
|
-
}, 100);
|
193
|
-
},
|
194
|
-
},
|
195
|
-
);
|
196
|
-
|
197
|
-
const PaginationContext = createContext<PaginationAction>({});
|
198
|
-
const usePagination = () => {
|
199
|
-
return useContext(PaginationContext);
|
200
|
-
};
|
201
|
-
|
202
|
-
const ArrayTablePagination: ReactFC<IArrayTablePaginationProps> = (props) => {
|
203
|
-
const [current, setCurrent] = useState(1);
|
204
|
-
const prefixCls = usePrefixCls("formily-array-table");
|
205
|
-
const showPagination = props.showPagination ?? true;
|
206
|
-
const pageSize = props.pageSize || 10;
|
207
|
-
const size = props.size || "default";
|
208
|
-
const dataSource = props.dataSource || [];
|
209
|
-
const startIndex = (current - 1) * pageSize;
|
210
|
-
const endIndex = startIndex + pageSize - 1;
|
211
|
-
const total = dataSource?.length || 0;
|
212
|
-
const totalPage = Math.ceil(total / pageSize);
|
213
|
-
const pages = Array.from(new Array(totalPage)).map((_, index) => {
|
214
|
-
const page = index + 1;
|
215
|
-
return {
|
216
|
-
label: page,
|
217
|
-
value: page,
|
218
|
-
};
|
219
|
-
});
|
220
|
-
const handleChange = (current: number) => {
|
221
|
-
setCurrent(current);
|
222
|
-
};
|
223
|
-
|
224
|
-
useEffect(() => {
|
225
|
-
if (totalPage > 0 && totalPage < current) {
|
226
|
-
handleChange(totalPage);
|
227
|
-
}
|
228
|
-
}, [totalPage, current]);
|
229
|
-
|
230
|
-
const renderPagination = () => {
|
231
|
-
if (totalPage <= 1 || !showPagination) return;
|
232
|
-
return (
|
233
|
-
<div className={`${prefixCls}-pagination`}>
|
234
|
-
<Space>
|
235
|
-
<StatusSelect
|
236
|
-
value={current}
|
237
|
-
pageSize={pageSize}
|
238
|
-
onChange={handleChange}
|
239
|
-
options={pages}
|
240
|
-
notFoundContent={false}
|
241
|
-
/>
|
242
|
-
<Pagination
|
243
|
-
{...props}
|
244
|
-
pageSize={pageSize}
|
245
|
-
current={current}
|
246
|
-
total={dataSource.length}
|
247
|
-
size={size}
|
248
|
-
showSizeChanger={false}
|
249
|
-
onChange={handleChange}
|
250
|
-
/>
|
251
|
-
</Space>
|
252
|
-
</div>
|
253
|
-
);
|
254
|
-
};
|
255
|
-
|
256
|
-
return (
|
257
|
-
<Fragment>
|
258
|
-
<PaginationContext.Provider
|
259
|
-
value={{
|
260
|
-
totalPage,
|
261
|
-
pageSize,
|
262
|
-
changePage: handleChange,
|
263
|
-
showPagination,
|
264
|
-
}}
|
265
|
-
>
|
266
|
-
{props.children?.(
|
267
|
-
showPagination ? dataSource?.slice(startIndex, endIndex + 1) : dataSource,
|
268
|
-
renderPagination(),
|
269
|
-
{ startIndex },
|
270
|
-
)}
|
271
|
-
</PaginationContext.Provider>
|
272
|
-
</Fragment>
|
273
|
-
);
|
274
|
-
};
|
275
|
-
|
276
|
-
const RowComp: ReactFC<React.HTMLAttributes<HTMLTableRowElement>> = (props) => {
|
277
|
-
const prefixCls = usePrefixCls("formily-array-table");
|
278
|
-
const index = props["data-row-key"] || 0;
|
279
|
-
return (
|
280
|
-
<SortableRow
|
281
|
-
lockAxis="y"
|
282
|
-
{...props}
|
283
|
-
index={index}
|
284
|
-
className={cls(props.className, `${prefixCls}-row-${index + 1}`)}
|
285
|
-
/>
|
286
|
-
);
|
287
|
-
};
|
288
|
-
|
289
|
-
export const ArrayTable: ComposedArrayTable = observer((props) => {
|
290
|
-
const ref = useRef<HTMLDivElement>();
|
291
|
-
const field = useField<ArrayField>();
|
292
|
-
const prefixCls = usePrefixCls("formily-array-table");
|
293
|
-
const dataSource = useMemo(() => {
|
294
|
-
return Array.isArray(field.value)
|
295
|
-
? field.value?.slice().map((item) => {
|
296
|
-
return {
|
297
|
-
...item,
|
298
|
-
_key: item?.id || nanoid(),
|
299
|
-
};
|
300
|
-
})
|
301
|
-
: [];
|
302
|
-
}, [field.value.length]);
|
303
|
-
const sources = useArrayTableSources();
|
304
|
-
const columns = useArrayTableColumns(dataSource, field, sources);
|
305
|
-
const pagination = isBool(props.pagination) ? { showPagination: props.pagination } : props.pagination;
|
306
|
-
const addition = useAddition();
|
307
|
-
const { onAdd, onCopy, onRemove, onMoveDown, onMoveUp } = props;
|
308
|
-
const defaultRowKey = (record: any) => {
|
309
|
-
return record?._key;
|
310
|
-
};
|
311
|
-
const addTdStyles = (id: number) => {
|
312
|
-
const node = ref.current?.querySelector(`.${prefixCls}-row-${id}`);
|
313
|
-
const helper = document.body.querySelector(`.${prefixCls}-sort-helper`);
|
314
|
-
if (!helper) return;
|
315
|
-
const tds = node?.querySelectorAll("td");
|
316
|
-
if (!tds) return;
|
317
|
-
requestAnimationFrame(() => {
|
318
|
-
helper.querySelectorAll("td").forEach((td, index) => {
|
319
|
-
if (tds[index]) {
|
320
|
-
td.style.width = getComputedStyle(tds[index]).width;
|
321
|
-
}
|
322
|
-
});
|
323
|
-
});
|
324
|
-
};
|
325
|
-
const getWrapperComp = useCallback(
|
326
|
-
(dataSource: any[], start: number) => (props: any) =>
|
327
|
-
(
|
328
|
-
<SortableBody
|
329
|
-
{...props}
|
330
|
-
start={start}
|
331
|
-
list={dataSource.slice()}
|
332
|
-
accessibility={{
|
333
|
-
container: ref.current || undefined,
|
334
|
-
}}
|
335
|
-
onSortStart={(event) => {
|
336
|
-
addTdStyles(event.active.id as number);
|
337
|
-
}}
|
338
|
-
onSortEnd={({ oldIndex, newIndex }) => {
|
339
|
-
field.move(oldIndex, newIndex);
|
340
|
-
}}
|
341
|
-
className={cls(`${prefixCls}-sort-helper`, props.className)}
|
342
|
-
/>
|
343
|
-
),
|
344
|
-
[field],
|
345
|
-
);
|
346
|
-
return (
|
347
|
-
<ArrayTablePagination {...pagination} dataSource={dataSource}>
|
348
|
-
{(dataSource, pager, { startIndex }) => (
|
349
|
-
<div ref={ref} className={prefixCls}>
|
350
|
-
<ArrayBase onAdd={onAdd} onCopy={onCopy} onRemove={onRemove} onMoveUp={onMoveUp} onMoveDown={onMoveDown}>
|
351
|
-
<Table
|
352
|
-
size="small"
|
353
|
-
bordered
|
354
|
-
rowKey={defaultRowKey}
|
355
|
-
{...props}
|
356
|
-
onChange={() => {}}
|
357
|
-
pagination={false}
|
358
|
-
columns={columns}
|
359
|
-
dataSource={dataSource}
|
360
|
-
components={{
|
361
|
-
body: {
|
362
|
-
wrapper: getWrapperComp(dataSource, startIndex),
|
363
|
-
row: RowComp,
|
364
|
-
},
|
365
|
-
}}
|
366
|
-
/>
|
367
|
-
<div style={{ marginTop: 5, marginBottom: 5 }}>{pager}</div>
|
368
|
-
{sources.map((column, key) => {
|
369
|
-
//专门用来承接对Column的状态管理
|
370
|
-
if (!isColumnComponent(column.schema)) return;
|
371
|
-
return React.createElement(RecursionField, {
|
372
|
-
name: column.name,
|
373
|
-
schema: column.schema,
|
374
|
-
onlyRenderSelf: true,
|
375
|
-
key,
|
376
|
-
});
|
377
|
-
})}
|
378
|
-
{addition}
|
379
|
-
</ArrayBase>
|
380
|
-
</div>
|
381
|
-
)}
|
382
|
-
</ArrayTablePagination>
|
383
|
-
);
|
384
|
-
});
|
385
|
-
|
386
|
-
ArrayTable.displayName = "ArrayTable";
|
387
|
-
|
388
|
-
ArrayTable.Column = () => {
|
389
|
-
return <Fragment />;
|
390
|
-
};
|
391
|
-
|
392
|
-
ArrayBase.mixin(ArrayTable);
|
393
|
-
|
394
|
-
const Addition: ArrayBaseMixins["Addition"] = (props) => {
|
395
|
-
const array = ArrayBase.useArray();
|
396
|
-
const { totalPage = 0, pageSize = 10, changePage, showPagination } = usePagination();
|
397
|
-
return (
|
398
|
-
<ArrayBase.Addition
|
399
|
-
{...props}
|
400
|
-
onClick={(e) => {
|
401
|
-
// 如果添加数据后将超过当前页,则自动切换到下一页
|
402
|
-
const total = array?.field?.value.length || 0;
|
403
|
-
if (showPagination && total === totalPage * pageSize + 1 && isFn(changePage)) {
|
404
|
-
changePage(totalPage + 1);
|
405
|
-
}
|
406
|
-
props.onClick?.(e);
|
407
|
-
}}
|
408
|
-
/>
|
409
|
-
);
|
410
|
-
};
|
411
|
-
ArrayTable.Addition = Addition;
|
412
|
-
|
413
|
-
export default ArrayTable;
|
@@ -1,53 +0,0 @@
|
|
1
|
-
@root-entry-name: 'default';
|
2
|
-
@import (reference) '~antd/es/style/themes/index.less';
|
3
|
-
|
4
|
-
@array-table-prefix-cls: ~'@{ant-prefix}-formily-array-table';
|
5
|
-
|
6
|
-
.@{array-table-prefix-cls} {
|
7
|
-
.@{array-table-prefix-cls}-pagination {
|
8
|
-
display: flex;
|
9
|
-
justify-content: center;
|
10
|
-
|
11
|
-
.@{array-table-prefix-cls}-status-select.has-error {
|
12
|
-
.@{ant-prefix}-select-selector {
|
13
|
-
border-color: @error-color !important;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
.@{ant-prefix}-table {
|
19
|
-
table {
|
20
|
-
overflow: hidden;
|
21
|
-
}
|
22
|
-
|
23
|
-
td {
|
24
|
-
visibility: visible;
|
25
|
-
|
26
|
-
.@{ant-prefix}-formily-item:not(.@{ant-prefix}-formily-item-feedback-layout-popover) {
|
27
|
-
margin-bottom: 0 !important;
|
28
|
-
|
29
|
-
.@{ant-prefix}-formily-item-help {
|
30
|
-
position: absolute;
|
31
|
-
font-size: 12px;
|
32
|
-
top: 100%;
|
33
|
-
background: #fff;
|
34
|
-
width: 100%;
|
35
|
-
margin-top: 3px;
|
36
|
-
padding: 3px;
|
37
|
-
z-index: 1;
|
38
|
-
border-radius: 3px;
|
39
|
-
box-shadow: 0 0 10px #eee;
|
40
|
-
animation: none;
|
41
|
-
transform: translateY(0);
|
42
|
-
opacity: 1;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
.@{array-table-prefix-cls}-sort-helper {
|
49
|
-
background: #fff;
|
50
|
-
border: 1px solid #eee;
|
51
|
-
z-index: 10;
|
52
|
-
}
|
53
|
-
}
|