Unverified Commit 48fe38a3 by Sendya

fix: table rowSelection false;

add: table alert example
parent 3b1d4a57
...@@ -249,22 +249,26 @@ export default { ...@@ -249,22 +249,26 @@ export default {
props[k] = this[localKey] props[k] = this[localKey]
return props[k] return props[k]
} }
if (showAlert && k === 'rowSelection') { if (k === 'rowSelection') {
// 重新绑定 rowSelection 事件 if (showAlert && this.rowSelection) {
props[k] = { // 重新绑定 rowSelection 事件
selectedRows: this.selectedRows, props[k] = {
selectedRowKeys: this.selectedRowKeys, selectedRows: this.selectedRows,
onChange: (selectedRowKeys, selectedRows) => { selectedRowKeys: this.selectedRowKeys,
this.updateSelect(selectedRowKeys, selectedRows) onChange: (selectedRowKeys, selectedRows) => {
typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows) this.updateSelect(selectedRowKeys, selectedRows)
typeof this[k].onChange !== 'undefined' && this[k].onChange(selectedRowKeys, selectedRows)
}
} }
return props[k]
} }
// 如果没打算开启 rowSelection 则清空默认的选择项
props[k] = null
return props[k] return props[k]
} }
props[k] = this[k] props[k] = this[k]
return props[k] return props[k]
}) })
const table = ( const table = (
<a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}> <a-table {...{ props, scopedSlots: { ...this.$scopedSlots } }} onChange={this.loadData}>
{this.$slots.default} {this.$slots.default}
......
...@@ -75,14 +75,20 @@ ...@@ -75,14 +75,20 @@
</a-dropdown> </a-dropdown>
</div> </div>
<div>
<a-button @click="tableOption(false)" v-if="optionAlertShow">关闭 alert</a-button>
</div>
<s-table <s-table
ref="table" ref="table"
size="default" size="default"
:columns="columns" :columns="columns"
:data="loadData" :data="loadData"
:alert="{ show: true, clear: () => { this.selectedRowKeys = [] } }" :alert="options.alert"
:rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :rowSelection="options.rowSelection"
> >
<span slot="serial" slot-scope="text, record, index">
{{ index + 1 }}
</span>
<span slot="action" slot-scope="text, record"> <span slot="action" slot-scope="text, record">
<template v-if="$auth('table.update')"> <template v-if="$auth('table.update')">
<a @click="handleEdit(record)">编辑</a> <a @click="handleEdit(record)">编辑</a>
...@@ -216,6 +222,10 @@ export default { ...@@ -216,6 +222,10 @@ export default {
// 表头 // 表头
columns: [ columns: [
{ {
title: '#',
scopedSlots: { customRender: 'serial' }
},
{
title: '规则编号', title: '规则编号',
dataIndex: 'no' dataIndex: 'no'
}, },
...@@ -254,15 +264,44 @@ export default { ...@@ -254,15 +264,44 @@ export default {
return res.result return res.result
}) })
}, },
selectedRowKeys: [], selectedRowKeys: [],
selectedRows: [] selectedRows: [],
// custom table alert & rowSelection
options: {
alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
rowSelection: {
selectedRowKeys: this.selectedRowKeys,
onChange: this.onSelectChange
}
},
optionAlertShow: true
} }
}, },
created () { created () {
this.tableOption(true)
getRoleList({ t: new Date() }) getRoleList({ t: new Date() })
}, },
methods: { methods: {
tableOption (bool) {
if (bool) {
this.options = {
alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
rowSelection: {
selectedRowKeys: this.selectedRowKeys,
onChange: this.onSelectChange
}
}
} else {
this.options = {
alert: false,
rowSelection: null
}
this.optionAlertShow = false
}
},
handleEdit (record) { handleEdit (record) {
this.mdl = Object.assign({}, record) this.mdl = Object.assign({}, record)
console.log(this.mdl) console.log(this.mdl)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment