|
137 | 137 | interface Props { |
138 | 138 | columns: any[], |
139 | 139 | reverseSortFields?: Array<string>, // 颠倒排序的字段数组 |
| 140 | + secondarySortField?: string, // 次级排序字段 |
140 | 141 | dataSource: (params: any) => Promise<IRequestResponsePaginationData<any>>, |
141 | 142 | paginationValidator?: (pagination: IPagination) => boolean, |
142 | 143 | isNeedHideClearSearchTip?: boolean, |
|
167 | 168 |
|
168 | 169 | const props = withDefaults(defineProps<Props>(), { |
169 | 170 | reverseSortFields: () => [], |
| 171 | + secondarySortField: '', |
170 | 172 | needEmptySearchTip: true, |
171 | 173 | paginationValidator: undefined, |
172 | 174 | border: true, |
|
574 | 576 |
|
575 | 577 | // 同时兼容两种后端参数形式:order_field/order_type 和 sort 数组 |
576 | 578 | const sortPrefix = orderType === 'desc' ? '-' : ''; |
577 | | - paramsMemo = { |
578 | | - ...paramsMemo, |
579 | | - order_field: firstSort.sortBy, |
580 | | - order_type: orderType, |
581 | | - sort: [`${sortPrefix}${firstSort.sortBy}`], |
582 | | - }; |
| 579 | + const sortArray = [`${sortPrefix}${firstSort.sortBy}`]; |
| 580 | +
|
| 581 | + const nextParams = { ...paramsMemo }; |
| 582 | +
|
| 583 | + if (props.secondarySortField) { |
| 584 | + if (firstSort.sortBy !== props.secondarySortField.replace(/^-/, '')) { |
| 585 | + sortArray.push(props.secondarySortField); |
| 586 | + } |
| 587 | + delete nextParams.order_field; |
| 588 | + delete nextParams.order_type; |
| 589 | + nextParams.sort = sortArray; |
| 590 | + } else { |
| 591 | + nextParams.order_field = firstSort.sortBy; |
| 592 | + nextParams.order_type = orderType; |
| 593 | + nextParams.sort = sortArray; |
| 594 | + } |
| 595 | +
|
| 596 | + paramsMemo = nextParams; |
583 | 597 | } |
584 | 598 | isLoading.value = true; |
585 | 599 | fetchListData(); |
|
0 commit comments