index.vue 7.61 KB
<template>
<<<<<<< HEAD
  <div class="full-container" v-bind="$attrs">
=======
  <div class="full-container">
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
    <el-tooltip placement="top" v-if="hoverStatus">
      <div slot="content">
        <template v-if="$slots.default"><slot></slot></template>
        <template v-else>
          {{ label }}
        </template>
      </div>
<<<<<<< HEAD
      <div :class="['full-text', identification]" :style="{ 'max-width': labelWidth + 'px' }" v-if="textType != 'text' && !haveClose">
        <el-tag type="info" class="full-text" :disable-transitions="false">
          <i class="el-icon-user-solid" v-if="textType == 'user'"></i>
          <template v-if="$slots.default"><slot></slot></template>
          <template v-else>
            {{ label }}
          </template>
        </el-tag>
      </div>
      <div v-if="textType != 'text' && haveClose">
=======
      <div :class="['full-text', identification]" :style="{ width: labelWidth + 'px' }" @mouseenter="hoverFun" v-if="textType != 'text' && !haveClose">
        <el-tag type="info" class="full-text" :disable-transitions="false">
          <i class="el-icon-user-solid" v-if="textType == 'user'"></i>
          {{ label }}
        </el-tag>
      </div>
      <div v-if="textType != 'text' && haveClose" @mouseenter="hoverFun">
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
        <el-tag class="tag-user-closable" :style="{ 'max-width': labelWidth + 'px' }" type="info" :disable-transitions="false" closable @close="handleRemove">
          <i class="el-icon-user-solid" v-if="textType == 'user'"></i>
          <span :class="['full-text-user', { 'user-icon-checked': textType == 'user' && haveClose }, identification]">{{ label }}</span>
        </el-tag>
      </div>
<<<<<<< HEAD
      <div :class="[line ? 'full-text-line' : 'full-text', identification]" :style="{ 'max-width': labelWidth + 'px', '-webkit-line-clamp': line }" v-if="textType == 'text'">
=======
      <div :class="[line ? 'full-text-line' : 'full-text', identification]" @mouseenter="hoverFun" :style="{ width: labelWidth + 'px', '-webkit-line-clamp': line }" v-if="textType == 'text'">
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
        <template v-if="$slots.default"><slot></slot></template>
        <template v-else>
          {{ label }}
        </template>
      </div>
    </el-tooltip>
    <template v-else>
<<<<<<< HEAD
      <div :class="['full-text', identification]" @mouseenter="hoverFun" :style="{ 'max-width': labelWidth + 'px' }" v-if="textType != 'text' && !haveClose">
        <el-tag type="info" class="full-text" :disable-transitions="false">
          <i class="el-icon-user-solid" v-if="textType == 'user'"></i>
          <template v-if="$slots.default"><slot></slot></template>
          <template v-else>
            {{ label }}
          </template>
=======
      <div :class="['full-text', identification]" @mouseenter="hoverFun" :style="{ width: labelWidth + 'px' }" v-if="textType != 'text' && !haveClose">
        <el-tag type="info" class="full-text" :disable-transitions="false">
          <i class="el-icon-user-solid" v-if="textType == 'user'"></i>
          {{ label }}
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
        </el-tag>
      </div>
      <div @mouseenter="hoverFun" v-if="textType != 'text' && haveClose">
        <el-tag class="tag-user-closable" type="info" :style="{ 'max-width': labelWidth + 'px' }" :disable-transitions="false" closable @close="handleRemove">
          <i class="el-icon-user-solid" v-if="textType == 'user'"></i>
          <span :class="['full-text-user', identification]">{{ label }}</span>
        </el-tag>
      </div>
<<<<<<< HEAD
      <div :class="[line ? 'full-text-line' : 'full-text', identification]" @mouseenter="hoverFun" :style="{ 'max-width': labelWidth + 'px', '-webkit-line-clamp': line }" v-if="textType == 'text'">
=======
      <div :class="[line ? 'full-text-line' : 'full-text', identification]" @mouseenter="hoverFun" :style="{ width: labelWidth + 'px', '-webkit-line-clamp': line }" v-if="textType == 'text'">
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
        <template v-if="$slots.default"><slot></slot></template>
        <template v-else>
          {{ label }}
        </template>
      </div>
    </template>
  </div>
</template>
<script>
export default {
  name: 'GLFull',
  data() {
    return {
<<<<<<< HEAD
      hoverStatus: false,
      identification: 'text_' + this.identi
=======
      hoverStatus: false
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
    }
  },
  props: {
    //唯一标识
    identi: {
      type: String,
      default: 'identi'
    },
    //文本
    label: {
      type: String,
      default: ''
    },
    //文本宽度
    labelWidth: {
      type: Number,
      default: 100
    },
    //行数
    line: {
      type: Number,
      default: 0
    },
    textType: {
      type: String,
      default: 'text', // text 文本 user 跟进员工 tag 标签
      validator: function(value) {
        return ['text', 'user', 'tag'].indexOf(value) !== -1
      }
    },
    //是否包含关闭按钮
    haveClose: {
      type: Boolean,
      default: false
    }
  },
<<<<<<< HEAD
  methods: {
    hoverFun() {
      if (this.line > 1) {
        this.hoverStatus = document.querySelector(`.${this.identification}`).scrollHeight - 10 > document.querySelector(`.${this.identification}`).offsetHeight
        return
      }
=======
  computed: {
    identification() {
      return 'text_' + this.identi
    }
  },
  methods: {
    hoverFun() {
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
      if (this.haveClose) {
        //this.hoverStatus = this.identi ? document.querySelector(`.${this.identification}`).scrollWidth > document.querySelector(`.${this.identification}`).offsetWidth : document.querySelector(`.full-text`).scrollWidth > this.labelWidth - 30
        this.hoverStatus = document.querySelector(`.${this.identification}`).scrollWidth > document.querySelector(`.${this.identification}`).offsetWidth
      } else {
        let widthMuti = this.textType == 'user' ? 17 : this.textType == 'tag' ? 20 : 0
        // this.hoverStatus = this.identi ? document.querySelector(`.${this.identification}`).scrollWidth - widthMuti > this.labelWidth : document.querySelector(`.full-text`).scrollWidth > this.labelWidth
        this.hoverStatus = document.querySelector(`.${this.identification}`).scrollWidth - widthMuti > this.labelWidth
      }
<<<<<<< HEAD
    },
    handleRemove() {
      this.$emit('handleRemove', this.$attrs)
=======
      console.log(this.hoverStatus)
    },
    handleRemove() {
      this.$emit('handleRemove')
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
    }
  }
}
</script>
<style scoped lang="scss">
.full-container {
  display: inline-block;
<<<<<<< HEAD
  margin-right: 4px;
  /deep/ {
    .el-tag {
      // margin-right: 10px;
      line-height: 26px;
      height: 26px;
=======
  /deep/ {
    .el-tag {
      height: 26px;
      line-height: 26px;
>>>>>>> 396e1482ded1b79e8dc9f700b1a584ff319bc981
    }
  }
}
.full-text {
  max-width: 100%;
  display: inline-block;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.full-text-user {
  max-width: calc(100% - 14px);
  display: inline-block;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  &.user-icon-checked {
    max-width: calc(100% - 30px);
  }
}
.tag-user-closable {
  display: flex;
  align-items: center;
  /deep/ {
    .el-icon-close {
      margin-top: 2px;
    }
  }
}
.full-text-line {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  word-break: break-all;
}
.el-icon-user-solid {
  color: #75acff;
  margin-right: 3px;
  font-size: 14px;
}
</style>