From e52dd298eb9a6b2c57448d491a5201bfd194acba Mon Sep 17 00:00:00 2001 From: Aaron <427787340@qq.com> Date: Wed, 31 Jul 2019 17:10:54 +0800 Subject: [PATCH] 修改Scheme组件默认分页参数传值,支持搜索与返回值数别名 --- packages/scheme/index.vue | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/scheme/index.vue b/packages/scheme/index.vue index 387e9aa..88c559c 100644 --- a/packages/scheme/index.vue +++ b/packages/scheme/index.vue @@ -280,24 +280,26 @@ export default { methods: { // 查询数据 async handleSearch(value) { - const { currentPageAlias = 'currentPage', pageSizeAlias = 'pageSize' } = this.option || {}; + const { currPageAlias = 'currPage', pageSizeAlias = 'pageSize' } = this.option || {}; const param = { ...this.searchModel, ...value, - [currentPageAlias]: this.currentPage, - [pageSizeAlias]: this.pageSize + [currPageAlias]: this.currentPage, + [pageSizeAlias]: this.pageSize, }; this.doSearch(param); }, // 查询数据逻辑 async doSearch(param) { + const { totalCountAlias = 'totalCount' } = this.option || {}; if (this.option.searchAPI) { // 配置了自定义查询API的情况 console.log('searchAPI'); this.tableLoading = true; try { - const { result = [], totalCount = 0 } = await this.option.searchAPI(param); + const response = await this.option.searchAPI(param) || {}; + const { result = [] } = response; this.tableData = result; - this.totalCount = totalCount; + this.totalCount = response[totalCountAlias] || 0; } catch (error) { console.error(error); } finally { @@ -308,9 +310,10 @@ export default { this.tableLoading = true; _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`) .then((response) => { - const { result: { list = [], totalCount = 0 } = {} } = response || {}; + const { result = {} } = response || {}; + const { list = [] } = result || {}; this.tableData = list; - this.totalCount = totalCount; + this.totalCount = result[totalCountAlias] || 0; }) .finally(() => { this.tableLoading = false; -- libgit2 0.21.0