diff --git a/packages/core/client/src/workflow/calculators.tsx b/packages/core/client/src/workflow/calculators.tsx index a7e0cf330..f495e9ef0 100644 --- a/packages/core/client/src/workflow/calculators.tsx +++ b/packages/core/client/src/workflow/calculators.tsx @@ -1,13 +1,14 @@ import React from "react"; -import { observer } from "@formily/react"; +import { observer, useForm } from "@formily/react"; import { FormItem } from "@formily/antd"; -import { Cascader, DatePicker, Input, InputNumber, Select } from "antd"; +import { Button, Cascader, Dropdown, Input, InputNumber, Menu, Select } from "antd"; import { css } from "@emotion/css"; +import { PlusOutlined, CloseCircleOutlined } from '@ant-design/icons'; import { instructions, useNodeContext } from "./nodes"; import { useFlowContext } from "./WorkflowCanvas"; import { triggers } from "./triggers"; -import { SchemaComponent, useCompile } from ".."; +import { SchemaComponent, useCollectionManager, useCompile } from ".."; function NullRender() { return null; @@ -370,11 +371,18 @@ export function VariableComponent({ value, onChange, renderSchemaComponent }) { } // NOTE: observer for watching useProps -export const CollectionFieldset = observer(({ value, onChange, useProps }: any) => { - const { fields } = useProps(); +export const CollectionFieldset = observer(({ value, onChange }: any) => { const compile = useCompile(); + const { getCollectionFields } = useCollectionManager(); + const { values: data } = useForm(); + const fields = getCollectionFields(data?.config?.collection) + .filter(field => ( + !field.hidden + && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : false) + )); - const VTypes = { ...VariableTypes, + const VTypes = { + ...VariableTypes, constant: { title: '常量', value: 'constant', @@ -395,34 +403,68 @@ export const CollectionFieldset = observer(({ value, onChange, useProps }: any) } `}> {fields.length - ? fields.map(field => { - const operand = typeof value[field.name] === 'string' - ? parseStringValue(value[field.name], VTypes) - : { type: 'constant', value: value[field.name] }; + ? ( + <> + {fields + .filter(field => field.name in value) + .map(field => { + const operand = typeof value[field.name] === 'string' + ? parseStringValue(value[field.name], VTypes) + : { type: 'constant', value: value[field.name] }; - return ( - - - { - if (next.type !== operand.type && next.type === 'constant') { - onChange({ ...value, [field.name]: null }); - } else { - const { stringify } = VTypes[next.type]; - onChange({ ...value, [field.name]: stringify(next) }); + return ( + + + { + if (next.type !== operand.type && next.type === 'constant') { + onChange({ ...value, [field.name]: null }); + } else { + const { stringify } = VTypes[next.type]; + onChange({ ...value, [field.name]: stringify(next) }); + } + }} + > + {operand.type === 'constant' + ? + : null } - }} - > - {operand.type === 'constant' - ? - : null - } - - - - ); - }) + + + + ) + : null + } + + ) :

请先选择数据表

} diff --git a/packages/core/client/src/workflow/schemas/collection.ts b/packages/core/client/src/workflow/schemas/collection.ts index 62353a50b..acad8ffe9 100644 --- a/packages/core/client/src/workflow/schemas/collection.ts +++ b/packages/core/client/src/workflow/schemas/collection.ts @@ -24,19 +24,7 @@ export const values = { flex-direction: column; ` }, - 'x-component': 'CollectionFieldset', - 'x-component-props': { - useProps() { - const { getCollectionFields } = useCollectionManager(); - const { values: form } = useForm(); - const fields = getCollectionFields(form?.config?.collection) - .filter(field => ( - !field.hidden - && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : false) - )); - return { fields }; - } - } + 'x-component': 'CollectionFieldset' }; export const filter = {