Blame view

ant-design-vue-jeecg/src/components/Ellipsis/Ellipsis.vue 1.04 KB
肖超群 authored
1
<script>
肖超群 authored
2
import {cutStrByFullLength, getStrFullLength} from '@/components/_util/StringUtil'
肖超群 authored
3
肖超群 authored
4
5
6
7
8
9
export default {
  name: 'Ellipsis',
  props: {
    prefixCls: {
      type: String,
      default: 'ant-pro-ellipsis'
肖超群 authored
10
    },
肖超群 authored
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
    tooltip: {
      type: Boolean,
      default: true,
    },
    length: {
      type: Number,
      default: 25,
    },
    lines: {
      type: Number,
      default: 1
    },
    fullWidthRecognition: {
      type: Boolean,
      default: false
    }
  },
  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) {
      return (
        <a-tooltip>
          <template slot="title">{text}</template>
          <span>{cutStrByFullLength(text, this.length) + '…'}</span>
        </a-tooltip>
      )
    } else {
      return (<span>{text}</span>)
肖超群 authored
46
47
    }
  }
肖超群 authored
48
}
肖超群 authored
49
</script>