table.md 5.22 KB

GLTable 表格

基于"element-ui": "2.15.6",将 table 和 Pagination 组件进行了封装,通过配置参数的方式就能快速生成表格。 使用该组件,能够在提高了工作效率的同时,保证了代码的可靠性和健壮性。

使用方式

在你想要使用的组件内,如下使用

(注:table column pagination 属性事件透传,table使用默认的$attr,$listener)

<template>
  <GLTable ref="liveRoomRef" 
    :tableParams="tableParams" 
    :tableData="tableData" 
    :tableTotal="100" 
    header-row-class-name="header-row" 
    @row-click="handleRowClick" 
    :paginationattrs="paginationattrs" 
    :paginationlisteners="paginationlisteners">
  </GLTable>
</template>
<script>
  import { GLTable } from 'glsx-components';
  import 'glsx-components/dist/glsx-components.css';

  export default {
    name: 'demo',
    data() {
      return {
        demo1: true,
        // el分页属性透传
        paginationattrs: {
          'prev-text':'上一页',
          'next-text':'下一页'
        },
        // el分页事件透传
        paginationlisteners: {
          'prev-click':this.prevClickHandle,
          'next-click':this.nextClickHandle
        },
        tableParams: {
          listName: 'list',
          tableOption: false,
          tableColumns: [
            {
              label: '最近开播',
              prop: 'time',
              width: '180',
              formatter: cellValue => {
                return cellValue.startTime + '-' + cellValue.endTime
              },
              // column 属性透传
              columnattrs:{
                'class-name':'custom-class'
              }
            },
            {
              label: '直播间名称',
              prop: 'name',
              line: 1
            },
            {
              label: '房间号',
              prop: 'roomId'
            },
            {
              label: '主播',
              prop: 'anchorName',
              line: 1
            }
          ]
        },
        tableData: [
          {
            name: '王小虎王小虎王小虎王',
            liveStatus3: '132',
            liveStatus4: '789',
            name1: '123',
            name2: '123'
          },
          {
            name: '王小虎王小虎王小虎王',
            liveStatus3: '132',
            liveStatus4: '789',
            name1: '123',
            name2: '123'
          },
          {
            name: '王小虎',
            liveStatus3: '132',
            liveStatus4: '789',
            name1: '123',
            name2: '123'
          },
          {
            name: '王小虎王小虎王小虎王',
            liveStatus3: '132',
            liveStatus4: '789',
            name1: '123',
            name2: '123'
          }
        ]
      }
    },
    methods:{
      btnClick(){
        alert('点击')
      },
      toggleShow(num){
        // console.log(123)
        this['demo' + num] = !this['demo' + num]
      },
      handleRowClick(){
        alert('点击这行')
      },
      prevClickHandle(){
        alert('我是上一页点击事件')
      },
      nextClickHandle(){
        alert('我是下一页点击事件')
      }
    },
    components:{
      GLTable
    }
  }
</script>

Props

Name Description Type Required Default
size medium / small / mini String false medium
height - String false -
noDataImg maxHeight:{ type:String, default:'3000' }, String false -
noDataText - String false 暂无数据
border - Boolean false false
headerStyle - Object false -
tableId 表格需要多传入一个id的情况 String false -
searchForm 搜索条件 Object false -
isCustomHead 是否定制表头 Boolean false false
customHeadShowList 表头展示 Array false []
tableData 表格数据-外部传入 Array false []
tableTotal - Number false 0
getListApi 获取列表接口 Function false -
beforeSearchFn 搜索前操作 Function false () => { return new Promise((resolve, reject) => {resolve();}); }
pageSizes - Array false [10,20,30,40]
hasPage 分页,默认有 Boolean false true
pageConf - Object false {"pageSize":"pageSize","pageNum":"pageNum","totalCount":"totalCount"}
layout 分页组件配置 String false sizes,total,->,prev,pager,next,jumper
hasNum 序号,默认有 Boolean false true
tableParams - Object false {"checkSelectKey":{"default":""},"checkSelectVal":{},"listName":{"default":""},"tableColumns":{}}
paginationattrs el分页组件属性透传 Object false {}
paginationlisteners el分页组件事件透传 Object false {}

Events

Event Name Description Parameters
sortChange 排序 column \ prop \ order
selectionTable 多选 -
setTableFinishFun 表格请求到数据 console.log('表格请求到数据this.data',this.data) -
refreshTable 刷新表格 -

Slots

Name Description Default Slot Content
addHtml 自定义插槽的名字 名字为动态传入
auth-button 按钮插槽的名字 -
additionalContent - -