Commit e52dd298eb9a6b2c57448d491a5201bfd194acba

Authored by Aaron
1 parent b537a6c9
Exists in master and in 1 other branch legacy

修改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 280 methods: {
281 281 // 查询数据
282 282 async handleSearch(value) {
283   - const { currentPageAlias = 'currentPage', pageSizeAlias = 'pageSize' } = this.option || {};
  283 + const { currPageAlias = 'currPage', pageSizeAlias = 'pageSize' } = this.option || {};
284 284 const param = {
285 285 ...this.searchModel,
286 286 ...value,
287   - [currentPageAlias]: this.currentPage,
288   - [pageSizeAlias]: this.pageSize
  287 + [currPageAlias]: this.currentPage,
  288 + [pageSizeAlias]: this.pageSize,
289 289 };
290 290 this.doSearch(param);
291 291 },
292 292 // 查询数据逻辑
293 293 async doSearch(param) {
  294 + const { totalCountAlias = 'totalCount' } = this.option || {};
294 295 if (this.option.searchAPI) { // 配置了自定义查询API的情况
295 296 console.log('searchAPI');
296 297 this.tableLoading = true;
297 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 301 this.tableData = result;
300   - this.totalCount = totalCount;
  302 + this.totalCount = response[totalCountAlias] || 0;
301 303 } catch (error) {
302 304 console.error(error);
303 305 } finally {
... ... @@ -308,9 +310,10 @@ export default {
308 310 this.tableLoading = true;
309 311 _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`)
310 312 .then((response) => {
311   - const { result: { list = [], totalCount = 0 } = {} } = response || {};
  313 + const { result = {} } = response || {};
  314 + const { list = [] } = result || {};
312 315 this.tableData = list;
313   - this.totalCount = totalCount;
  316 + this.totalCount = result[totalCountAlias] || 0;
314 317 })
315 318 .finally(() => {
316 319 this.tableLoading = false;
... ...