关于内容区和表格自适应的说明

127 阅读1分钟
// 150: 头部导航栏56 + 主体区域下内边距20 + .table-container的上下内边距共40 + .btn-box34
/**
* 一行  106:.formBox(content76 + 上内边距20 + 下外边距10)
* 两行  182:.formBox(content162 + 上内边距20 + 下外边距10)
* 三行  258:.formBox(content228 + 上内边距20 + 下外边距10)
* 四行  334:.formBox(content304 + 上内边距20 + 下外边距10)
* 五行  410:.formBox(content380 + 上内边距20 + 下外边距10)
*/
// 42:分页器42

有两个地方需要根据这个调整:

1、tableHeight

  1. el-table标签设置 :height="tableHeight"
  2. 初始化tableHeight: 0, // 设置表格高度
  3. 页面挂载完成后
// 获取表格高度
this.$nextTick(() => {
  this.tableHeight = window.innerHeight - 150 // 这里的150根据上述的变化
})
// 视窗大小变化时,重设表格高度
window.addEventListener('resize', () => {
  this.tableHeight = window.innerHeight - 150
})
// 就完成啦

但还有一种筛选项超过两行的情况

  1. 在需要折叠的元素上添加v-show="!isCollapse"
  2. el-form同级添加
<div class="arrow-box" @click="isCollapse = !isCollapse">
  <i :class="[isCollapse ? 'rotate1' : 'rotate']" class="el-icon-arrow-down"></i>
</div>
.formBox{
  position: relative;

  .arrow-box {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 16px;
    background-color: rgba(117,161,252,0.12);
    border-radius: 8px 8px 0 0;
    z-index: 999;
    cursor: pointer;
    text-align: center;
    line-height: 16px;
    .rotate {
      transform: scaleY(-1);
      transition: all 0.5s;
    }
    .rotate1 {
      transition: all 0.5s;
    }
  }

}
  1. class="table-container"的元素上添加
:style="`height: calc(100% - ${isCollapse ? 182: 258}px)`"
  1. 初始化 isCollapse: true, 5.动态改变表格高度
watch: {
   isCollapse: function() {
     this.resetTableHeight()
   }
 },
 ...
 // 重设表格高度
resetTableHeight() {
  // 获取表格高度
  this.$nextTick(() => {
    this.tableHeight = this.isCollapse ? window.innerHeight - (150 + 182 + 42) : window.innerHeight - (150 + 258 + 42)
  })
  // 视窗大小变化时,重设表格高度
  window.addEventListener('resize', () => {
    this.tableHeight = this.isCollapse ? window.innerHeight - (150 + 182 + 42) : window.innerHeight - (150 + 258 + 42)
  })
},

2、.table-container

height: calc(100% - 258px); // 只减去el-form高度