import React, { useState, useRef, useEffect } from 'react'; import { Popover } from 'antd'; import classNames from 'classnames'; import s from './index.less'; import IconFont from '@/submodule/components/IconFont'; export const ApolloTextLinkDetail = (props: any) => { const { value, origin, formatter, changeEdit, columnConfig, componentAttr } = props; const { disabled } = componentAttr; const newValue = formatter ? formatter(value) : value; if (!newValue) return null; // 以逗号分隔 const arr = newValue.replace(/,/g, ',').split(','); const [dotVisible, setDotVisible] = useState(false); const outer = useRef(null); const inner = useRef(null); const detaWidth = useRef(columnConfig.width || 0); useEffect(() => { const outerTarget: any = outer.current; const innerTarget: any = inner.current; const deta = columnConfig.width - detaWidth.current; if (outerTarget && innerTarget && origin !== 'detailForm') { if (innerTarget.clientWidth > outerTarget.clientWidth + deta) { setDotVisible(true); } else { setDotVisible(false); } } if (deta !== 0) { detaWidth.current = columnConfig.width; } }, [value, columnConfig.width]); const outStyle: any = {}; const innerStyle: any = {}; const itemStyle: any = {}; if (origin === 'detailForm') { outStyle.width = 'auto'; innerStyle.flexWrap = 'wrap'; itemStyle.marginBottom = '5px'; itemStyle.wordBreak = 'break-all'; } return (
{dotVisible ? ( { e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); }} > {arr.map((item: any, i: number) => { return (
{item}
); })}
} >
{ e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); }} > {arr.map((item: any, i: number) => { return ( {item} ); })}
) : (
{ e.stopPropagation(); e.nativeEvent.stopImmediatePropagation(); }} > {arr.map((item: any, i: number) => { return ( {item} ); })}
)}
{origin !== 'detailForm' && !disabled && (
{ changeEdit(); }} >
)} ); };