displayComponent.tsx 2.13 KB
import React, { memo } from 'react';
import { Button, Typography } from 'antd';
import { useAction } from '@qx/flow';
const { Text } = Typography;
import type { IDisplayComponent, INode } from '@qx/flow';

const paramsEnums: Record<string, string> = {
  STRING: '文本',
  NUMBER: '数字',
  TIME: '日期',
  BOOL: '布尔',
  OBJECT: '对象',
  ARRAY: '数组',
  ANNEX: '附件',
  PIC: '图片',
  FORM: '表单',
  USER: '人员',
  ORG: '部门',
};

const DisplayComponent: React.FC<DisplayComponentProps> = (props) => {
  const { node, nodes } = props;

  const handleChangeName = (newValue: string) => {
    node.name = newValue;
    props.onChange?.([...nodes]);
  };

  const { clickNode } = useAction();

  return (
    <div className="qx-flow-default-node">
      <div className="qx-flow-default-node__header">
        <span className="qx-flow-default-node__title">
          <span className="qx-flow-default-node__title--icon">
            {/* <Icon /> */}
          </span>
          <span className="qx-flow-default-node__title--name">{node.name}</span>
        </span>
      </div>
      {!!node?.data?.params?.length ? (
        <>
          <div className="qx-flow-default-node__content">
            {props?.node?.data?.params.map((_v: any) => {
              return (
                <Text
                  style={{
                    width: '100%',
                    lineHeight: '22px',
                  }}
                  ellipsis={{
                    tooltip: `${paramsEnums?.[_v.type || '']}&nbsp;${
                      _v.title || '未命名'
                    }`,
                  }}
                >
                  {paramsEnums?.[_v.type || '']}&nbsp;{_v.title || '未命名'}
                </Text>
              );
            })}
          </div>
        </>
      ) : (
        <Button
          style={{ marginTop: 8 }}
          type="link"
          size="small"
          // onClick={() => clickNode()}
        >
          设置入参
        </Button>
      )}
    </div>
  );
};

interface DisplayComponentProps extends IDisplayComponent {
  onChange?: (nodes: INode[]) => void;
}

export default memo(DisplayComponent);