Skip to content

Commit 42339a0

Browse files
committed
feat: 🎸 ProAddition now can use more than one
1 parent 6932f5c commit 42339a0

File tree

6 files changed

+73
-9
lines changed

6 files changed

+73
-9
lines changed

bun.lockb

23.4 KB
Binary file not shown.

docs/components/demos/ProArrayTableWithShadow.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,57 @@ const schema: ISchema = {
169169
},
170170
title: "添加条目",
171171
},
172+
add2: {
173+
type: "void",
174+
"x-component": "ProArrayTable.ProAddition",
175+
"x-component-props": {
176+
onOk: (
177+
data: any,
178+
ctx: ReturnType<typeof ProArrayTable.useProArrayTableContext>,
179+
) => {
180+
// 如果添加数据后将超过当前页,则自动切换到下一页
181+
const total = ctx?.array.field?.value.length || 0;
182+
if (
183+
total >=
184+
ctx.pagination!.current! * ctx.pagination.pageSize!
185+
) {
186+
ctx.pagination.setPagination((memo) => {
187+
return { ...memo, current: memo.current + 1 };
188+
});
189+
}
190+
191+
ctx.array.field.push(data);
192+
console.log(data);
193+
},
194+
schema: {
195+
type: "void",
196+
properties: {
197+
id: {
198+
title: "ID",
199+
type: "string",
200+
"x-decorator": "FormItem",
201+
"x-component": "Input",
202+
},
203+
domain: {
204+
title: "域名",
205+
"x-decorator": "FormItem",
206+
type: "string",
207+
"x-component": "Input",
208+
},
209+
desc: {
210+
title: "描述",
211+
"x-decorator": "FormItem",
212+
type: "string",
213+
"x-component": "Input.TextArea",
214+
"x-component-props": {
215+
rows: 4,
216+
},
217+
},
218+
},
219+
},
220+
},
221+
title: "演示多个添加共存",
222+
},
172223
},
173224
},
174225
},

docs/components/demos/ShadowFormAll.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ const schema: ISchema = {
6464
layout: "vertical",
6565
},
6666
properties: {
67+
_modal: {
68+
type: "void",
69+
title: "Void内置的Modal",
70+
"x-decorator": "ShadowForm",
71+
"x-component": "ShadowModal",
72+
"x-decorator-props": {
73+
schema: shadowSchema,
74+
},
75+
},
6776
info: {
6877
type: "object",
6978
"x-read-pretty": true,

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,7 @@
6262
"rimraf": "^5.0.5",
6363
"rspress": "latest"
6464
},
65-
"files": ["dist"]
66-
}
65+
"files": [
66+
"dist"
67+
]
68+
}

src/pro-array-table/hooks.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ export const useExpandRender = (index: number) => {
231231

232232
export const useAddition = () => {
233233
const schema = useFieldSchema();
234-
return schema.reduceProperties((addition, schema, key) => {
234+
return schema.reduceProperties((buf, schema, key) => {
235235
if (isAdditionComponent(schema)) {
236-
return <RecursionField schema={schema} name={key} />;
236+
buf.push(<RecursionField schema={schema} name={key} />);
237237
}
238-
return addition;
239-
}, null);
238+
return buf;
239+
}, [] as React.ReactElement[]);
240240
};
241241

242242
export const useShadowComponents = () => {

src/pro-array-table/mixin.pro.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FormProvider, useField, useFieldSchema } from "@formily/react";
22
import { toJS } from "@formily/reactive";
3-
import React, { useContext, useEffect, useRef } from "react";
3+
import React, { useContext, useEffect, useId, useRef } from "react";
44
import { empty, omit, pick } from "../__builtins__";
55
import { Alert, BUTTON_TYPE, Button, Divider, Modal, Space } from "../adaptor";
66
import { ArrayBase } from "../adaptor/adaptor";
@@ -271,13 +271,15 @@ export const ProAddition = ({
271271
React.ComponentProps<typeof Modal>,
272272
"onOk" | "onCancel" | "children"
273273
>) => {
274+
const id = useId();
275+
const actName = `_pro_additino_${id}`;
274276
return (
275277
<React.Fragment>
276-
<ArrayTableShowModal act="_pro_addition" {...props}></ArrayTableShowModal>
278+
<ArrayTableShowModal act={actName} {...props}></ArrayTableShowModal>
277279
<DelegateAction
278280
initLoader={() => empty}
279281
index={Infinity}
280-
act={"_pro_addition"}
282+
act={actName}
281283
></DelegateAction>
282284
</React.Fragment>
283285
);

0 commit comments

Comments
 (0)