Commit e52dd298eb9a6b2c57448d491a5201bfd194acba
1 parent
b537a6c9
Exists in
master
and in
1 other branch
修改Scheme组件默认分页参数传值,支持搜索与返回值数别名
Showing
1 changed file
with
10 additions
and
7 deletions
Show diff stats
packages/scheme/index.vue
| @@ -280,24 +280,26 @@ export default { | @@ -280,24 +280,26 @@ export default { | ||
| 280 | methods: { | 280 | methods: { |
| 281 | // 查询数据 | 281 | // 查询数据 |
| 282 | async handleSearch(value) { | 282 | async handleSearch(value) { |
| 283 | - const { currentPageAlias = 'currentPage', pageSizeAlias = 'pageSize' } = this.option || {}; | 283 | + const { currPageAlias = 'currPage', pageSizeAlias = 'pageSize' } = this.option || {}; |
| 284 | const param = { | 284 | const param = { |
| 285 | ...this.searchModel, | 285 | ...this.searchModel, |
| 286 | ...value, | 286 | ...value, |
| 287 | - [currentPageAlias]: this.currentPage, | ||
| 288 | - [pageSizeAlias]: this.pageSize | 287 | + [currPageAlias]: this.currentPage, |
| 288 | + [pageSizeAlias]: this.pageSize, | ||
| 289 | }; | 289 | }; |
| 290 | this.doSearch(param); | 290 | this.doSearch(param); |
| 291 | }, | 291 | }, |
| 292 | // 查询数据逻辑 | 292 | // 查询数据逻辑 |
| 293 | async doSearch(param) { | 293 | async doSearch(param) { |
| 294 | + const { totalCountAlias = 'totalCount' } = this.option || {}; | ||
| 294 | if (this.option.searchAPI) { // 配置了自定义查询API的情况 | 295 | if (this.option.searchAPI) { // 配置了自定义查询API的情况 |
| 295 | console.log('searchAPI'); | 296 | console.log('searchAPI'); |
| 296 | this.tableLoading = true; | 297 | this.tableLoading = true; |
| 297 | try { | 298 | try { |
| 298 | - const { result = [], totalCount = 0 } = await this.option.searchAPI(param); | 299 | + const response = await this.option.searchAPI(param) || {}; |
| 300 | + const { result = [] } = response; | ||
| 299 | this.tableData = result; | 301 | this.tableData = result; |
| 300 | - this.totalCount = totalCount; | 302 | + this.totalCount = response[totalCountAlias] || 0; |
| 301 | } catch (error) { | 303 | } catch (error) { |
| 302 | console.error(error); | 304 | console.error(error); |
| 303 | } finally { | 305 | } finally { |
| @@ -308,9 +310,10 @@ export default { | @@ -308,9 +310,10 @@ export default { | ||
| 308 | this.tableLoading = true; | 310 | this.tableLoading = true; |
| 309 | _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`) | 311 | _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`) |
| 310 | .then((response) => { | 312 | .then((response) => { |
| 311 | - const { result: { list = [], totalCount = 0 } = {} } = response || {}; | 313 | + const { result = {} } = response || {}; |
| 314 | + const { list = [] } = result || {}; | ||
| 312 | this.tableData = list; | 315 | this.tableData = list; |
| 313 | - this.totalCount = totalCount; | 316 | + this.totalCount = result[totalCountAlias] || 0; |
| 314 | }) | 317 | }) |
| 315 | .finally(() => { | 318 | .finally(() => { |
| 316 | this.tableLoading = false; | 319 | this.tableLoading = false; |