@gx-design-vue/pro-table 0.2.0-alpha.8 → 0.2.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ProTable.d.ts +14 -492
- package/dist/ProTable.js +818 -518
- package/dist/components/ScrollBar/Bar.d.ts +81 -0
- package/dist/components/ScrollBar/Bar.js +84 -0
- package/dist/components/ScrollBar/Thumb.d.ts +52 -0
- package/dist/components/ScrollBar/{Thumb/index.js → Thumb.js} +67 -55
- package/dist/components/ScrollBar/context.d.ts +3 -4
- package/dist/components/ScrollBar/context.js +3 -3
- package/dist/components/ScrollBar/util.d.ts +6 -5
- package/dist/components/ScrollBar/util.js +1 -12
- package/dist/components/SearchForm/CollapseToggle.d.ts +55 -0
- package/dist/components/SearchForm/CollapseToggle.js +47 -0
- package/dist/components/SearchForm/FormItemContainer.d.ts +75 -0
- package/dist/components/SearchForm/FormItemContainer.js +225 -0
- package/dist/components/SearchForm/FormItemWrapper.d.ts +82 -0
- package/dist/components/SearchForm/FormItemWrapper.js +62 -0
- package/dist/components/SearchForm/SearchForm.d.ts +130 -0
- package/dist/components/SearchForm/SearchForm.js +319 -0
- package/dist/components/SearchForm/index.d.ts +2 -0
- package/dist/components/SearchForm/index.js +2 -0
- package/dist/components/Toolbar/FullscreenIcon.d.ts +26 -0
- package/dist/components/Toolbar/FullscreenIcon.js +22 -0
- package/dist/components/Toolbar/ListToolBar.d.ts +111 -0
- package/dist/components/Toolbar/ListToolBar.js +101 -0
- package/dist/components/Toolbar/index.d.ts +103 -0
- package/dist/components/Toolbar/index.js +101 -0
- package/dist/components/Toolbar/style.d.ts +8 -0
- package/dist/components/{ListToolBar → Toolbar}/style.js +32 -27
- package/dist/context/TableContext.d.ts +15 -27
- package/dist/context/TableContext.js +3 -3
- package/dist/hooks/index.d.ts +16 -0
- package/dist/hooks/index.js +16 -0
- package/dist/hooks/useBreakpoints.d.ts +13 -0
- package/dist/hooks/useBreakpoints.js +57 -0
- package/dist/hooks/useCellRender.d.ts +13 -0
- package/dist/hooks/useCellRender.js +28 -0
- package/dist/hooks/useColumnResize.d.ts +30 -0
- package/dist/hooks/useColumnResize.js +110 -0
- package/dist/hooks/useColumns.d.ts +35 -24
- package/dist/hooks/useColumns.js +89 -56
- package/dist/hooks/useFetchData.d.ts +40 -65
- package/dist/hooks/useFetchData.js +157 -172
- package/dist/hooks/useFitPage.d.ts +19 -0
- package/dist/hooks/useFitPage.js +90 -0
- package/dist/hooks/useKeepAliveReload.d.ts +21 -0
- package/dist/hooks/useKeepAliveReload.js +24 -0
- package/dist/hooks/useLoading.d.ts +18 -7
- package/dist/hooks/useLoading.js +26 -8
- package/dist/hooks/usePagination.d.ts +10 -7
- package/dist/hooks/usePagination.js +37 -26
- package/dist/hooks/useRequestOptions.d.ts +18 -0
- package/dist/hooks/useRequestOptions.js +39 -0
- package/dist/hooks/useRowSelection.d.ts +27 -15
- package/dist/hooks/useRowSelection.js +92 -77
- package/dist/hooks/useTable.d.ts +19 -77
- package/dist/hooks/useTable.js +66 -54
- package/dist/hooks/useTableForm.d.ts +15 -83
- package/dist/hooks/useTableForm.js +93 -57
- package/dist/hooks/useTableScroll.d.ts +33 -31
- package/dist/hooks/useTableScroll.js +71 -26
- package/dist/hooks/useTableSize.d.ts +17 -7
- package/dist/hooks/useTableSize.js +20 -6
- package/dist/index.d.ts +10 -7
- package/dist/index.js +9 -3
- package/dist/interface.d.ts +492 -0
- package/dist/pro-table.esm.js +3512 -3965
- package/dist/pro-table.js +1 -1
- package/dist/style/fit-page.d.ts +4 -2
- package/dist/style/fit-page.js +9 -3
- package/dist/style/index.d.ts +4 -6
- package/dist/style/index.js +24 -74
- package/dist/style/list.d.ts +4 -2
- package/dist/style/list.js +1 -10
- package/dist/style/resizable.d.ts +8 -0
- package/dist/style/resizable.js +18 -0
- package/dist/style/scroll.d.ts +4 -2
- package/dist/style/scroll.js +8 -6
- package/dist/style/search.d.ts +8 -0
- package/dist/{components/Form/style.js → style/search.js} +22 -8
- package/dist/theme/augment.d.ts +8 -0
- package/dist/theme/interface/components.d.ts +8 -0
- package/dist/utils/dateFormat.d.ts +9 -0
- package/dist/utils/dateFormat.js +29 -0
- package/dist/utils/formConstants.d.ts +9 -0
- package/dist/utils/formConstants.js +29 -0
- package/dist/utils/valueFormat.d.ts +9 -0
- package/dist/utils/valueFormat.js +27 -0
- package/package.json +10 -9
- package/dist/components/Form/components/RequestSelect.d.ts +0 -50
- package/dist/components/Form/components/RequestSelect.js +0 -56
- package/dist/components/Form/hooks/useForm.d.ts +0 -11
- package/dist/components/Form/hooks/useForm.js +0 -30
- package/dist/components/Form/index.d.ts +0 -32
- package/dist/components/Form/index.js +0 -504
- package/dist/components/Form/style.d.ts +0 -6
- package/dist/components/Form/utils/config.d.ts +0 -9
- package/dist/components/Form/utils/config.js +0 -29
- package/dist/components/Form/utils/dateFormat.d.ts +0 -22
- package/dist/components/Form/utils/dateFormat.js +0 -43
- package/dist/components/ListToolBar/index.d.ts +0 -59
- package/dist/components/ListToolBar/index.js +0 -123
- package/dist/components/ListToolBar/style.d.ts +0 -6
- package/dist/components/ScrollBar/Bar/index.d.ts +0 -49
- package/dist/components/ScrollBar/Bar/index.js +0 -68
- package/dist/components/ScrollBar/Bar/props.d.ts +0 -25
- package/dist/components/ScrollBar/Bar/props.js +0 -17
- package/dist/components/ScrollBar/Thumb/index.d.ts +0 -40
- package/dist/components/ScrollBar/Thumb/props.d.ts +0 -20
- package/dist/components/ScrollBar/Thumb/props.js +0 -17
- package/dist/components/TableCell/index.d.ts +0 -37
- package/dist/components/TableCell/index.js +0 -69
- package/dist/components/ToolBar/FullscreenIcon.d.ts +0 -7
- package/dist/components/ToolBar/FullscreenIcon.js +0 -11
- package/dist/components/ToolBar/index.d.ts +0 -34
- package/dist/components/ToolBar/index.js +0 -97
- package/dist/hooks/tryOnActivated.d.ts +0 -6
- package/dist/hooks/tryOnActivated.js +0 -12
- package/dist/hooks/useDebounceFn.d.ts +0 -8
- package/dist/hooks/useDebounceFn.js +0 -31
- package/dist/hooks/useScrollArea.d.ts +0 -24
- package/dist/hooks/useScrollArea.js +0 -102
- package/dist/props.d.ts +0 -340
- package/dist/props.js +0 -247
- package/dist/types/ColumnTypings.d.ts +0 -130
- package/dist/types/SlotsTypings.d.ts +0 -63
- package/dist/types/SlotsTypings.js +0 -12
- package/dist/types/TableTypings.d.ts +0 -359
- package/dist/types/index.d.ts +0 -9
- package/dist/utils/utils.d.ts +0 -10
- package/dist/utils/utils.js +0 -89
- /package/dist/{types/ColumnTypings.js → interface.js} +0 -0
- /package/dist/{types/TableTypings.js → theme/augment.js} +0 -0
- /package/dist/{types/index.js → theme/interface/components.js} +0 -0
package/dist/hooks/useColumns.js
CHANGED
|
@@ -1,64 +1,97 @@
|
|
|
1
|
-
import { computed,
|
|
2
|
-
import {
|
|
1
|
+
import { computed, onScopeDispose, shallowRef, watch } from "vue";
|
|
2
|
+
import { getRandomNumber } from "@gx-design-vue/pro-utils";
|
|
3
3
|
//#region src/hooks/useColumns.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
/** 获取列唯一标识,优先 key,回退 dataIndex */
|
|
5
|
+
function getColumnKey(col) {
|
|
6
|
+
return col.key ?? col.dataIndex;
|
|
7
|
+
}
|
|
8
|
+
function isActionColumn(column) {
|
|
9
|
+
return getColumnKey(column) === "action" || column.dataIndex === "action";
|
|
10
|
+
}
|
|
11
|
+
function normalizeFixedValue(fixed) {
|
|
12
|
+
if (fixed === "left") return "start";
|
|
13
|
+
if (fixed === "right") return "end";
|
|
14
|
+
return fixed;
|
|
15
|
+
}
|
|
16
|
+
/** 规范化单列:补齐 key/dataIndex/align/order,递归处理 children */
|
|
17
|
+
function normalizeColumn(col, index, defaultAlign) {
|
|
18
|
+
const key = getColumnKey(col);
|
|
19
|
+
const normalized = {
|
|
20
|
+
...col,
|
|
21
|
+
key,
|
|
22
|
+
dataIndex: col.dataIndex ?? key,
|
|
23
|
+
order: col.order ?? index,
|
|
24
|
+
align: col.align ?? defaultAlign
|
|
25
|
+
};
|
|
26
|
+
if (col.children?.length) normalized.children = col.children.map((child, childIndex) => normalizeColumn(child, childIndex, defaultAlign));
|
|
27
|
+
return normalized;
|
|
28
|
+
}
|
|
29
|
+
/** 批量规范化列配置 */
|
|
30
|
+
function normalizeColumns(columns, defaultAlign) {
|
|
31
|
+
return columns.map((col, index) => normalizeColumn(col, index, defaultAlign));
|
|
32
|
+
}
|
|
33
|
+
function createIndexColumn(indexColumn, defaultAlign, firstColumn) {
|
|
34
|
+
const config = typeof indexColumn === "object" ? indexColumn : {};
|
|
35
|
+
return {
|
|
36
|
+
title: config.title ?? "序号",
|
|
37
|
+
align: config.align ?? defaultAlign,
|
|
38
|
+
fixed: normalizeFixedValue(config.fixed ?? firstColumn?.fixed),
|
|
39
|
+
width: config.width ?? 60,
|
|
40
|
+
uuid: getRandomNumber().uuid(15),
|
|
41
|
+
dataIndex: "sortIndex",
|
|
42
|
+
key: "sortIndex"
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function applyIndexColumn(columns, indexColumn, defaultAlign) {
|
|
46
|
+
if (!indexColumn || columns.length === 0 || columns.some((column) => column.dataIndex === "sortIndex" || getColumnKey(column) === "sortIndex")) return columns;
|
|
47
|
+
return [createIndexColumn(indexColumn === true ? true : indexColumn, defaultAlign, columns[0]), ...columns];
|
|
48
|
+
}
|
|
49
|
+
function applyActionColumnFixed(columns, shouldFixActionColumn) {
|
|
50
|
+
if (!shouldFixActionColumn) return columns;
|
|
51
|
+
return columns.map((column) => {
|
|
52
|
+
if (!isActionColumn(column) || column.fixed !== void 0) return column;
|
|
53
|
+
return {
|
|
54
|
+
...column,
|
|
55
|
+
fixed: "end"
|
|
56
|
+
};
|
|
20
57
|
});
|
|
21
|
-
|
|
22
|
-
|
|
58
|
+
}
|
|
59
|
+
/** 过滤掉 show=false 的列 */
|
|
60
|
+
function filterVisible(columns) {
|
|
61
|
+
return columns.filter((col) => col.show !== false);
|
|
62
|
+
}
|
|
63
|
+
/** 按 order 字段升序排列 */
|
|
64
|
+
function sortByOrder(columns) {
|
|
65
|
+
return [...columns].sort((columnA, columnB) => (columnA.order ?? 0) - (columnB.order ?? 0));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 列配置管理。
|
|
69
|
+
* 纯函数 + computed 实现,无 watcher/ref 链。
|
|
70
|
+
* - tableColumns: 仅可见列,按 order 排序
|
|
71
|
+
* - cacheColumns: 全量规范化列(含隐藏列)
|
|
72
|
+
* - setColumns: 外部覆写列(用于 sortOrder 同步等),props 变化时自动重置
|
|
73
|
+
*/
|
|
74
|
+
function useColumns(options) {
|
|
75
|
+
const overrideColumns = shallowRef(null);
|
|
76
|
+
const stopWatch = watch(() => options.columns.value, () => {
|
|
77
|
+
overrideColumns.value = null;
|
|
23
78
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
item.fixed = "right";
|
|
35
|
-
} else {
|
|
36
|
-
const originCol = unref(columns).find((col) => col.dataIndex === item.dataIndex);
|
|
37
|
-
item.width = originCol?.width || "";
|
|
38
|
-
item.fixed = originCol?.fixed;
|
|
39
|
-
}
|
|
40
|
-
return item;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function resizeColumnWidth(width, col) {
|
|
44
|
-
proColumnsRef.value = proColumnsRef.value.map((item) => {
|
|
45
|
-
if (item.uuid === col.uuid) item.width = width;
|
|
46
|
-
return item;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function setColumns(columnList) {
|
|
50
|
-
if (columnList.length <= 0) {
|
|
51
|
-
proColumnsRef.value = [];
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (!isDeepEqualReact(handleColumns(columnList), toRaw(proColumnsRef.value))) proColumnsRef.value = handleColumns(columnList);
|
|
79
|
+
onScopeDispose(() => stopWatch());
|
|
80
|
+
const cacheColumns = computed(() => {
|
|
81
|
+
return applyActionColumnFixed(normalizeColumns(applyIndexColumn(overrideColumns.value ?? options.columns.value, options.indexColumn?.value, options.align.value), options.align.value), !!options.shouldFixActionColumn?.value);
|
|
82
|
+
});
|
|
83
|
+
const tableColumns = computed(() => {
|
|
84
|
+
const visible = sortByOrder(filterVisible(cacheColumns.value));
|
|
85
|
+
return options.wrapColumnRender ? visible.map((col) => options.wrapColumnRender(col)) : visible;
|
|
86
|
+
});
|
|
87
|
+
function setColumns(columns) {
|
|
88
|
+
overrideColumns.value = columns;
|
|
55
89
|
}
|
|
56
90
|
return {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
setColumns
|
|
60
|
-
resizeColumnWidth
|
|
91
|
+
tableColumns,
|
|
92
|
+
cacheColumns,
|
|
93
|
+
setColumns
|
|
61
94
|
};
|
|
62
95
|
}
|
|
63
96
|
//#endregion
|
|
64
|
-
export { useColumns };
|
|
97
|
+
export { applyActionColumnFixed, applyIndexColumn, filterVisible, getColumnKey, normalizeColumn, normalizeColumns, sortByOrder, useColumns };
|
|
@@ -1,77 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PageState, ProTableFetchParams, ProTablePagination, ProTablePaginationConfig, ProTableProps } from "../types/TableTypings.js";
|
|
1
|
+
import { BeforeSearchSubmit, OperateRowProps, PageState, ProColumnType, ProTableFetchParams, ProTablePagination, ProTablePaginationConfig, RequestFunction } from "../interface.js";
|
|
3
2
|
import { ComputedRef, Reactive, Ref } from "vue";
|
|
4
|
-
import {
|
|
5
|
-
import { FilterValue, SorterResult, TableCurrentDataSource } from "ant-design-vue/es/table/interface";
|
|
3
|
+
import { FilterValue, SorterResult, TableCurrentDataSource } from "antdv-next/dist/table/interface";
|
|
6
4
|
|
|
7
5
|
//#region src/hooks/useFetchData.d.ts
|
|
8
|
-
interface
|
|
9
|
-
|
|
6
|
+
interface FetchDataConfig<T = any, R = any> {
|
|
7
|
+
rowKey: ComputedRef<string>;
|
|
8
|
+
polling: ComputedRef<boolean>;
|
|
9
|
+
pollingTime: ComputedRef<number>;
|
|
10
|
+
request: RequestFunction<T, R> | undefined;
|
|
11
|
+
postData: ((data: T[]) => T[]) | undefined;
|
|
12
|
+
dataSource: ComputedRef<T[] | undefined>;
|
|
13
|
+
immediate: ComputedRef<boolean>;
|
|
14
|
+
waitRequest: ComputedRef<boolean>;
|
|
15
|
+
autoRequest: ComputedRef<boolean>;
|
|
16
|
+
debounceTime: ComputedRef<number>;
|
|
17
|
+
params: ComputedRef<R | undefined>;
|
|
18
|
+
defaultFormSearch: Ref<Record<string, any>>;
|
|
19
|
+
onLoadingChange: ((loading: boolean) => any) | undefined;
|
|
20
|
+
onRequestError: ((e: Error) => void) | undefined;
|
|
21
|
+
onBeforeSearchSubmit: BeforeSearchSubmit<R> | undefined;
|
|
22
|
+
}
|
|
23
|
+
interface FetchDataAction<T = any> {
|
|
10
24
|
pageInfo: Reactive<PageState>;
|
|
11
25
|
paginationInfo: Ref<ProTablePagination | false>;
|
|
12
|
-
setPagination: (info: Partial<
|
|
26
|
+
setPagination: (info: Partial<ProTablePaginationConfig>) => void;
|
|
13
27
|
setLoading: (loading: boolean) => void;
|
|
14
|
-
setColumns: (
|
|
15
|
-
removeRowKeys: (
|
|
28
|
+
setColumns: (columns: ProColumnType<any>[]) => void;
|
|
29
|
+
removeRowKeys: (keys: (string | number)[]) => void;
|
|
16
30
|
syncSelectedRows: (dataList: any[]) => void;
|
|
17
|
-
columns: ComputedRef<
|
|
18
|
-
defaultFormSearch: Ref<RecordType>;
|
|
19
|
-
params: Ref<ProTableProps['params']>;
|
|
20
|
-
onRequestError: ProTableProps['onRequestError'];
|
|
21
|
-
onBeforeSearchSubmit: ProTableProps['onBeforeSearchSubmit'];
|
|
22
|
-
hasCustomRender: ComputedRef<boolean>;
|
|
23
|
-
}
|
|
24
|
-
interface ConfigFetchData {
|
|
25
|
-
rowKey: ComputedRef<ProTableProps['rowKey']>;
|
|
26
|
-
polling: ComputedRef<ProTableProps['polling']>;
|
|
27
|
-
request: ProTableProps['request'];
|
|
28
|
-
postData: ProTableProps['postData'];
|
|
29
|
-
waitRequest: Ref<ProTableProps['waitRequest']>;
|
|
30
|
-
debounceTime: ComputedRef<ProTableProps['debounceTime']>;
|
|
31
|
-
dataSource: ComputedRef<ProTableProps['dataSource']>;
|
|
32
|
-
autoRequest: ComputedRef<ProTableProps['autoRequest']>;
|
|
31
|
+
columns: ComputedRef<ProColumnType<T>[]>;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}: ConfigFetchData, {
|
|
45
|
-
params,
|
|
46
|
-
columns,
|
|
47
|
-
setLoading,
|
|
48
|
-
setColumns,
|
|
49
|
-
removeRowKeys,
|
|
50
|
-
syncSelectedRows,
|
|
51
|
-
defaultFormSearch,
|
|
52
|
-
setPagination,
|
|
53
|
-
pageInfo,
|
|
54
|
-
paginationInfo,
|
|
55
|
-
onRequestError,
|
|
56
|
-
onBeforeSearchSubmit,
|
|
57
|
-
hasCustomRender
|
|
58
|
-
}: ActionType, emit: any): {
|
|
33
|
+
/**
|
|
34
|
+
* 核心请求引擎。
|
|
35
|
+
* 负责数据请求调度、分页状态、轮询、AbortController 中断、
|
|
36
|
+
* loading 管理、数据转换、行操作、排序/筛选变更。
|
|
37
|
+
*
|
|
38
|
+
* 调度模型:所有请求入口(run/reload/handleTableChange/params 变化等)
|
|
39
|
+
* 统一进入 dispatchFetch → debouncedFetch → fetchList。
|
|
40
|
+
* 通过 requestId + AbortController 双重保证旧响应不回写。
|
|
41
|
+
*/
|
|
42
|
+
declare function useFetchData(config: FetchDataConfig, action: FetchDataAction): {
|
|
59
43
|
dataSource: ComputedRef<any[]>;
|
|
60
44
|
isTreeDataRef: ComputedRef<boolean>;
|
|
61
|
-
setTableDataList: (list:
|
|
62
|
-
operateTableDataRow: (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
value
|
|
67
|
-
}: {
|
|
68
|
-
row?: Partial<RecordType>;
|
|
69
|
-
key?: string;
|
|
70
|
-
value?: any;
|
|
71
|
-
type?: "update" | "push" | "delete" | "unshift";
|
|
72
|
-
}) => void;
|
|
73
|
-
handleTableChange: (pagination: ProTablePaginationConfig, filters?: Record<string, FilterValue | null>, sorter?: SorterResult | SorterResult[], extra?: TableCurrentDataSource) => void;
|
|
74
|
-
run: (info?: ProTableFetchParams) => Promise<void>;
|
|
45
|
+
setTableDataList: (list: any[]) => void;
|
|
46
|
+
operateTableDataRow: (props: OperateRowProps) => void;
|
|
47
|
+
handleTableChange: (paginationConfig: ProTablePaginationConfig, filters?: Record<string, FilterValue | null>, sorter?: SorterResult | SorterResult[], extra?: TableCurrentDataSource) => void;
|
|
48
|
+
run: (info?: ProTableFetchParams) => void;
|
|
49
|
+
reload: (info?: ProTableFetchParams) => void;
|
|
75
50
|
};
|
|
76
51
|
//#endregion
|
|
77
|
-
export {
|
|
52
|
+
export { FetchDataAction, FetchDataConfig, useFetchData };
|