SubElTableColumn.vue 4.43 KB
<template>
  <div class='sub-el-table-column'>
    <el-table-column
      v-for='(item, index) in reverseData'
      :key="index + 'child'"
      :label='item.label'
      :prop='item.prop'
      :width='item.width'
      :min-width='item.minWidth'
      :fixed='item.fixed'
      :align="item.align || 'left'"
      :sortable='item.sortable'
      :render-header='item.renderHeader'
      v-bind='item.columnattrs ? item.columnattrs : {}'
      v-on='item.columnlisteners ? item.columnlisteners : {}'>
      <template slot-scope='scope'>
        <slot v-if='item.addHtml' :name='item.addHtml' :scope='scope.row' :prop='item.prop' :width='item.width'></slot>

        <template v-else-if='item.formatter'>
          <el-popover
            v-if='scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width - 36) / 14) * item.line'
            placement='top' popper-class='base-popper' trigger='hover' :content='item.formatter(scope.row)'>
            <span slot='reference' class='line-ellipsis' :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
              {{ item.formatter(scope.row) | lineEllipsis(item.width, item.line) }}
            </span>
          </el-popover>
          <span v-else class='line-ellipsis' :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
            <!-- {{ item.formatter(scope.row) || '--' }} -->
            {{ item.formatter(scope.row) | tableCellFormat }}
          </span>
        </template>

        <template v-else-if='getListApi'>
          <el-popover
            v-if='scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width - 36) / 14) * item.line'
            placement='top' popper-class='base-popper' trigger='hover' :content='scope.row[item.prop]'>
            <span slot='reference' class='line-ellipsis' :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
              {{ scope.row[item.prop] | lineEllipsis(item.width, item.line) }}
            </span>
          </el-popover>
          <span v-else class='line-ellipsis' :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
            <!-- {{ scope.row[item.prop] || '--' }} -->
            {{ scope.row[item.prop] | tableCellFormat }}
          </span>
        </template>

        <template v-else>
          <!-- 大于10或 20个字节长度 -->

          <el-popover
            v-if='tableData[scope.$index][item.prop] && tableData[scope.$index][item.prop].length >= Math.ceil((item.width - 36) / 14) * item.line'
            placement='top' width='200' trigger='hover' :content='tableData[scope.$index][item.prop]'>
            <span slot='reference' class='line-ellipsis' :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
              {{ tableData[scope.$index][item.prop] | lineEllipsis(item.width, item.line) }}
            </span>
          </el-popover>
          <!-- <span v-else class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }" v-text="tableData[scope.$index][item.prop]"></span> -->
          <span v-else class='line-ellipsis' :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
            <!-- {{ tableData[scope.$index][item.prop] || '--' }} -->
            {{ tableData[scope.$index][item.prop] | tableCellFormat }}
          </span>
        </template>
        <template v-if='item.addSymbol'>
          <span v-text='item.addSymbol'></span>
        </template>
      </template>

      <!-- 递归 -->
      <sub-el-table-column v-if='item.children' :data='item.children' :tableData='tableData'
                           :getListApi='getListApi'></sub-el-table-column>

    </el-table-column>
  </div>
</template>

<script>
// import GlSubTableColumn from '../../GlSubTableColumn'
export default {
  name: 'SubElTableColumn',
  props: {
    data: {
      type: Array,
      default: () => []
    },
    // 表格数据-外部传入
    tableData: {
      type: Array,
      default: () => []
    },
    // 获取列表接口
    getListApi: {
      type: Function,
      default: null
    }
  },
  computed: {
    reverseData() {
      const arr = [...this.data]
      const temp = arr.pop()
      arr.unshift(temp)
      console.log(arr)
      console.log(this.tableData)
      arr.forEach(item => {
        console.log(item.addHtml)
      })
      return arr
    }
  }
  // components: {
  //   GlSubTableColumn
  // }
  // created(){
  //   // console.log('data',this.data)
  // }
}
</script>
<style lang='scss'>
// .sub-el-table-column {
// }
</style>