【更新】s-table问题修复,同时修改斑马纹的是否显示由开关变为选择框更美观

pull/56/head
小诺 2022-11-08 17:10:03 +08:00 committed by 俞宝山
parent 07f5caf73b
commit 3817434d74
1 changed files with 32 additions and 48 deletions

View File

@ -13,10 +13,8 @@
data() { data() {
return { return {
needTotalList: [], needTotalList: [],
selectedRows: [], selectedRows: [],
selectedRowKeys: [], selectedRowKeys: [],
localLoading: false, localLoading: false,
localDataSource: [], localDataSource: [],
localPagination: Object.assign({}, this.pagination), localPagination: Object.assign({}, this.pagination),
@ -44,7 +42,7 @@
default: 1 default: 1
}, },
size: { size: {
// type: Number, type: String,
default: '10' default: '10'
}, },
showSizeChanger: { showSizeChanger: {
@ -140,7 +138,7 @@
size: this.size, //this.compSize, size// size: this.size, //this.compSize, size//
showSizeChanger: this.showSizeChanger, showSizeChanger: this.showSizeChanger,
showTotal: (total, range) => { showTotal: (total, range) => {
return `${range[0]}-${range[1]}${total}` return `${range[0]}-${range[1]} ${total} `
} }
})) || })) ||
false false
@ -155,14 +153,9 @@
* @param bool Boolean * @param bool Boolean
*/ */
refresh(bool = false) { refresh(bool = false) {
bool && bool && (this.localPagination = Object.assign({}, {
(this.localPagination = Object.assign( current: 1, size: this.size
{}, }))
{
current: 1,
size: this.size
}
))
this.loadData() this.loadData()
}, },
/** /**
@ -173,30 +166,22 @@
*/ */
loadData(pagination, filters, sorter) { loadData(pagination, filters, sorter) {
this.localLoading = true this.localLoading = true
const parameter = Object.assign( const parameter = Object.assign({
{ current: (pagination && pagination.current) ||
current: this.showPagination && this.localPagination.current || this.pageNum,
(pagination && pagination.current) || size: (pagination && pagination.pageSize) ||
(this.showPagination && this.localPagination.current) || this.showPagination && this.localPagination.pageSize || this.pageSize
this.pageNum,
size: (pagination && pagination.pageSize) || (this.showPagination && this.localPagination.size) || this.size
}, },
(sorter && (sorter && sorter.field && {
sorter.field && { sortField: sorter.field
sortField: sorter.field }) || {},
}) || (sorter && sorter.order && {
{}, sortOrder: sorter.order
(sorter && }) || {}, {
sorter.order && {
sortOrder: sorter.order
}) ||
{},
{
...filters ...filters
} }
) )
const result = this.data(parameter) const result = this.data(parameter)
// r.current, r.totalCount, r.data
// eslint-disable-next-line // eslint-disable-next-line
if ( if (
(typeof result === 'object' || typeof result === 'function') && (typeof result === 'object' || typeof result === 'function') &&
@ -213,6 +198,9 @@
current: r.current, // pageNo, // current: r.current, // pageNo, //
total: r.total, // totalRows, // total: r.total, // totalRows, //
showSizeChanger: this.showSizeChanger, showSizeChanger: this.showSizeChanger,
showTotal: (total, range) => {
return `${range[0]}-${range[1]}${total}`
},
size: (pagination && pagination.size) || this.localPagination.size size: (pagination && pagination.size) || this.localPagination.size
})) || })) ||
false false
@ -226,23 +214,21 @@
this.loadData() this.loadData()
return return
} }
// r.totalCount(total) this.showPagination = true current size totalCount current * size
// table // table
try { 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 this.localPagination.hideOnSinglePage = true
} }
} catch (e) { } catch (e) {
this.localPagination = false this.localPagination = false
} }
// //
if (this.showPagination === false) { this.localDataSource = r.records
// datadata
this.localDataSource = r
} else {
this.localDataSource = r.records
}
this.localLoading = false this.localLoading = false
}) })
} }
@ -321,7 +307,7 @@
const needTotalItems = this.needTotalList.map((item) => { const needTotalItems = this.needTotalList.map((item) => {
return ( return (
<span className="mr-3"> <span className="mr-3">
{item.title}总计{' '} {item.title} 总计 {' '}
<a className="font-6">{!item.customRender ? item.total : item.customRender(item.total)}</a> <a className="font-6">{!item.customRender ? item.total : item.customRender(item.total)}</a>
</span> </span>
) )
@ -400,24 +386,23 @@
} }
// //
const changeRowClass = (val) => { const changeRowClass = (value) => {
const val = value.target.checked
this.localSettings.rowClassNameSwitch = val this.localSettings.rowClassNameSwitch = val
const evenClass = val ? (_record, index) => (index % 2 === 1 ? 'table-striped' : null) : this.rowClassName const evenClass = val ? (_record, index) => (index % 2 === 1 ? 'table-striped' : null) : this.rowClassName
this.localSettings.rowClassName = evenClass this.localSettings.rowClassName = evenClass
} }
return ( return (
<div className="s-table-tool"> <div className="s-table-tool">
<div className="s-table-tool-left">{this.$slots.operator && this.$slots.operator()}</div> <div className="s-table-tool-left">{this.$slots.operator && this.$slots.operator()}</div>
<div className="layout-items-center s-table-tool-right"> <div className="layout-items-center s-table-tool-right">
{this.toolConfig.striped ? ( {this.toolConfig.striped ? (
<div className="layout-items-center ml-4"> <div className="layout-items-center ml-4">
<span>斑马线</span> <a-checkbox
<a-switch
checked={this.localSettings.rowClassNameSwitch} checked={this.localSettings.rowClassNameSwitch}
onChange={changeRowClass} onChange={changeRowClass}
className="ml-2" >斑马纹
/> </a-checkbox>
</div> </div>
) : null} ) : null}
@ -430,7 +415,6 @@
{tool.icon} {tool.icon}
</a-tooltip> </a-tooltip>
) )
if (tool.isPopover) { if (tool.isPopover) {
return ( return (
<a-popover <a-popover