TopBottomLayout.vue 2.15 KB
Newer Older
wangdanlei's avatar
wangdanlei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
<template>
  <div ref="topBottomLayoutCom" class="up-down-layout-com">
    <!-- <dee-fold-pane
      :min-percent="minPercent"
      :default-percent="defaultPercent"
      split="horizontal"
    > -->
    <div ref="topBox" slot="paneL" class="border-box-style border-box-left">
      <slot name="top" />
    </div>
    <div ref="bottomBox" slot="paneR" class="border-box-style border-box-right">
      <slot name="bottom" />
    </div>
    <!-- </dee-fold-pane> -->
  </div>
</template>

<script>
import elementResizeDetectorMaker from 'element-resize-detector'
export default {
  name: 'TopBottomLayout',
  slots: ['top', 'bottom'],
  description: '上下结构',
  data() {
    return {
      minPercent: 10,
      defaultPercent: 15
    }
  },
  mounted() {
    this.$refs.topBox && this.onResize()
  },
  methods: {
    onResize() {
      const that = this
      const erd = elementResizeDetectorMaker()
      const containerHeight = this.$refs.topBottomLayoutCom.offsetHeight - 8
      erd.listenTo(this.$refs.topBox, (ele) => {
        that.$nextTick(() => {
          that.defaultPercent = Math.ceil(ele.offsetHeight / containerHeight * 100)
        })
      })
    }
  }
}
</script>

<style lang='scss'>
.up-down-layout-com {
  height: 100%;
  display: flex;
  flex-direction: column;
  .border-box-style {
    padding: 0;
    height: auto;
    .slot-item-content{
      height: calc(100% - 2px);
    }
  }
  .border-box-left {
    height: auto;
    // min-height: 100%;
    margin-bottom: 8px;
  }
  .border-box-left,
  .border-box-right {
    padding: 8px;
    box-sizing: border-box;
  }
  .border-box-right {
    z-index: 10;
    position: relative;
    flex: 1;
  }
  .panel-wrap {
    padding: 8px;
    height: 100%;
    overflow-y: hidden;
    box-sizing: border-box;
  }
  .splitter-pane-resizer.horizontal {
    opacity: 1;
    background-color: #F1F4F5;
    height: 8px;
    border-bottom: 1px solid #e0e0e0;
    border-top: 1px solid #e0e0e0;
  }
  /* 处理插入的 object 标签占据顶部的高度导致上部逐渐增加进而循环触发 element-resize-detector 的监听事件,导出下面表格逐渐塌落的bug */
  object {
    display: none !important;
  }
}
</style>