Ellipsis.vue 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<script>
  import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil'

  export default {
    name: 'Ellipsis',
    props: {
      prefixCls: {
        type: String,
        default: 'ant-pro-ellipsis'
      },
      tooltip: {
12 13
        type: Boolean,
        default: true,
14 15 16
      },
      length: {
        type: Number,
17
        default: 25,
18 19 20 21 22 23 24 25 26 27
      },
      lines: {
        type: Number,
        default: 1
      },
      fullWidthRecognition: {
        type: Boolean,
        default: false
      }
    },
28 29 30 31 32 33 34 35 36 37
    methods: {},
    render() {
      const { tooltip, length } = this.$props
      let text = ''
      // 处理没有default插槽时的特殊情况
      if (this.$slots.default) {
        text = this.$slots.default.map(vNode => vNode.text).join('')
      }
      // 判断是否显示 tooltip
      if (tooltip && getStrFullLength(text) > length) {
38
        return (
39 40 41 42
          <a-tooltip>
            <template slot="title">{text}</template>
            <span>{cutStrByFullLength(text, this.length) + ''}</span>
          </a-tooltip>
43
        )
44 45
      } else {
        return (<span>{text}</span>)
46 47 48 49
      }
    }
  }
</script>