diff --git a/packages/client/src/workflow/calculators.tsx b/packages/client/src/workflow/calculators.tsx index a98b15069..7b459d6ec 100644 --- a/packages/client/src/workflow/calculators.tsx +++ b/packages/client/src/workflow/calculators.tsx @@ -65,7 +65,7 @@ export function parseStringValue(value: string, Types) { return { type, - options: paths.length ? (Types || VariableTypes)[type].parse(paths) : {} + options: paths.length ? (Types || VariableTypes)[type]?.parse(paths) : {} }; } @@ -252,7 +252,7 @@ export function Operand({ const { type } = operand; - const { component, appendTypeValue } = Types[type]; + const { component, appendTypeValue } = Types[type] || {}; const VariableComponent = typeof component === 'function' ? component(operand) : NullRender; return ( diff --git a/packages/client/src/workflow/nodes/create.tsx b/packages/client/src/workflow/nodes/create.tsx new file mode 100644 index 000000000..1b609266e --- /dev/null +++ b/packages/client/src/workflow/nodes/create.tsx @@ -0,0 +1,156 @@ +import React from 'react'; +import { observer, useForm } from '@formily/react'; +import { action } from '@formily/reactive'; +import { Select } from 'antd'; +import { t } from 'i18next'; +import { css } from '@emotion/css'; + +import { SchemaComponent, useCollectionManager } from '../..'; +import { useCollectionFilterOptions } from '../../collection-manager/action-hooks'; +import { useFlowContext } from '../WorkflowCanvas'; +import { Operand, parseStringValue, VariableTypes, VariableTypesContext, BaseTypeSet } from '../calculators'; +import { FormItem } from '@formily/antd'; + +export default { + title: '新增', + type: 'create', + group: 'model', + fieldset: { + collection: { + type: 'string', + title: '数据表', + name: 'collection', + required: true, + 'x-reactions': ['{{useCollectionDataSource()}}'], + 'x-decorator': 'FormItem', + 'x-component': 'Select', + }, + // multiple: { + // type: 'boolean', + // title: '多条数据', + // name: 'multiple', + // 'x-decorator': 'FormItem', + // 'x-component': 'Checkbox', + // 'x-component-props': { + // disabled: true + // } + // }, + params: { + type: 'object', + name: 'params', + title: '数据', + 'x-decorator': 'FormItem', + properties: { + values: { + type: 'object', + title: '', + name: 'values', + 'x-component': 'DynamicFieldset', + 'x-component-props': { + useProps() { + const { values } = useForm(); + return { fields: useCollectionFilterOptions(values.collection) }; + } + } + } + } + } + }, + view: { + + }, + scope: { + useCollectionDataSource() { + return (field: any) => { + const { collections = [] } = useCollectionManager(); + action.bound((data: any) => { + field.dataSource = data.map(item => ({ + label: t(item.title), + value: item.name + })); + })(collections); + } + } + }, + components: { + // NOTE: observer for watching useProps + DynamicFieldset: observer(({ value, onChange, useProps }: any) => { + const { fields } = useProps(); + + const VTypes = { ...VariableTypes, + constant: { + title: '常量', + value: 'constant', + options: undefined + } + }; + + return ( +
+ ); + }) + }, + getter({ type, options, onChange }) { + const { collections = [] } = useCollectionManager(); + const { nodes } = useFlowContext(); + const { config } = nodes.find(n => n.id == options.nodeId); + const collection = collections.find(item => item.name === config.collection) ?? { fields: [] }; + + return ( + + ); + } +}; diff --git a/packages/client/src/workflow/nodes/index.tsx b/packages/client/src/workflow/nodes/index.tsx index e55185d6e..96a65715b 100644 --- a/packages/client/src/workflow/nodes/index.tsx +++ b/packages/client/src/workflow/nodes/index.tsx @@ -12,6 +12,7 @@ import { AddButton, useFlowContext } from '../WorkflowCanvas'; import { nodeClass, nodeCardClass, nodeHeaderClass, nodeTitleClass, nodeBlockClass } from '../style'; import query from './query'; +import create from './create'; import condition from './condition'; import parallel from './parallel'; import calculation from './calculation'; @@ -59,6 +60,7 @@ export interface Instruction { export const instructions = new Registry