Merge pull request 'bugfix/custom-table' (#8) from bugfix/custom-table into master
This commit is contained in:
commit
ae5fc57778
|
@ -19,7 +19,6 @@
|
|||
</a-table>
|
||||
</template>
|
||||
<script>
|
||||
import {cloneDeep} from 'lodash'
|
||||
export default {
|
||||
props: {
|
||||
list: {
|
||||
|
@ -47,32 +46,46 @@ export default {
|
|||
selectedRowKeys: {
|
||||
type: Array
|
||||
},
|
||||
selectionRows: {
|
||||
type: Array
|
||||
},
|
||||
canSelect: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
innerSelectedRowKeys: cloneDeep(this.selectedRowKeys) || []
|
||||
innerSelectedRowKeys: [],
|
||||
innerSelectedRows: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 实现单击选中/反选功能
|
||||
customRow(record) {
|
||||
const key = record[this.rowKey]
|
||||
return {
|
||||
class: this.innerSelectedRowKeys.includes(record[this.rowKey]) ? 'ant-table-row-selected' : '',
|
||||
class: this.innerSelectedRowKeys.includes(key) ? 'ant-table-row-selected' : '',
|
||||
on: {
|
||||
click: () => {
|
||||
if(!this.canSelect) {
|
||||
return
|
||||
}
|
||||
if (this.innerSelectedRowKeys.includes(record[this.rowKey])) {
|
||||
this.innerSelectedRowKeys = []
|
||||
if (this.innerSelectedRowKeys.includes(key)) {
|
||||
const findIndex = this.innerSelectedRowKeys.findIndex(k => k == key)
|
||||
this.innerSelectedRowKeys.splice(findIndex, 1)
|
||||
} else {
|
||||
this.innerSelectedRowKeys = [record[this.rowKey]]
|
||||
if(this.multiple) {
|
||||
this.innerSelectedRowKeys.push(key)
|
||||
}
|
||||
else {
|
||||
this.innerSelectedRowKeys = [key]
|
||||
}
|
||||
}
|
||||
this.$emit('update:selectedRowKeys', this.innerSelectedRowKeys)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,8 +95,15 @@ export default {
|
|||
}
|
||||
},
|
||||
watch: {
|
||||
selectedRowKeys () {
|
||||
this.innerSelectedRowKeys = cloneDeep(this.selectedRowKeys)
|
||||
selectedRowKeys (val) {
|
||||
this.innerSelectedRowKeys = val
|
||||
},
|
||||
innerSelectedRowKeys () {
|
||||
this.$emit('update:selectedRowKeys', this.innerSelectedRowKeys)
|
||||
this.innerSelectedRows = this.innerSelectedRowKeys.map((key) => {
|
||||
return this.list.find(item => item[this.rowKey] === key)
|
||||
})
|
||||
this.$emit('update:selectionRows', this.innerSelectedRows)
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
|
Loading…
Reference in New Issue
Block a user