Browse Source

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

pull/175/head
lingsoul 1 year ago
parent
commit
4d01ed6214
  1. 50
      snowy-admin-web/src/components/Table/index.vue

50
snowy-admin-web/src/components/Table/index.vue

@ -63,6 +63,14 @@
type: Object,
default: null
},
lineSelection: {
type: Boolean,
default: false
},
customRow: {
type: Function,
default: undefined
},
showPagination: {
type: [String, Boolean],
default: 'auto'
@ -470,6 +478,48 @@
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])
//
props = {

Loading…
Cancel
Save