import React, { useState, useEffect, useMemo } from 'react'; import { FlowchartFormWrapper } from '@antv/xflow'; import { Position, Size, ColorPicker, InputNumberField, InputField, SelectField, } from '../fields'; import { PREFIX } from '../constants'; import { connect } from 'umi'; import { UnityAction } from '@/utils/utils'; import { Button, Card } from 'antd'; import AddCondition from '../../components/judgeModal'; import RenderJudge, { JudgeType } from '../../components/judgeComponent'; import { TYPE } from '../auditNode/mapServe'; import { CloseOutlined, PlusOutlined } from '@ant-design/icons'; // export const enum TYPE { // AUDIT, // INITIATOR, // COPYMAN, // } export const enum ComponentName { Inner = 'InnerContactField', Depart = 'DepartmentField', Select = 'DDSelectField', Money = 'MoneyField', MultiSelect = 'DDMultiSelectField', Number = 'NumberField', } export interface IConfig { label?: string; x?: number; y?: number; width?: number; height?: number; count?: number; fontSize?: number; fontFill?: string; fill?: string; stroke?: string; flow_id?: string; flow_node_id?: string; process_code?: string; type: TYPE; // 条件 【此字段存在是为了兼容旧格式】 formItems: string; // 条件组 【新版用此字段】 formItems和formItemsOr同时只能存在一个 formItemsOr: string[]; priority?: number; //优先级 } export interface FormItem { componentName: string; props: { label: string; id: string; options?: string[]; required: boolean; placeholder?: string; }; judge?: JudgeType; } const Component = (props: any) => { const { config, plugin = {}, formData } = props; const { updateNode } = plugin; // const formData: FormItem[] = [ // { // componentName: 'InnerContactField', // props: { // label: '申请人', // id: 'InnerContactField-JEQRQ5VH', // required: true, // }, // }, // { // componentName: 'DepartmentField', // props: { // label: '选择部门', // id: 'DepartmentField_1VALX0GTRNVK0', // required: true, // }, // }, // { // componentName: 'DDSelectField', // props: { // id: 'DDSelectField_LWFCJRK508W0', // label: '文件类型', // options: [ // '{"value":"新增|FT008","key":"option_1IXTB1VDV9EO0"}', // '{"value":"补充|FT009","key":"option_1DVWNV9BNZNK0"}', // ], // required: true, // }, // }, // { // componentName: 'DDSelectField', // props: { // id: 'DDSelectField_21WUQ0OWR7R40', // label: '是否外带', // options: [ // '{"value":"是","key":"option_DUSP6XANFKO0"}', // '{"value":"否","key":"option_CC5VQ63ZLJK0"}', // ], // required: true, // }, // }, // { // componentName: 'MoneyField', // props: { // id: 'MoneyField-JSCUC2GG', // label: '文件金额(元)', // placeholder: '请输入金额', // required: true, // }, // }, // ]; const [nodeConfig, setNodeConfig] = useState({ ...config, }); const formItemsGroup = nodeConfig.formItemsOr || []; const onNodeConfigChange = (key: string, value: number | string | object) => { if (key) { setNodeConfig({ ...nodeConfig, [key]: value, }); updateNode({ type: TYPE.JUDGE, [key]: value, }); } else if (value instanceof Object) { setNodeConfig({ ...nodeConfig, ...value, }); updateNode({ type: TYPE.JUDGE, ...value, }); } }; const onSave = () => { UnityAction.emit('NODE_SAVE', nodeConfig); }; const onAddConditionGroup = () => { onNodeConfigChange('formItemsOr', [...formItemsGroup, '[]']); }; const onRemoveConditionGroup = (index: number) => { let tempGroup = [...formItemsGroup]; tempGroup.splice(index, 1); onNodeConfigChange('formItemsOr', [...tempGroup]); }; const onAddCondition = (values: FormItem[], index: number) => { const getFormItemsStr = (formItems: string) => { let newFormItems: FormItem[] = []; let oldFormItems = JSON.parse(formItems || '[]'); values.forEach((item) => { let id = item.props.id; // 判断是否含有旧的item let oldItem = oldFormItems.find( (formItem: FormItem) => formItem.props.id == id, ); if (oldItem) { newFormItems.push(oldItem); } else { newFormItems.push(item); } }); return JSON.stringify(newFormItems); }; let tempGroup = [...formItemsGroup]; // 更新条件组 tempGroup[index] = getFormItemsStr(tempGroup[index]); onNodeConfigChange('formItemsOr', tempGroup); }; const renderCondition = () => { let Cards: any = []; formItemsGroup.forEach((formItems: string, index: number) => { Cards.push( onRemoveConditionGroup(index)} /> } > onAddCondition(values, index)} /> { let tempGroup = [...formItemsGroup]; tempGroup[index] = JSON.stringify(values); onNodeConfigChange('formItemsOr', tempGroup); }} /> , ); if (index != formItemsGroup.length - 1) { Cards.push(
); } }); return Cards; }; useEffect(() => { setNodeConfig({ ...config, }); }, [config]); return (
内容
{ onNodeConfigChange('label', value); }} />
样式
{ onNodeConfigChange(key, value); }} /> { onNodeConfigChange(key, value); }} /> { onNodeConfigChange('fill', value); }} /> { onNodeConfigChange('stroke', value); }} /> { onNodeConfigChange('count', value); }} />
{ onNodeConfigChange('fontSize', value); }} /> { onNodeConfigChange('fontFill', value); }} />
{ onNodeConfigChange('priority', value); }} /> {renderCondition()}
); }; function RecthServe(props: any) { return ( {(config, plugin) => ( )} ); } export default connect(({ xflow }: any) => ({ auditList: xflow.auditList, formData: xflow.formData, }))(RecthServe);