Skip to content

Commit 448a433

Browse files
committed
fix: table refresh(bool) reset pageNo = 1
1 parent 19f2b82 commit 448a433

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

src/components/table/index.js

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import T from 'ant-design-vue/es/table/Table'
22
import get from 'lodash.get'
33

44
export default {
5-
data() {
5+
data () {
66
return {
77
needTotalList: [],
88

@@ -55,35 +55,36 @@ export default {
5555
default: false
5656
},
5757
showPagination: {
58+
type: String,
5859
default: 'auto'
5960
}
6061
}),
6162
watch: {
62-
'localPagination.current'(val) {
63+
'localPagination.current' (val) {
6364
this.$router.push({
6465
name: this.$route.name,
6566
params: Object.assign({}, this.$route.params, {
6667
pageNo: val
6768
})
6869
})
6970
},
70-
pageNum(val) {
71+
pageNum (val) {
7172
Object.assign(this.localPagination, {
7273
current: val
7374
})
7475
},
75-
pageSize(val) {
76+
pageSize (val) {
7677
Object.assign(this.localPagination, {
7778
pageSize: val
7879
})
7980
},
80-
showSizeChanger(val) {
81+
showSizeChanger (val) {
8182
Object.assign(this.localPagination, {
8283
showSizeChanger: val
8384
})
8485
}
8586
},
86-
created() {
87+
created () {
8788
this.localPagination = ['auto', true].includes(this.showPagination) && Object.assign({}, this.localPagination, {
8889
current: this.pageNum,
8990
pageSize: this.pageSize,
@@ -93,29 +94,38 @@ export default {
9394
this.loadData()
9495
},
9596
methods: {
96-
refresh() {
97-
this.loadData()
97+
/**
98+
* 表格重新加载方法
99+
* 如果参数为 true, 则强制刷新到第一页
100+
* @param Boolean bool
101+
*/
102+
refresh(bool = false) {
103+
this.loadData(bool ? { current: 1 }: {})
98104
},
99-
loadData(pagination, filters, sorter) {
105+
/**
106+
* 加载数据方法
107+
* @param {Object} pagination 分页选项器
108+
* @param {Object} filters 过滤条件
109+
* @param {Object} sorter 排序条件
110+
*/
111+
loadData (pagination, filters, sorter) {
100112

101113
this.localLoading = true
102-
var result = this.data(
103-
Object.assign({
104-
pageNo: (pagination && pagination.current) ||
105-
this.localPagination.current,
106-
pageSize: (pagination && pagination.pageSize) ||
107-
this.localPagination.pageSize
108-
},
109-
(sorter && sorter.field && {
110-
sortField: sorter.field
111-
}) || {},
112-
(sorter && sorter.order && {
113-
sortOrder: sorter.order
114-
}) || {}, {
115-
...filters
116-
}
117-
)
118-
)
114+
var result = this.data(Object.assign({
115+
pageNo: (pagination && pagination.current) ||
116+
this.localPagination.current,
117+
pageSize: (pagination && pagination.pageSize) ||
118+
this.localPagination.pageSize
119+
},
120+
(sorter && sorter.field && {
121+
sortField: sorter.field
122+
}) || {},
123+
(sorter && sorter.order && {
124+
sortOrder: sorter.order
125+
}) || {}, {
126+
...filters
127+
}
128+
))
119129

120130
// 对接自己的通用数据接口需要修改下方代码中的 r.pageNo, r.totalCount, r.data
121131
if (result instanceof Promise) {
@@ -143,7 +153,7 @@ export default {
143153
})
144154
}
145155
},
146-
initTotalList(columns) {
156+
initTotalList (columns) {
147157
const totalList = []
148158
columns && columns instanceof Array && columns.forEach(column => {
149159
if (column.needTotal) {
@@ -160,7 +170,7 @@ export default {
160170
* @param selectedRowKeys
161171
* @param selectedRows
162172
*/
163-
updateSelect(selectedRowKeys, selectedRows) {
173+
updateSelect (selectedRowKeys, selectedRows) {
164174
this.selectedRows = selectedRows
165175
const list = this.needTotalList
166176
this.needTotalList = list.map(item => {
@@ -223,7 +233,7 @@ export default {
223233
}
224234
},
225235

226-
render() {
236+
render () {
227237
const props = {}
228238
const localKeys = Object.keys(this.$data)
229239
const showAlert = (typeof this.alert === 'object' && this.alert !== null && this.alert.show) || this.alert

src/views/list/TableList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</template>
5050
<a-col :md="!advanced && 8 || 24" :sm="24">
5151
<span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
52-
<a-button type="primary" @click="$refs.table.refresh()">查询</a-button>
52+
<a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
5353
<a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
5454
<a @click="toggleAdvanced" style="margin-left: 8px">
5555
{{ advanced ? '收起' : '展开' }}

0 commit comments

Comments
 (0)