|
|
@ -8,44 +8,43 @@ interface Props { |
|
|
|
text: string |
|
|
|
text: string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const LineEllipsis:FC<Props> = ({text}:Props) => { |
|
|
|
const LineEllipsis: FC<Props> = ({text}: Props) => { |
|
|
|
const [disabled, setDisabled] = useState(false) |
|
|
|
const [disabled, setDisabled] = useState(false) |
|
|
|
const [isExpansioned, setIsExpansioned] = useState(false) |
|
|
|
const [isExpansioned, setIsExpansioned] = useState(false) |
|
|
|
const [overflow, setOverflow] = useState(false) |
|
|
|
const [overflow, setOverflow] = useState(false) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
useEffect(() => { |
|
|
|
init() |
|
|
|
init() |
|
|
|
},[text]) |
|
|
|
}, [text]) |
|
|
|
|
|
|
|
|
|
|
|
function init () { |
|
|
|
function init() { |
|
|
|
Taro.nextTick(() => { |
|
|
|
Taro.nextTick(() => { |
|
|
|
const query = Taro.createSelectorQuery() |
|
|
|
const query = Taro.createSelectorQuery() |
|
|
|
query.select('#Text').boundingClientRect() |
|
|
|
query.select('#Text').boundingClientRect() |
|
|
|
query.exec((res) => { |
|
|
|
query.exec((res) => { |
|
|
|
console.log({res}) |
|
|
|
|
|
|
|
const height = res[0].height |
|
|
|
const height = res[0].height |
|
|
|
if(height <= 30) { |
|
|
|
if (height <= 105) { |
|
|
|
setDisabled(true) |
|
|
|
setDisabled(true) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
setOverflow(true) |
|
|
|
setOverflow(true) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleExpend (e?: ITouchEvent) { |
|
|
|
function handleExpend(e?: ITouchEvent) { |
|
|
|
e && e.stopPropagation(); |
|
|
|
e && e.stopPropagation(); |
|
|
|
setOverflow(false) |
|
|
|
setOverflow(false) |
|
|
|
setIsExpansioned(true) |
|
|
|
setIsExpansioned(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleHide (e?: ITouchEvent) { |
|
|
|
function handleHide(e?: ITouchEvent) { |
|
|
|
e && e.stopPropagation(); |
|
|
|
e && e.stopPropagation(); |
|
|
|
setOverflow(true) |
|
|
|
setOverflow(true) |
|
|
|
setIsExpansioned(false) |
|
|
|
setIsExpansioned(false) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function toggle () { |
|
|
|
function toggle() { |
|
|
|
if (disabled) return; |
|
|
|
if (disabled) return; |
|
|
|
if (isExpansioned) { |
|
|
|
if (isExpansioned) { |
|
|
|
handleHide(); |
|
|
|
handleHide(); |
|
|
@ -54,37 +53,36 @@ const LineEllipsis:FC<Props> = ({text}:Props) => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<View |
|
|
|
<View |
|
|
|
id="wrap" |
|
|
|
id="wrap" |
|
|
|
style={{ |
|
|
|
style={{ |
|
|
|
position: 'relative', |
|
|
|
position: 'relative', |
|
|
|
color: '#999795', |
|
|
|
color: '#999795', |
|
|
|
fontSize: '25rpx', |
|
|
|
fontSize: '25rpx', |
|
|
|
overflow: overflow ? 'hidden' : 'unset', |
|
|
|
overflow: overflow ? 'hidden' : 'unset', |
|
|
|
height: overflow ? '35rpx' : 'unset', |
|
|
|
height: overflow ? '105rpx' : 'unset', |
|
|
|
lineHeight: overflow ? '35rpx' : '35rpx', |
|
|
|
lineHeight: overflow ? '35rpx' : '35rpx', |
|
|
|
marginTop:'24rpx', |
|
|
|
marginTop: '24rpx', |
|
|
|
}}> |
|
|
|
}}> |
|
|
|
<View id='Text' onClick={toggle}> |
|
|
|
<View id='Text' onClick={toggle}> |
|
|
|
{text} |
|
|
|
{text} |
|
|
|
{!overflow && isExpansioned && ( |
|
|
|
{!overflow && isExpansioned && ( |
|
|
|
<Text className={styles.expansion} onClick={handleHide}> |
|
|
|
<Text className={styles.expansion} onClick={handleHide}> |
|
|
|
收起 |
|
|
|
收起 |
|
|
|
</Text> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
{overflow && ( |
|
|
|
|
|
|
|
<Text |
|
|
|
|
|
|
|
className={styles.expansion} |
|
|
|
|
|
|
|
onClick={handleExpend} |
|
|
|
|
|
|
|
style={{position: 'absolute', top: '0', right: '0', background: '#fff'}}> |
|
|
|
|
|
|
|
...展开 |
|
|
|
|
|
|
|
</Text> |
|
|
|
</Text> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</View> |
|
|
|
</View> |
|
|
|
); |
|
|
|
{overflow && ( |
|
|
|
// }
|
|
|
|
<Text |
|
|
|
|
|
|
|
style={{position: "absolute", top: "70rpx", right: "0", background: "#fff"}} |
|
|
|
|
|
|
|
className={styles.expansion} |
|
|
|
|
|
|
|
onClick={handleExpend}> |
|
|
|
|
|
|
|
. . . 展开 |
|
|
|
|
|
|
|
</Text> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default LineEllipsis; |
|
|
|
export default LineEllipsis; |
|
|
|