Ellipsis.vue 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
<script>
  import Tooltip from 'ant-design-vue/es/tooltip'
  import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil'
/*
  const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;

  const TooltipOverlayStyle = {
    overflowWrap: 'break-word',
    wordWrap: 'break-word',
  };
*/

  export default {
    name: 'Ellipsis',
    components: {
      Tooltip
    },
    props: {
      prefixCls: {
        type: String,
        default: 'ant-pro-ellipsis'
      },
      tooltip: {
        type: Boolean
      },
      length: {
        type: Number,
        required: true
      },
      lines: {
        type: Number,
        default: 1
      },
      fullWidthRecognition: {
        type: Boolean,
        default: false
      }
    },
    methods: {
      getStrDom (str) {
        return (
          <span>{ cutStrByFullLength(str, this.length) + '...' }</span>
        )
      },
      getTooltip ( fullStr) {
        return (
          <Tooltip>
            <template slot="title">{ fullStr }</template>
            { this.getStrDom(fullStr) }
          </Tooltip>
        )
      }
    },
    render () {
      const { tooltip, length } = this.$props
      let str = this.$slots.default.map(vNode => vNode.text).join("")
      const strDom = tooltip && getStrFullLength(str) > length ? this.getTooltip(str) : this.getStrDom(str);
      return (
        strDom
      )
    }
  }
</script>