Commit 491ba9a3cc19ceb97dd9a6448831b64c86e1e475
1 parent
d09406e3
feat: add the parameter sortFn to the table
Showing
6 changed files
with
43 additions
and
6 deletions
CHANGELOG.zh_CN.md
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | |
5 | 5 | - 面包屑支持显示图标 |
6 | 6 | - 新增 tinymce 富文本组件 |
7 | +- 表单新增 submitOnReset 控制是否在重置时重新发起请求 | |
7 | 8 | |
8 | 9 | ### 🎫 Chores |
9 | 10 | |
... | ... | @@ -21,6 +22,7 @@ |
21 | 22 | - 修复菜单没有子节点时显示折叠的问题 |
22 | 23 | - 修复面包屑显示样式问题 |
23 | 24 | - 修复 modal 在 destroyOnClose=true 时多次打开拖拽失效 |
25 | +- 修复表格出现多个 action 列 | |
24 | 26 | |
25 | 27 | # 2.0.0-rc.4 (2020-10-21) |
26 | 28 | ... | ... |
src/components/Table/src/BasicTable.vue
... | ... | @@ -64,7 +64,7 @@ |
64 | 64 | import { ROW_KEY } from './const'; |
65 | 65 | import { PaginationProps } from './types/pagination'; |
66 | 66 | import { deepMerge } from '/@/utils'; |
67 | - import { TableCustomRecord } from 'ant-design-vue/types/table/table'; | |
67 | + import { SorterResult, TableCustomRecord } from 'ant-design-vue/types/table/table'; | |
68 | 68 | import { useEvent } from '/@/hooks/event/useEvent'; |
69 | 69 | |
70 | 70 | import './style/index.less'; |
... | ... | @@ -216,12 +216,22 @@ |
216 | 216 | fetch({ searchInfo: info, page: 1 }); |
217 | 217 | } |
218 | 218 | |
219 | - function handleTableChange(pagination: PaginationProps) { | |
220 | - const { clearSelectOnPageChange } = unref(getMergeProps); | |
219 | + function handleTableChange( | |
220 | + pagination: PaginationProps, | |
221 | + filters: Partial<Record<string, string[]>>, | |
222 | + sorter: SorterResult<any> | |
223 | + ) { | |
224 | + const { clearSelectOnPageChange, sortFn } = unref(getMergeProps); | |
221 | 225 | if (clearSelectOnPageChange) { |
222 | 226 | clearSelectedRowKeys(); |
223 | 227 | } |
224 | 228 | setPagination(pagination); |
229 | + | |
230 | + if (sorter && isFunction(sortFn)) { | |
231 | + const sortInfo = sortFn(sorter); | |
232 | + fetch({ sortInfo }); | |
233 | + return; | |
234 | + } | |
225 | 235 | fetch(); |
226 | 236 | } |
227 | 237 | ... | ... |
src/components/Table/src/const.ts
1 | +import { SorterResult } from 'ant-design-vue/types/table/table'; | |
2 | + | |
1 | 3 | export const ROW_KEY = 'key'; |
2 | 4 | |
3 | 5 | export const PAGE_SIZE_OPTIONS = ['10', '50', '80', '100']; |
... | ... | @@ -10,3 +12,11 @@ export const FETCH_SETTING = { |
10 | 12 | listField: 'items', |
11 | 13 | totalField: 'total', |
12 | 14 | }; |
15 | + | |
16 | +export function DEFAULT_SORT_FN(sortInfo: SorterResult<any>) { | |
17 | + const { field, order } = sortInfo; | |
18 | + return { | |
19 | + field, | |
20 | + order, | |
21 | + }; | |
22 | +} | ... | ... |
src/components/Table/src/hooks/useDataSource.ts
... | ... | @@ -98,6 +98,8 @@ export function useDataSource( |
98 | 98 | ...(useSearchForm ? getFieldsValue() : {}), |
99 | 99 | ...searchInfo, |
100 | 100 | ...(opt ? opt.searchInfo : {}), |
101 | + ...(opt ? opt.sortInfo : {}), | |
102 | + ...(opt ? opt.filterInfo : {}), | |
101 | 103 | }; |
102 | 104 | if (beforeFetch && isFunction(beforeFetch)) { |
103 | 105 | params = beforeFetch(params) || params; | ... | ... |
src/components/Table/src/props.ts
1 | 1 | import type { PropType } from 'vue'; |
2 | 2 | import type { PaginationProps } from './types/pagination'; |
3 | 3 | import type { BasicColumn, FetchSetting, TableSetting } from './types/table'; |
4 | -import type { TableCustomRecord, TableRowSelection } from 'ant-design-vue/types/table/table'; | |
4 | +import type { | |
5 | + SorterResult, | |
6 | + TableCustomRecord, | |
7 | + TableRowSelection, | |
8 | +} from 'ant-design-vue/types/table/table'; | |
5 | 9 | import type { FormProps } from '/@/components/Form/index'; |
6 | -import { FETCH_SETTING } from './const'; | |
10 | +import { DEFAULT_SORT_FN, FETCH_SETTING } from './const'; | |
7 | 11 | |
8 | 12 | // 注释看 types/table |
9 | 13 | export const basicProps = { |
10 | 14 | tableSetting: { |
11 | 15 | type: Object as PropType<TableSetting>, |
12 | 16 | }, |
17 | + | |
18 | + sortFn: { | |
19 | + type: Function as PropType<(sortInfo: SorterResult<any>) => any>, | |
20 | + default: DEFAULT_SORT_FN, | |
21 | + }, | |
22 | + | |
13 | 23 | showTableSetting: { |
14 | 24 | type: Boolean as PropType<boolean>, |
15 | 25 | default: false, | ... | ... |
src/components/Table/src/types/table.ts
... | ... | @@ -28,6 +28,8 @@ export interface RenderEditableCellParams { |
28 | 28 | export interface FetchParams { |
29 | 29 | searchInfo?: any; |
30 | 30 | page?: number; |
31 | + sortInfo?: any; | |
32 | + filterInfo?: any; | |
31 | 33 | } |
32 | 34 | |
33 | 35 | export interface GetColumnsParams { |
... | ... | @@ -75,6 +77,8 @@ export interface TableSetting { |
75 | 77 | } |
76 | 78 | |
77 | 79 | export interface BasicTableProps<T = any> { |
80 | + // 自定义排序方法 | |
81 | + sortFn?: (sortInfo: SorterResult<any>) => any; | |
78 | 82 | // 显示表格设置 |
79 | 83 | showTableSetting?: boolean; |
80 | 84 | tableSetting?: TableSetting; |
... | ... | @@ -106,7 +110,6 @@ export interface BasicTableProps<T = any> { |
106 | 110 | emptyDataIsShowTable?: boolean; |
107 | 111 | // 额外的请求参数 |
108 | 112 | searchInfo?: any; |
109 | - | |
110 | 113 | // 使用搜索表单 |
111 | 114 | useSearchForm?: boolean; |
112 | 115 | // 表单配置 | ... | ... |