select-dropdown.vue 1.5 KB
<template>
  <div class="el-select-dropdown el-popper group-select" :style="groupStyle">
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'ElSelectDropdown',
  props: {
    appendToBody: {
      type: Boolean,
      default: true
    },
    domEl: {
      type: Object,
      default: () => {}
    }
  },
  componentName: 'selectyy',
  data() {
    return {
      groupStyle: '',
      includeData: ['el-input__inner', 'placeholder', 'el-select__caret el-input__icon el-icon-arrow-up']
    }
  },
  mounted() {
    if (this.appendToBody) document.body.appendChild(this.$el)
    this.getBoundingClientRect()
    window.addEventListener('resize', this.getBoundingClientRect)
    document.addEventListener('click', e => {
      if (!this.includeData.includes(e.target.className)) {
        this.removeEl()
      }
    })
  },
  methods: {
    getBoundingClientRect() {
      let { left, top } = this.domEl.getBoundingClientRect()
      this.groupStyle = { left: left + 'px', top: top + 45 + 'px' }
    },
    removeEl() {
      document.body.contains(this.$el) && document.body.removeChild(this.$el)
      this.$emit('changeStatu')
    }
  },
  beforeDestroy() {
    this.removeEl()
  }
}
</script>
<style lang="scss" scoped>
.group-select {
  min-width: 284px;
  transform-origin: center top;
  z-index: 10000;
  position: fixed;
  top: 740px;
  left: 600px;

  ::v-deep .el-select-dropdown__item {
    width: 236px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
  }
}
</style>