index.vue 1.79 KB
<template>
  <div class="full-container">
    <el-tooltip placement="top" v-if="hoverStatus">
      <div slot="content">
        <template v-if="$slots.default"><slot></slot></template>
        <template v-else>
          {{ label }}
        </template>
      </div>
      <div :class="[line ? 'full-text-line' : 'full-text']" :style="{ width: labelWidth + 'px', '-webkit-line-clamp': line }">
        <template v-if="$slots.default"><slot></slot></template>
        <template v-else>
          {{ label }}
        </template>
      </div>
    </el-tooltip>
    <div :class="[line ? 'full-text-line' : 'full-text', identification]" v-else @mouseenter="hoverFun" :style="{ width: labelWidth + 'px', '-webkit-line-clamp': line }">
      <template v-if="$slots.default"><slot></slot></template>
      <template v-else>
        {{ label }}
      </template>
    </div>
  </div>
</template>
<script>
export default {
  name: 'GLFull',
  data() {
    return {
      hoverStatus: false
    }
  },
  props: {
    identification: {
      type: String,
      default: ''
    },
    label: {
      type: String,
      default: ''
    },
    labelWidth: {
      type: Number,
      default: 100
    },
    line: {
      type: Number,
      default: 0
    }
  },
  methods: {
    hoverFun() {
      this.hoverStatus = this.identification ? document.querySelector(`.${this.identification}`).scrollWidth > this.labelWidth : document.querySelector(`.full-text`).scrollWidth > this.labelWidth
    }
  }
}
</script>
<style scoped lang="scss">
.full-container {
  display: inline-block;
}
.full-text {
  display: inline-block;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.full-text-line {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  word-break: break-all;
}
</style>