dfa5742f860bc0224d368670705bc48743e65bae.svn-base 1.1 KB

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