Skip to content

Commit 5f1d8a8

Browse files
committed
fix: table rowSelection false;
add: table alert example
1 parent 75701a8 commit 5f1d8a8

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

src/components/table/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,26 @@ export default {
249249
props[k] = this[localKey]
250250
return props[k]
251251
}
252-
if (showAlert && k === 'rowSelection') {
253-
// 重新绑定 rowSelection 事件
254-
props[k] = {
255-
selectedRows: this.selectedRows,
256-
selectedRowKeys: this.selectedRowKeys,
257-
onChange: (selectedRowKeys, selectedRows) => {
258-
this.updateSelect(selectedRowKeys, selectedRows)
259-
typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
252+
if (k === 'rowSelection') {
253+
if (showAlert && this.rowSelection) {
254+
// 重新绑定 rowSelection 事件
255+
props[k] = {
256+
selectedRows: this.selectedRows,
257+
selectedRowKeys: this.selectedRowKeys,
258+
onChange: (selectedRowKeys, selectedRows) => {
259+
this.updateSelect(selectedRowKeys, selectedRows)
260+
typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
261+
}
260262
}
263+
return props[k]
261264
}
265+
// 如果没打算开启 rowSelection 则清空默认的选择项
266+
props[k] = null
262267
return props[k]
263268
}
264269
props[k] = this[k]
265270
return props[k]
266271
})
267-
268272
const table = (
269273
<a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}>
270274
{this.$slots.default}

src/views/list/TableList.vue

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,20 @@
7575
</a-dropdown>
7676
</div>
7777

78+
<div>
79+
<a-button @click="tableOption(false)" v-if="optionAlertShow">关闭 alert</a-button>
80+
</div>
7881
<s-table
7982
ref="table"
8083
size="default"
8184
:columns="columns"
8285
:data="loadData"
83-
:alert="{ show: true, clear: () => { this.selectedRowKeys = [] } }"
84-
:rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
86+
:alert="options.alert"
87+
:rowSelection="options.rowSelection"
8588
>
89+
<span slot="serial" slot-scope="text, record, index">
90+
{{ index + 1 }}
91+
</span>
8692
<span slot="action" slot-scope="text, record">
8793
<template v-if="$auth('table.update')">
8894
<a @click="handleEdit(record)">编辑</a>
@@ -215,6 +221,10 @@ export default {
215221
queryParam: {},
216222
// 表头
217223
columns: [
224+
{
225+
title: '#',
226+
scopedSlots: { customRender: 'serial' }
227+
},
218228
{
219229
title: '规则编号',
220230
dataIndex: 'no'
@@ -254,15 +264,44 @@ export default {
254264
return res.result
255265
})
256266
},
257-
258267
selectedRowKeys: [],
259-
selectedRows: []
268+
selectedRows: [],
269+
270+
// custom table alert & rowSelection
271+
options: {
272+
alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
273+
rowSelection: {
274+
selectedRowKeys: this.selectedRowKeys,
275+
onChange: this.onSelectChange
276+
}
277+
},
278+
optionAlertShow: true
260279
}
261280
},
262281
created () {
282+
this.tableOption(true)
263283
getRoleList({ t: new Date() })
264284
},
265285
methods: {
286+
287+
tableOption (bool) {
288+
if (bool) {
289+
this.options = {
290+
alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
291+
rowSelection: {
292+
selectedRowKeys: this.selectedRowKeys,
293+
onChange: this.onSelectChange
294+
}
295+
}
296+
} else {
297+
this.options = {
298+
alert: false,
299+
rowSelection: null
300+
}
301+
this.optionAlertShow = false
302+
}
303+
},
304+
266305
handleEdit (record) {
267306
this.mdl = Object.assign({}, record)
268307
console.log(this.mdl)

0 commit comments

Comments
 (0)