import React, { useState, useEffect } from 'react'; import { FlowchartFormWrapper, MODELS, useXFlowApp } from '@antv/xflow'; import { Button, message, Select } from 'antd'; import { Position, Size, ColorPicker, InputNumberField, InputField, UploadField, RadioField, } from '../fields'; import { PREFIX } from '../constants'; import { UnityAction } from '@/utils/utils'; import { connect } from "umi"; import { IProps } from '@/components/Flow/index'; interface ExcelInfo { file_name?: string; excel_cols?: any; } export interface IConfig { id?: string; label?: string; x?: number; y?: number; width?: number; height?: number; fontSize?: number; count?: number; fontFill?: string; fill?: string; stroke?: string; muti_version?: string | number; is_start_node?: string | number; bom_template?: string; version_name?: string; data?: any; excel_info?: ExcelInfo; role_list?: string; is_seal?: string | number; } const defaultConfig: IConfig = { muti_version: 1, is_start_node: 0, is_seal: 0, excel_info: { file_name: '' }, }; const Component = (props: any) => { const { config, plugin = {}, roleList } = props; const { updateNode } = plugin; const [options, setOptions] = useState([]); const [fileName, setFileName] = useState(''); const [nodeConfig, setNodeConfig] = useState({ ...defaultConfig, ...config, }); const app = useXFlowApp(); const [meta, setMeta] = useState(null); const onNodeConfigChange = (key: string, value: number | string | object) => { if (key) { setNodeConfig({ ...nodeConfig, [key]: value, }); updateNode({ [key]: value, }); } else if (value instanceof Object) { setNodeConfig({ ...nodeConfig, ...value, }); updateNode({ ...value, }); } }; const onSave = () => { UnityAction.emit('NODE_SAVE', nodeConfig); }; useEffect(() => { if(config.id != nodeConfig.id) { setNodeConfig({ ...defaultConfig, ...config, }); } }, [config]); useEffect(() => { MODELS.GRAPH_META.useValue(app.modelService).then((meta: IProps['meta']) => { setMeta(meta); }); }, []); const updataFileName = (name: string) => { var idx = name?.lastIndexOf('/'); let str = name.substring(idx + 1, name.length); setFileName(str); onNodeConfigChange('version_name', str); }; useEffect(() => { if (config.bom_template) updataFileName(config.bom_template); if (nodeConfig.excel_info?.file_name) updataFileName(nodeConfig.excel_info.file_name); }, [nodeConfig.bom_template, nodeConfig.excel_info.file_name]); // console.log(nodeConfig, config) useEffect(() => { if (!roleList || roleList.length <= 0) return; let op = []; console.log(roleList); roleList .filter(cur => cur.RoleType == 4) .forEach(item => { op.push({ label: `${item.Name}(${item.ID})`, value: item.ID }); }); setOptions(op); console.log(op); }, [roleList]); // const handleFileNameClick = () => { // if (nodeConfig.bom_template) window.open(nodeConfig.bom_template); // }; return (
内容
{ onNodeConfigChange('label', value); }} />
数据
{ onNodeConfigChange('muti_version', value); }} options={[ { label: '是', value: 1 }, { label: '否', value: 0 }, ]} /> { onNodeConfigChange('is_start_node', value); }} options={[ { label: '是', value: 1 }, { label: '否', value: 0 }, ]} /> { onNodeConfigChange('is_seal', value); }} options={[ { label: '是', value: 1 }, { label: '否', value: 0 }, ]} /> {nodeConfig.is_start_node == 1 && ( <> { onNodeConfigChange('version_name', value); }} /> {/* onNodeConfigChange('bom_template', url)} beforeUpload={beforeUpload} /> */} {/*
{fileName}
*/} {fileName} )}