You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { PipelineGlobalParamType, type PipelineGlobalParam } from '@/types';
  2. import { formatEnum } from '@/utils/format';
  3. import { Typography, type SelectProps } from 'antd';
  4. import classNames from 'classnames';
  5. import './index.less';
  6. type FormInfoProps = {
  7. /** 值 */
  8. value?: any;
  9. /** 如果 `value` 是对象,取对象的哪个属性作为值 */
  10. valuePropName?: string;
  11. /** 是否是多行文本 */
  12. textArea?: boolean;
  13. /** 是否是下拉框 */
  14. select?: boolean;
  15. /** 下拉框数据 */
  16. options?: SelectProps['options'];
  17. /** 自定义节点 label、value 的字段 */
  18. fieldNames?: SelectProps['fieldNames'];
  19. /** 全局参数 */
  20. globalParams?: PipelineGlobalParam[] | null;
  21. /** 自定义类名 */
  22. className?: string;
  23. /** 自定义样式 */
  24. style?: React.CSSProperties;
  25. };
  26. /**
  27. * 模拟禁用的输入框,但是内容超长时,hover 时显示所有内容
  28. */
  29. function FormInfo({
  30. value,
  31. valuePropName,
  32. textArea = false,
  33. select = false,
  34. options,
  35. fieldNames,
  36. globalParams,
  37. className,
  38. style,
  39. }: FormInfoProps) {
  40. let showValue = value;
  41. if (value && typeof value === 'object' && valuePropName) {
  42. showValue = value[valuePropName];
  43. const reg = /^\$\{(.*)\}$/;
  44. if (value.fromSelect && Array.isArray(globalParams) && globalParams.length > 0) {
  45. const match = reg.exec(showValue);
  46. if (match) {
  47. const paramName = match[1];
  48. const foundParam = globalParams.find((v) => v.param_name === paramName);
  49. if (foundParam) {
  50. showValue =
  51. foundParam.param_type === PipelineGlobalParamType.Boolean // 布尔类型转换
  52. ? foundParam.param_value
  53. ? 'true'
  54. : 'false'
  55. : foundParam.param_value;
  56. }
  57. }
  58. }
  59. } else if (select === true && options) {
  60. let _options: SelectProps['options'] = options;
  61. if (fieldNames) {
  62. _options = options.map((v) => {
  63. return {
  64. ...v,
  65. label: fieldNames.label && v[fieldNames.label],
  66. value: fieldNames.value && v[fieldNames.value],
  67. options: fieldNames.options && v[fieldNames.options],
  68. };
  69. });
  70. }
  71. showValue = formatEnum(_options)(value);
  72. }
  73. return (
  74. <div
  75. className={classNames(
  76. 'form-info',
  77. {
  78. 'form-info--multiline': textArea,
  79. },
  80. className,
  81. )}
  82. style={style}
  83. >
  84. <Typography.Paragraph ellipsis={textArea ? false : { tooltip: showValue }}>
  85. {showValue}
  86. </Typography.Paragraph>
  87. </div>
  88. );
  89. }
  90. export default FormInfo;