Complete posts pagination

pull/3445/head
johnniang 2019-04-10 19:50:10 +08:00
parent 64aa7ef1bc
commit 98426d1ef6
1 changed files with 40 additions and 4 deletions

View File

@ -60,7 +60,7 @@
>查询</a-button> >查询</a-button>
<a-button <a-button
style="margin-left: 8px;" style="margin-left: 8px;"
@click="() => (queryParam = {})" @click="resetParam"
>重置</a-button> >重置</a-button>
</span> </span>
</a-col> </a-col>
@ -97,8 +97,8 @@
}" }"
:columns="columns" :columns="columns"
:dataSource="formattedPosts" :dataSource="formattedPosts"
:pagination="pagination"
:loading="postsLoading" :loading="postsLoading"
:pagination="false"
> >
<span <span
@ -163,6 +163,20 @@
>删除</a> >删除</a>
</span> </span>
</a-table> </a-table>
<a-row
type="flex"
justify="end"
align="middle"
>
<a-pagination
class="pagination"
:total="pagination.total"
:pageSizeOptions="['1', '2', '5', '10', '20', '50', '100']"
showSizeChanger
@showSizeChange="onPaginationChange"
@change="onPaginationChange"
/>
</a-row>
</div> </div>
</a-card> </a-card>
</div> </div>
@ -179,7 +193,11 @@ export default {
return { return {
postStatus: postApi.postStatus, postStatus: postApi.postStatus,
// //
pagination: {}, pagination: {
current: 1,
pageSize: 10,
sort: null
},
queryParam: { queryParam: {
page: 0, page: 0,
size: 10, size: 10,
@ -263,8 +281,9 @@ export default {
loadPosts() { loadPosts() {
this.postsLoading = true this.postsLoading = true
// Set from pagination // Set from pagination
this.queryParam.page = this.pagination.current this.queryParam.page = this.pagination.current - 1
this.queryParam.size = this.pagination.pageSize this.queryParam.size = this.pagination.pageSize
this.queryParam.sort = this.pagination.sort
postApi.query(this.queryParam).then(response => { postApi.query(this.queryParam).then(response => {
this.posts = response.data.data.content this.posts = response.data.data.content
this.pagination.total = response.data.data.total this.pagination.total = response.data.data.total
@ -292,7 +311,24 @@ export default {
name: post.title name: post.title
} }
} }
},
onPaginationChange(page, pageSize) {
this.$log.debug(`Current: ${page}, PageSize: ${pageSize}`)
this.pagination.current = page
this.pagination.pageSize = pageSize
this.loadPosts()
},
resetParam() {
this.queryParam.keyword = null
this.queryParam.categoryId = null
this.queryParam.status = null
} }
} }
} }
</script> </script>
<style scoped>
.pagination {
margin-top: 1rem;
}
</style>