Unverified Commit 7b4764e5 by Sendya

fix: ellipsis full length out '...'

parent de7c4ca0
<script> <script>
import Tooltip from 'ant-design-vue/es/tooltip' import Tooltip from 'ant-design-vue/es/tooltip'
import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil' import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil'
/* /*
const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined; const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
const TooltipOverlayStyle = { const TooltipOverlayStyle = {
overflowWrap: 'break-word', overflowWrap: 'break-word',
wordWrap: 'break-word', wordWrap: 'break-word',
}; };
*/ */
export default { export default {
name: 'Ellipsis', name: 'Ellipsis',
...@@ -37,16 +37,16 @@ ...@@ -37,16 +37,16 @@
} }
}, },
methods: { methods: {
getStrDom (str) { getStrDom (str, fullLength) {
return ( return (
<span>{ cutStrByFullLength(str, this.length) + '...' }</span> <span>{ cutStrByFullLength(str, this.length) + (fullLength > this.length ? '...' : '') }</span>
) )
}, },
getTooltip ( fullStr) { getTooltip (fullStr, fullLength) {
return ( return (
<Tooltip> <Tooltip>
<template slot="title">{ fullStr }</template> <template slot="title">{ fullStr }</template>
{ this.getStrDom(fullStr) } { this.getStrDom(fullStr, fullLength) }
</Tooltip> </Tooltip>
) )
} }
...@@ -54,10 +54,11 @@ ...@@ -54,10 +54,11 @@
render () { render () {
const { tooltip, length } = this.$props const { tooltip, length } = this.$props
const str = this.$slots.default.map(vNode => vNode.text).join('') const str = this.$slots.default.map(vNode => vNode.text).join('')
const strDom = tooltip && getStrFullLength(str) > length ? this.getTooltip(str) : this.getStrDom(str) const fullLength = getStrFullLength(str)
const strDom = tooltip && fullLength > length ? this.getTooltip(str, fullLength) : this.getStrDom(str, fullLength)
return ( return (
strDom strDom
) )
} }
} }
</script> </script>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment