Ellipsis.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <script>
  2. import Tooltip from 'ant-design-vue/es/tooltip'
  3. import { cutStrByFullLength, getStrFullLength } from '@/components/_util/StringUtil'
  4. /*
  5. const isSupportLineClamp = document.body.style.webkitLineClamp !== undefined;
  6. const TooltipOverlayStyle = {
  7. overflowWrap: 'break-word',
  8. wordWrap: 'break-word',
  9. };
  10. */
  11. export default {
  12. name: 'Ellipsis',
  13. components: {
  14. Tooltip
  15. },
  16. props: {
  17. prefixCls: {
  18. type: String,
  19. default: 'ant-pro-ellipsis'
  20. },
  21. tooltip: {
  22. type: Boolean
  23. },
  24. length: {
  25. type: Number,
  26. required: true
  27. },
  28. lines: {
  29. type: Number,
  30. default: 1
  31. },
  32. fullWidthRecognition: {
  33. type: Boolean,
  34. default: false
  35. }
  36. },
  37. methods: {
  38. getStrDom (str, fullLength) {
  39. return (
  40. <span>{ cutStrByFullLength(str, this.length) + (fullLength > this.length ? '...' : '') }</span>
  41. )
  42. },
  43. getTooltip (fullStr, fullLength) {
  44. return (
  45. <Tooltip>
  46. <template slot="title">{ fullStr }</template>
  47. { this.getStrDom(fullStr, fullLength) }
  48. </Tooltip>
  49. )
  50. }
  51. },
  52. render () {
  53. const { tooltip, length } = this.$props
  54. const str = this.$slots.default.map(vNode => vNode.text).join('')
  55. const fullLength = getStrFullLength(str)
  56. const strDom = tooltip && fullLength > length ? this.getTooltip(str, fullLength) : this.getStrDom(str, fullLength)
  57. return (
  58. strDom
  59. )
  60. }
  61. }
  62. </script>