Commit 914ae6d1a6c2441574e41ca4685383c0abcd0004
1 parent
6b95167f
Exists in
master
and in
1 other branch
修复Search显示数量,Scheme支持responseFilter
Showing
2 changed files
with
104 additions
and
37 deletions
Show diff stats
packages/scheme/index.vue
| ... | ... | @@ -330,7 +330,6 @@ export default { |
| 330 | 330 | this._formList = this.formList || []; |
| 331 | 331 | this._tableList = this.tableList || []; |
| 332 | 332 | } |
| 333 | - this.totalCount = this.tableData.length; | |
| 334 | 333 | // 传入axios标准的http库 |
| 335 | 334 | if (this.option.$http) { |
| 336 | 335 | _$http = this.option.$http; |
| ... | ... | @@ -339,7 +338,7 @@ export default { |
| 339 | 338 | mounted() { |
| 340 | 339 | const defaultData = this.value; |
| 341 | 340 | this.totalCount = defaultData.length; |
| 342 | - this.tableDataStatic = defaultData.map(item => { return { ...item, id: item.id || getUUID() } }); | |
| 341 | + this.tableDataStatic = defaultData.map(item => { return { ...item, $pk: item[this.option.primaryKey] || item['$pk'] || getUUID() } }); | |
| 343 | 342 | // 设置自动加载数据 |
| 344 | 343 | if (this.option.auto !== false) { |
| 345 | 344 | this.handleSearch(); |
| ... | ... | @@ -384,17 +383,21 @@ export default { |
| 384 | 383 | }, |
| 385 | 384 | watch: { |
| 386 | 385 | value(val) { |
| 387 | - this.tableData = val; | |
| 388 | - }, | |
| 389 | - tableData: { | |
| 390 | - handler(val) { | |
| 391 | - this.$emit("input", val); | |
| 392 | - this.$emit("change", val); | |
| 393 | - }, | |
| 394 | - deep: true | |
| 386 | + if (!(this.option.searchAPI || _$http && this.option.url)) { | |
| 387 | + const valueData = val.map(item => { return { ...item, $pk: item[this.option.primaryKey] || item['$pk'] || getUUID() } }); | |
| 388 | + this.tableDataStatic = valueData; | |
| 389 | + this.tableData = valueData; | |
| 390 | + } else { | |
| 391 | + this.tableData = val; | |
| 392 | + } | |
| 395 | 393 | }, |
| 396 | 394 | }, |
| 397 | 395 | methods: { |
| 396 | + // 向上反馈组件值 | |
| 397 | + emit() { | |
| 398 | + this.$emit("input", this.tableData); | |
| 399 | + this.$emit("change", this.tableData); | |
| 400 | + }, | |
| 398 | 401 | // 动态改变表格列 |
| 399 | 402 | dynamicChange() { |
| 400 | 403 | this.$forceUpdate(); |
| ... | ... | @@ -422,6 +425,7 @@ export default { |
| 422 | 425 | const { result = [] } = response; |
| 423 | 426 | this.tableData = result; |
| 424 | 427 | this.totalCount = response[totalCountAlias] || 0; |
| 428 | + this.emit(); | |
| 425 | 429 | } catch (error) { |
| 426 | 430 | console.error(error); |
| 427 | 431 | } finally { |
| ... | ... | @@ -431,10 +435,20 @@ export default { |
| 431 | 435 | this.tableLoading = true; |
| 432 | 436 | _$http.get(`${this.option.url.trim('/')}/${this.option.searchMethod || 'page'}?${stringify(param)}`) |
| 433 | 437 | .then((response) => { |
| 434 | - const { result = {} } = response || {}; | |
| 435 | - const { list = [] } = result || {}; | |
| 436 | - this.tableData = list; | |
| 437 | - this.totalCount = result[totalCountAlias] || 0; | |
| 438 | + // 预留 支持全局配置filter | |
| 439 | + const responseFilter = this.option.searchFilter || this.searchFilter; | |
| 440 | + if (responseFilter) { | |
| 441 | + responseFilter(response).then(({ list, total }) => { | |
| 442 | + this.tableData = list; | |
| 443 | + this.totalCount = total; | |
| 444 | + }); | |
| 445 | + } else { | |
| 446 | + const { result = {} } = response || {}; | |
| 447 | + const { list = [] } = result || {}; | |
| 448 | + this.tableData = list; | |
| 449 | + this.totalCount = result[totalCountAlias] || 0; | |
| 450 | + } | |
| 451 | + this.emit(); | |
| 438 | 452 | }) |
| 439 | 453 | .finally(() => { |
| 440 | 454 | this.tableLoading = false; |
| ... | ... | @@ -466,6 +480,7 @@ export default { |
| 466 | 480 | this.tableData = resultData.slice(begin, end); |
| 467 | 481 | this.totalCount = resultData.length; |
| 468 | 482 | this.tableLoading = false; |
| 483 | + this.emit(); | |
| 469 | 484 | }); |
| 470 | 485 | } |
| 471 | 486 | }, |
| ... | ... | @@ -499,8 +514,16 @@ export default { |
| 499 | 514 | const detailMethodFormat = this.option.detailMethod ? `${this.option.detailMethod.trim('/')}/${param[detailPrimaryKey || primaryKey]}` : undefined; |
| 500 | 515 | _$http.get(`${this.option.url.trim('/')}/${detailMethodFormat || defaultDetailMethod}`) |
| 501 | 516 | .then(response => { |
| 502 | - const { result = {} } = response || {}; | |
| 503 | - this.setFormModel(result); | |
| 517 | + // 预留 支持全局配置filter | |
| 518 | + const responseFilter = this.option.detailFilter || this.detailFilter || this.option.resultFilter || this.resultFilter; | |
| 519 | + if (responseFilter) { | |
| 520 | + responseFilter(response).then((result = {}) => { | |
| 521 | + this.setFormModel(result); | |
| 522 | + }); | |
| 523 | + } else { | |
| 524 | + const { result = {} } = response || {}; | |
| 525 | + this.setFormModel(result); | |
| 526 | + } | |
| 504 | 527 | }) |
| 505 | 528 | .finally(() => { |
| 506 | 529 | this.dialogLoading = false; |
| ... | ... | @@ -553,8 +576,16 @@ export default { |
| 553 | 576 | const getMethodFormat = this.option.getMethod ? `${this.option.getMethod.trim('/')}/${param[getPrimaryKey || primaryKey]}` : undefined; |
| 554 | 577 | _$http.get(`${this.option.url.trim('/')}/${getMethodFormat || defaultGetMethod}`) |
| 555 | 578 | .then(response => { |
| 556 | - const { result = {} } = response || {}; | |
| 557 | - this.setFormModel(result); | |
| 579 | + // 预留 支持全局配置filter | |
| 580 | + const responseFilter = this.option.getFilter || this.getFilter || this.option.resultFilter || this.resultFilter; | |
| 581 | + if (responseFilter) { | |
| 582 | + responseFilter(response).then((result = {}) => { | |
| 583 | + this.setFormModel(result); | |
| 584 | + }); | |
| 585 | + } else { | |
| 586 | + const { result = {} } = response || {}; | |
| 587 | + this.setFormModel(result); | |
| 588 | + } | |
| 558 | 589 | }) |
| 559 | 590 | .finally(() => { |
| 560 | 591 | this.dialogLoading = false; |
| ... | ... | @@ -606,19 +637,32 @@ export default { |
| 606 | 637 | const postData = param; |
| 607 | 638 | _$http.post(`${this.option.url.trim('/')}/${this.option.deleteMethod || 'delete'}`, postData) |
| 608 | 639 | .then(response => { |
| 609 | - const { code } = response || {}; | |
| 610 | - if (`${code}` === '0') { | |
| 611 | - this.hideDialog(); | |
| 612 | - this.handleSearch(); | |
| 613 | - if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.deleteSuccess') || '删除成功', type: 'success' }); } | |
| 640 | + // 预留 支持全局配置filter | |
| 641 | + const responseFilter = this.option.deleteFilter || this.deleteFilter || this.option.successFilter || this.successFilter; | |
| 642 | + if (responseFilter) { | |
| 643 | + responseFilter(response).then((success) => { | |
| 644 | + if (success) { | |
| 645 | + this.hideDialog(); | |
| 646 | + this.handleSearch(); | |
| 647 | + if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.submitSuccess') || '删除成功', type: 'success' }); } | |
| 648 | + } | |
| 649 | + }); | |
| 650 | + } else { | |
| 651 | + const { code } = response || {}; | |
| 652 | + if (`${code}` === '0') { | |
| 653 | + this.hideDialog(); | |
| 654 | + this.handleSearch(); | |
| 655 | + if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.editSuccess') || '删除成功', type: 'success' }); } | |
| 656 | + } | |
| 614 | 657 | } |
| 615 | 658 | }) |
| 616 | 659 | .finally(() => { |
| 617 | 660 | this.dialogLoading = false; |
| 618 | 661 | }); |
| 619 | 662 | } else { |
| 663 | + console.log(selection, this.tableDataStatic) | |
| 620 | 664 | selection.forEach(slt => { |
| 621 | - this.tableDataStatic = this.tableDataStatic.filter(item => item.id !== slt.id); | |
| 665 | + this.tableDataStatic = this.tableDataStatic.filter(item => item['$pk'] !== slt['$pk']); | |
| 622 | 666 | }); |
| 623 | 667 | this.hideDialog(); |
| 624 | 668 | this.handleSearch(); |
| ... | ... | @@ -689,18 +733,30 @@ export default { |
| 689 | 733 | delete postData[formPrimaryKey || primaryKey]; |
| 690 | 734 | _$http.post(`${this.option.url.trim('/')}/${this.option.newMethod || 'add'}`, postData) |
| 691 | 735 | .then(response => { |
| 692 | - const { code } = response || {}; | |
| 693 | - if (`${code}` === '0') { | |
| 694 | - this.hideDialog(); | |
| 695 | - this.handleSearch(); | |
| 696 | - if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.submitSuccess') || '提交成功', type: 'success' }); } | |
| 736 | + // 预留 支持全局配置filter | |
| 737 | + const responseFilter = this.option.newFilter || this.newFilter || this.option.successFilter || this.successFilter; | |
| 738 | + if (responseFilter) { | |
| 739 | + responseFilter(response).then((success) => { | |
| 740 | + if (success) { | |
| 741 | + this.hideDialog(); | |
| 742 | + this.handleSearch(); | |
| 743 | + if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.submitSuccess') || '提交成功', type: 'success' }); } | |
| 744 | + } | |
| 745 | + }); | |
| 746 | + } else { | |
| 747 | + const { code } = response || {}; | |
| 748 | + if (`${code}` === '0') { | |
| 749 | + this.hideDialog(); | |
| 750 | + this.handleSearch(); | |
| 751 | + if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.submitSuccess') || '提交成功', type: 'success' }); } | |
| 752 | + } | |
| 697 | 753 | } |
| 698 | 754 | }) |
| 699 | 755 | .finally(() => { |
| 700 | 756 | this.dialogLoading = false; |
| 701 | 757 | }); |
| 702 | 758 | } else { |
| 703 | - this.tableDataStatic.unshift({ ...param, id: param.id || getUUID() }); | |
| 759 | + this.tableDataStatic.unshift({ ...param, $pk: param.id || getUUID() }); | |
| 704 | 760 | this.totalCount = this.tableDataStatic.length; |
| 705 | 761 | this.hideDialog(); |
| 706 | 762 | this.handleSearch(); |
| ... | ... | @@ -726,18 +782,29 @@ export default { |
| 726 | 782 | this.dialogLoading = true; |
| 727 | 783 | _$http.post(`${this.option.url.trim('/')}/${this.option.editMethod || 'update'}`, param) |
| 728 | 784 | .then(response => { |
| 729 | - const { code } = response || {}; | |
| 730 | - if (`${code}` === '0') { | |
| 731 | - this.hideDialog(); | |
| 732 | - this.handleSearch(); | |
| 733 | - if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.editSuccess') || '编辑成功', type: 'success' }); } | |
| 785 | + const responseFilter = this.option.editFilter || this.editFilter || this.option.successFilter || this.successFilter; | |
| 786 | + if (responseFilter) { | |
| 787 | + responseFilter(response).then((success) => { | |
| 788 | + if (success) { | |
| 789 | + this.hideDialog(); | |
| 790 | + this.handleSearch(); | |
| 791 | + if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.submitSuccess') || '编辑成功', type: 'success' }); } | |
| 792 | + } | |
| 793 | + }); | |
| 794 | + } else { | |
| 795 | + const { code } = response || {}; | |
| 796 | + if (`${code}` === '0') { | |
| 797 | + this.hideDialog(); | |
| 798 | + this.handleSearch(); | |
| 799 | + if (this.$message) { this.$message({ message: this.i18n('eagle.scheme.editSuccess') || '编辑成功', type: 'success' }); } | |
| 800 | + } | |
| 734 | 801 | } |
| 735 | 802 | }) |
| 736 | 803 | .finally(() => { |
| 737 | 804 | this.dialogLoading = false; |
| 738 | 805 | }); |
| 739 | 806 | } else { |
| 740 | - this.$set(this.tableDataStatic, this.tableDataStatic.findIndex(item => item.id === param.id), { ...param, id: param.id || getUUID() }); | |
| 807 | + this.$set(this.tableDataStatic, this.tableDataStatic.findIndex(item => item['$pk'] === param['$pk']), { ...param, $pk: param['$pk'] || getUUID() }); | |
| 741 | 808 | this.hideDialog(); |
| 742 | 809 | this.handleSearch(); |
| 743 | 810 | } | ... | ... |
packages/search/index.vue
| ... | ... | @@ -27,7 +27,7 @@ |
| 27 | 27 | <el-button-group v-else> |
| 28 | 28 | <el-button size="small" type="primary" :loading="searching" @click="handleSearch" icon="el-icon-search">{{ i18n('eagle.search.search') || '查询' }}</el-button> |
| 29 | 29 | <el-button size="small" @click="handleReset">{{ i18n('eagle.search.reset') || '重置' }}</el-button> |
| 30 | - <el-button size="small" v-if="list.length > visibleColNum" :icon="collapse ? 'ios-arrow-down' : 'ios-arrow-up'" @click="handleCollapse"> | |
| 30 | + <el-button size="small" v-if="list.length > visibleColNum - 1" :icon="collapse ? 'ios-arrow-down' : 'ios-arrow-up'" @click="handleCollapse"> | |
| 31 | 31 | {{ collapse ? i18n('eagle.search.unfold') || '展开' : i18n('eagle.search.fold') || '收起' }} |
| 32 | 32 | </el-button> |
| 33 | 33 | </el-button-group> | ... | ... |