@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.
Files changed (133) hide show
  1. package/dist/ProTable.d.ts +14 -492
  2. package/dist/ProTable.js +818 -518
  3. package/dist/components/ScrollBar/Bar.d.ts +81 -0
  4. package/dist/components/ScrollBar/Bar.js +84 -0
  5. package/dist/components/ScrollBar/Thumb.d.ts +52 -0
  6. package/dist/components/ScrollBar/{Thumb/index.js → Thumb.js} +67 -55
  7. package/dist/components/ScrollBar/context.d.ts +3 -4
  8. package/dist/components/ScrollBar/context.js +3 -3
  9. package/dist/components/ScrollBar/util.d.ts +6 -5
  10. package/dist/components/ScrollBar/util.js +1 -12
  11. package/dist/components/SearchForm/CollapseToggle.d.ts +55 -0
  12. package/dist/components/SearchForm/CollapseToggle.js +47 -0
  13. package/dist/components/SearchForm/FormItemContainer.d.ts +75 -0
  14. package/dist/components/SearchForm/FormItemContainer.js +225 -0
  15. package/dist/components/SearchForm/FormItemWrapper.d.ts +82 -0
  16. package/dist/components/SearchForm/FormItemWrapper.js +62 -0
  17. package/dist/components/SearchForm/SearchForm.d.ts +130 -0
  18. package/dist/components/SearchForm/SearchForm.js +319 -0
  19. package/dist/components/SearchForm/index.d.ts +2 -0
  20. package/dist/components/SearchForm/index.js +2 -0
  21. package/dist/components/Toolbar/FullscreenIcon.d.ts +26 -0
  22. package/dist/components/Toolbar/FullscreenIcon.js +22 -0
  23. package/dist/components/Toolbar/ListToolBar.d.ts +111 -0
  24. package/dist/components/Toolbar/ListToolBar.js +101 -0
  25. package/dist/components/Toolbar/index.d.ts +103 -0
  26. package/dist/components/Toolbar/index.js +101 -0
  27. package/dist/components/Toolbar/style.d.ts +8 -0
  28. package/dist/components/{ListToolBar → Toolbar}/style.js +32 -27
  29. package/dist/context/TableContext.d.ts +15 -27
  30. package/dist/context/TableContext.js +3 -3
  31. package/dist/hooks/index.d.ts +16 -0
  32. package/dist/hooks/index.js +16 -0
  33. package/dist/hooks/useBreakpoints.d.ts +13 -0
  34. package/dist/hooks/useBreakpoints.js +57 -0
  35. package/dist/hooks/useCellRender.d.ts +13 -0
  36. package/dist/hooks/useCellRender.js +28 -0
  37. package/dist/hooks/useColumnResize.d.ts +30 -0
  38. package/dist/hooks/useColumnResize.js +110 -0
  39. package/dist/hooks/useColumns.d.ts +35 -24
  40. package/dist/hooks/useColumns.js +89 -56
  41. package/dist/hooks/useFetchData.d.ts +40 -65
  42. package/dist/hooks/useFetchData.js +157 -172
  43. package/dist/hooks/useFitPage.d.ts +19 -0
  44. package/dist/hooks/useFitPage.js +90 -0
  45. package/dist/hooks/useKeepAliveReload.d.ts +21 -0
  46. package/dist/hooks/useKeepAliveReload.js +24 -0
  47. package/dist/hooks/useLoading.d.ts +18 -7
  48. package/dist/hooks/useLoading.js +26 -8
  49. package/dist/hooks/usePagination.d.ts +10 -7
  50. package/dist/hooks/usePagination.js +37 -26
  51. package/dist/hooks/useRequestOptions.d.ts +18 -0
  52. package/dist/hooks/useRequestOptions.js +39 -0
  53. package/dist/hooks/useRowSelection.d.ts +27 -15
  54. package/dist/hooks/useRowSelection.js +92 -77
  55. package/dist/hooks/useTable.d.ts +19 -77
  56. package/dist/hooks/useTable.js +66 -54
  57. package/dist/hooks/useTableForm.d.ts +15 -83
  58. package/dist/hooks/useTableForm.js +93 -57
  59. package/dist/hooks/useTableScroll.d.ts +33 -31
  60. package/dist/hooks/useTableScroll.js +71 -26
  61. package/dist/hooks/useTableSize.d.ts +17 -7
  62. package/dist/hooks/useTableSize.js +20 -6
  63. package/dist/index.d.ts +10 -7
  64. package/dist/index.js +9 -3
  65. package/dist/interface.d.ts +492 -0
  66. package/dist/pro-table.esm.js +3512 -3965
  67. package/dist/pro-table.js +1 -1
  68. package/dist/style/fit-page.d.ts +4 -2
  69. package/dist/style/fit-page.js +9 -3
  70. package/dist/style/index.d.ts +4 -6
  71. package/dist/style/index.js +24 -74
  72. package/dist/style/list.d.ts +4 -2
  73. package/dist/style/list.js +1 -10
  74. package/dist/style/resizable.d.ts +8 -0
  75. package/dist/style/resizable.js +18 -0
  76. package/dist/style/scroll.d.ts +4 -2
  77. package/dist/style/scroll.js +8 -6
  78. package/dist/style/search.d.ts +8 -0
  79. package/dist/{components/Form/style.js → style/search.js} +22 -8
  80. package/dist/theme/augment.d.ts +8 -0
  81. package/dist/theme/interface/components.d.ts +8 -0
  82. package/dist/utils/dateFormat.d.ts +9 -0
  83. package/dist/utils/dateFormat.js +29 -0
  84. package/dist/utils/formConstants.d.ts +9 -0
  85. package/dist/utils/formConstants.js +29 -0
  86. package/dist/utils/valueFormat.d.ts +9 -0
  87. package/dist/utils/valueFormat.js +27 -0
  88. package/package.json +10 -9
  89. package/dist/components/Form/components/RequestSelect.d.ts +0 -50
  90. package/dist/components/Form/components/RequestSelect.js +0 -56
  91. package/dist/components/Form/hooks/useForm.d.ts +0 -11
  92. package/dist/components/Form/hooks/useForm.js +0 -30
  93. package/dist/components/Form/index.d.ts +0 -32
  94. package/dist/components/Form/index.js +0 -504
  95. package/dist/components/Form/style.d.ts +0 -6
  96. package/dist/components/Form/utils/config.d.ts +0 -9
  97. package/dist/components/Form/utils/config.js +0 -29
  98. package/dist/components/Form/utils/dateFormat.d.ts +0 -22
  99. package/dist/components/Form/utils/dateFormat.js +0 -43
  100. package/dist/components/ListToolBar/index.d.ts +0 -59
  101. package/dist/components/ListToolBar/index.js +0 -123
  102. package/dist/components/ListToolBar/style.d.ts +0 -6
  103. package/dist/components/ScrollBar/Bar/index.d.ts +0 -49
  104. package/dist/components/ScrollBar/Bar/index.js +0 -68
  105. package/dist/components/ScrollBar/Bar/props.d.ts +0 -25
  106. package/dist/components/ScrollBar/Bar/props.js +0 -17
  107. package/dist/components/ScrollBar/Thumb/index.d.ts +0 -40
  108. package/dist/components/ScrollBar/Thumb/props.d.ts +0 -20
  109. package/dist/components/ScrollBar/Thumb/props.js +0 -17
  110. package/dist/components/TableCell/index.d.ts +0 -37
  111. package/dist/components/TableCell/index.js +0 -69
  112. package/dist/components/ToolBar/FullscreenIcon.d.ts +0 -7
  113. package/dist/components/ToolBar/FullscreenIcon.js +0 -11
  114. package/dist/components/ToolBar/index.d.ts +0 -34
  115. package/dist/components/ToolBar/index.js +0 -97
  116. package/dist/hooks/tryOnActivated.d.ts +0 -6
  117. package/dist/hooks/tryOnActivated.js +0 -12
  118. package/dist/hooks/useDebounceFn.d.ts +0 -8
  119. package/dist/hooks/useDebounceFn.js +0 -31
  120. package/dist/hooks/useScrollArea.d.ts +0 -24
  121. package/dist/hooks/useScrollArea.js +0 -102
  122. package/dist/props.d.ts +0 -340
  123. package/dist/props.js +0 -247
  124. package/dist/types/ColumnTypings.d.ts +0 -130
  125. package/dist/types/SlotsTypings.d.ts +0 -63
  126. package/dist/types/SlotsTypings.js +0 -12
  127. package/dist/types/TableTypings.d.ts +0 -359
  128. package/dist/types/index.d.ts +0 -9
  129. package/dist/utils/utils.d.ts +0 -10
  130. package/dist/utils/utils.js +0 -89
  131. /package/dist/{types/ColumnTypings.js → interface.js} +0 -0
  132. /package/dist/{types/TableTypings.js → theme/augment.js} +0 -0
  133. /package/dist/{types/index.js → theme/interface/components.js} +0 -0
@@ -1,64 +1,97 @@
1
- import { computed, ref, toRaw, unref, watch } from "vue";
2
- import { cloneDeep, compareArray, isBoolean, isDeepEqualReact, isNumber } from "@gx-design-vue/pro-utils";
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
- function useColumns({ scroll, columns, breakpoint, draggable, autoScroll, neverScroll }) {
5
- const proColumnsRef = ref([]);
6
- watch([
7
- () => scroll.value,
8
- () => columns.value,
9
- () => breakpoint.value,
10
- () => draggable.value,
11
- () => breakpoint.value,
12
- () => autoScroll.value,
13
- () => neverScroll.value
14
- ], () => {
15
- const columnsList = handleColumns(toRaw(columns.value));
16
- if (!isDeepEqualReact(columnsList, toRaw(proColumnsRef.value))) proColumnsRef.value = cloneDeep(columnsList);
17
- }, {
18
- deep: true,
19
- immediate: true
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
- const proColumns = computed(() => {
22
- return handleTableSort(unref(proColumnsRef));
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
- function handleTableSort(data) {
25
- return data.sort((a, b) => compareArray(a, b, "order", 0));
26
- }
27
- function handleColumns(columnsList) {
28
- return cloneDeep(columnsList).map((item, index) => {
29
- if (item.dataIndex === "action" || index === columnsList.length - 1) item.resizable = false;
30
- else item.resizable = isBoolean(item.resizable) ? item.resizable : !!(isNumber(item.width) && unref(draggable));
31
- if (!item.width || unref(neverScroll)) return item;
32
- if (item.dataIndex === "action" && unref(autoScroll)) if (scroll.value?.x || !unref(breakpoint)) {
33
- item.width = item.width || 100;
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
- breakpoint,
58
- proColumns,
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 { ProColumnsType } from "../types/ColumnTypings.js";
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 { RecordType } from "@gx-design-vue/pro-utils";
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 ActionType {
9
- loading: Ref<boolean>;
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<ProTablePagination>) => void;
26
+ setPagination: (info: Partial<ProTablePaginationConfig>) => void;
13
27
  setLoading: (loading: boolean) => void;
14
- setColumns: (columnList: ProColumnsType) => void;
15
- removeRowKeys: (keyList: (string | number)[]) => void;
28
+ setColumns: (columns: ProColumnType<any>[]) => void;
29
+ removeRowKeys: (keys: (string | number)[]) => void;
16
30
  syncSelectedRows: (dataList: any[]) => void;
17
- columns: ComputedRef<ProColumnsType>;
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
- declare function useConfigFetchData(props: ProTableProps): Omit<ConfigFetchData, 'waitRequest'>;
35
- declare function useFetchData({
36
- rowKey,
37
- autoRequest,
38
- polling,
39
- request,
40
- postData,
41
- dataSource,
42
- waitRequest,
43
- debounceTime
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: RecordType[]) => void;
62
- operateTableDataRow: ({
63
- key,
64
- type,
65
- row,
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 { ConfigFetchData, useConfigFetchData, useFetchData };
52
+ export { FetchDataAction, FetchDataConfig, useFetchData };