// 列设置用jsx实现起来较为困难 import ColumnSetting from './column' export default { props: { pageNo: { default: 1, type: Number, }, pageSize: { default: 10, type: Number, }, loadData: { type: Function, require: true, }, columns: { type: Array, require: true, }, }, data() { return { loading: false, type: '', data: [], pagination: { current: this.pageNo, pageSize: this.pageSize, total: 0, size: 'small', showSizeChanger: true, showQuickJumper: true, showTotal: (total) => `总共${total}条数据` }, sorter: { sortField: '', sortOrder: '', }, columnSettingVisible: false }; }, created() { this.onLoadData() }, methods: { renderColumnSetting() { const props = { visible: this.columnSettingVisible, placement: 'bottomRight' } const on = { visibleChange: (visible) => { this.columnSettingVisible = visible } } return ( this.columnSettingVisible = true}>设置列 { return false }}> { this.columns.map(column => { return ( { column.hidden = !column.hidden }}>{column.title} ) }) } ) }, onLoading() { this.loading = { indicator: } }, onLoaded() { this.loading = false }, onLoadData() { this.onLoading() this.loadData({ pageNo: this.pagination.current, pageSize: this.pagination.pageSize, ...this.sorter }).then((res) => { if (res.rows) { // 普通表格 this.type = 'table' this.data = res.rows this.pagination.total = res.totalRows } else if (res) { // 树形表格 this.type = 'tree' this.data = this.onClearChildren(res) this.pagination = false } this.onLoaded() }) }, onReloadData(refresh = false) { if (refresh && refresh.constructor === Boolean && this.pagination.constructor === Object) { this.pagination.current = this.pageNo this.pagination.pageSize = this.pageSize } this.onLoadData() }, onTableChange(pagination, filters, sorter) { this.pagination = pagination this.sorter = { sortField: sorter.field, sortOrder: sorter.order, } this.onLoadData() }, /** * 清除没有子节点内容的子节点位置 */ onClearChildren(data) { data.forEach(p => { if (p.children) { if (p.children.length) { p.children = this.onClearChildren(p.children) } else { delete p.children } } }) return data }, }, render() { const props = { loading: this.loading, pagination: this.pagination, dataSource: this.data, columns: this.columns.filter(p => !p.hidden), bordered: true, size: 'middle', rowKey: record => record.id, scroll: { x: 'max-content' } } const on = { change: this.onTableChange, ...this.$listeners } return (

{this.$scopedSlots.operator && this.$scopedSlots.operator()}
刷新 { this.type === 'table' && }
{Object.keys(this.$slots).map((name) => ( ))}
) }, }