From 3817434d749c1cf60c55bc7ce159b68449e96471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=AF=BA?= <1253070437@qq.com> Date: Tue, 8 Nov 2022 17:10:03 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9B=B4=E6=96=B0=E3=80=91s-table?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=EF=BC=8C=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=91=E9=A9=AC=E7=BA=B9=E7=9A=84=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=98=BE=E7=A4=BA=E7=94=B1=E5=BC=80=E5=85=B3=E5=8F=98?= =?UTF-8?q?=E4=B8=BA=E9=80=89=E6=8B=A9=E6=A1=86=E6=9B=B4=E7=BE=8E=E8=A7=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Table/index.vue | 80 ++++++++----------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/snowy-admin-web/src/components/Table/index.vue b/snowy-admin-web/src/components/Table/index.vue index 5d11336e..1b799171 100644 --- a/snowy-admin-web/src/components/Table/index.vue +++ b/snowy-admin-web/src/components/Table/index.vue @@ -13,10 +13,8 @@ data() { return { needTotalList: [], - selectedRows: [], selectedRowKeys: [], - localLoading: false, localDataSource: [], localPagination: Object.assign({}, this.pagination), @@ -44,7 +42,7 @@ default: 1 }, size: { - // type: Number, + type: String, default: '10' }, showSizeChanger: { @@ -140,7 +138,7 @@ size: this.size, //this.compSize, size// 改动 showSizeChanger: this.showSizeChanger, showTotal: (total, range) => { - return `${range[0]}-${range[1]}共${total}条` + return `${range[0]}-${range[1]} 共 ${total} 条 ` } })) || false @@ -155,14 +153,9 @@ * @param bool Boolean */ refresh(bool = false) { - bool && - (this.localPagination = Object.assign( - {}, - { - current: 1, - size: this.size - } - )) + bool && (this.localPagination = Object.assign({}, { + current: 1, size: this.size + })) this.loadData() }, /** @@ -173,30 +166,22 @@ */ loadData(pagination, filters, sorter) { this.localLoading = true - const parameter = Object.assign( - { - current: - (pagination && pagination.current) || - (this.showPagination && this.localPagination.current) || - this.pageNum, - size: (pagination && pagination.pageSize) || (this.showPagination && this.localPagination.size) || this.size + const parameter = Object.assign({ + current: (pagination && pagination.current) || + this.showPagination && this.localPagination.current || this.pageNum, + size: (pagination && pagination.pageSize) || + this.showPagination && this.localPagination.pageSize || this.pageSize }, - (sorter && - sorter.field && { - sortField: sorter.field - }) || - {}, - (sorter && - sorter.order && { - sortOrder: sorter.order - }) || - {}, - { + (sorter && sorter.field && { + sortField: sorter.field + }) || {}, + (sorter && sorter.order && { + sortOrder: sorter.order + }) || {}, { ...filters } ) const result = this.data(parameter) - // 对接自己的通用数据接口需要修改下方代码中的 r.current, r.totalCount, r.data // eslint-disable-next-line if ( (typeof result === 'object' || typeof result === 'function') && @@ -213,6 +198,9 @@ current: r.current, // pageNo, // 返回结果中的当前分页数 total: r.total, // totalRows, // 返回结果中的总记录数 showSizeChanger: this.showSizeChanger, + showTotal: (total, range) => { + return `${range[0]}-${range[1]} 共 ${total} 条 ` + }, size: (pagination && pagination.size) || this.localPagination.size })) || false @@ -226,23 +214,21 @@ this.loadData() return } - - // 这里用于判断接口是否有返回 r.totalCount(total) 且 this.showPagination = true 且 current 和 size 存在 且 totalCount 小于等于 current * size 的大小 // 当情况满足时,表示数据不满足分页大小,关闭 table 分页功能 try { - if (['auto', true].includes(this.showPagination) && r.total <= r.pages * this.localPagination.size) { + /* + if ((['auto', true].includes(this.showPagination) && r.total <= (r.pages * this.localPagination.size))) { + this.localPagination.hideOnSinglePage = true + } + */ + if (!this.showPagination) { this.localPagination.hideOnSinglePage = true } } catch (e) { this.localPagination = false } // 返回结果中的数组数据 - if (this.showPagination === false) { - // 因为按住小诺的套路,不分页的直接是在data中,我们在界面中直接就是返回了data - this.localDataSource = r - } else { - this.localDataSource = r.records - } + this.localDataSource = r.records this.localLoading = false }) } @@ -321,7 +307,7 @@ const needTotalItems = this.needTotalList.map((item) => { return ( - {item.title}总计{' '} + {item.title} 总计 {' '} {!item.customRender ? item.total : item.customRender(item.total)} ) @@ -400,24 +386,23 @@ } // 斑马纹 - const changeRowClass = (val) => { + const changeRowClass = (value) => { + const val = value.target.checked this.localSettings.rowClassNameSwitch = val const evenClass = val ? (_record, index) => (index % 2 === 1 ? 'table-striped' : null) : this.rowClassName this.localSettings.rowClassName = evenClass } - return (
{this.$slots.operator && this.$slots.operator()}
{this.toolConfig.striped ? (
- 斑马线 - + >斑马纹 +
) : null} @@ -430,7 +415,6 @@ {tool.icon} ) - if (tool.isPopover) { return (