【更新】STable组件加入整行选择

pull/175/head
lingsoul 2023-11-13 15:09:42 +08:00
parent b0b3786bd9
commit 4d01ed6214
1 changed files with 50 additions and 0 deletions

View File

@ -63,6 +63,14 @@
type: Object, type: Object,
default: null default: null
}, },
lineSelection: {
type: Boolean,
default: false
},
customRow: {
type: Function,
default: undefined
},
showPagination: { showPagination: {
type: [String, Boolean], type: [String, Boolean],
default: 'auto' default: 'auto'
@ -470,6 +478,48 @@
return props[k] return props[k]
} }
} }
if (k === 'customRow') {
if (this.lineSelection && this.rowSelection) {
// customRow
props[k] = (record, index) => {
return {
...(typeof this.customRow !== 'undefined' && this.customRow(record, index)),
onClick: (event) => {
// onClick
typeof this[k] !== 'undefined' &&
typeof this[k](record, index).onClick !== 'undefined' &&
this[k](record, index).onClick(event)
// disabled
const rowDisabled =
typeof this.rowSelection.getCheckboxProps !== 'undefined' &&
this.rowSelection.getCheckboxProps(record).disabled
if (rowDisabled) return
//
const classList = event.target?.classList
if (!classList.contains('ant-table-cell')) return
const key = (typeof this.rowKey === 'function' && this.rowKey(record)) || this.rowKey || index
let selectedRows = this.rowSelection.selectedRows
let selectedRowKeys = this.rowSelection.selectedRowKeys
const rowType = this.rowSelection?.type || 'checkbox'
if (rowType === 'radio' || this.rowSelection.selectedRowKeys === undefined) {
selectedRowKeys = [key]
selectedRows = [record]
} else if (!this.rowSelection.selectedRowKeys?.includes(key)) {
selectedRowKeys.push(key)
selectedRows.push(record)
} else {
const index = this.rowSelection.selectedRowKeys?.findIndex((itemKey) => itemKey === key)
selectedRows.splice(index, 1)
selectedRowKeys.splice(index, 1)
}
this.updateSelect(selectedRowKeys, selectedRows)
}
}
}
return props[k]
}
}
this[k] && (props[k] = this[k]) this[k] && (props[k] = this[k])
// //
props = { props = {