@gx-design-vue/pro-table 0.2.0-alpha.0 → 0.2.0-alpha.10

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 (136) hide show
  1. package/dist/ProTable.d.ts +14 -493
  2. package/dist/ProTable.js +818 -512
  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 -58
  7. package/dist/components/ScrollBar/context.d.ts +3 -4
  8. package/dist/components/ScrollBar/context.js +3 -5
  9. package/dist/components/ScrollBar/util.d.ts +6 -5
  10. package/dist/components/ScrollBar/util.js +1 -14
  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 -5
  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 -58
  41. package/dist/hooks/useFetchData.d.ts +40 -65
  42. package/dist/hooks/useFetchData.js +157 -174
  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 +27 -11
  49. package/dist/hooks/usePagination.d.ts +10 -7
  50. package/dist/hooks/usePagination.js +38 -29
  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 +93 -80
  55. package/dist/hooks/useTable.d.ts +35 -77
  56. package/dist/hooks/useTable.js +72 -50
  57. package/dist/hooks/useTableForm.d.ts +15 -82
  58. package/dist/hooks/useTableForm.js +93 -55
  59. package/dist/hooks/useTableScroll.d.ts +33 -31
  60. package/dist/hooks/useTableScroll.js +71 -28
  61. package/dist/hooks/useTableSize.d.ts +17 -7
  62. package/dist/hooks/useTableSize.js +21 -9
  63. package/dist/index.d.ts +10 -7
  64. package/dist/index.js +9 -4
  65. package/dist/interface.d.ts +499 -0
  66. package/dist/interface.js +1 -0
  67. package/dist/pro-table.esm.js +3579 -3834
  68. package/dist/pro-table.js +1 -1
  69. package/dist/style/fit-page.d.ts +4 -2
  70. package/dist/style/fit-page.js +10 -5
  71. package/dist/style/index.d.ts +4 -6
  72. package/dist/style/index.js +24 -76
  73. package/dist/style/list.d.ts +4 -2
  74. package/dist/style/list.js +2 -12
  75. package/dist/style/resizable.d.ts +8 -0
  76. package/dist/style/resizable.js +18 -0
  77. package/dist/style/scroll.d.ts +4 -2
  78. package/dist/style/scroll.js +9 -9
  79. package/dist/style/search.d.ts +8 -0
  80. package/dist/{components/Form/style.js → style/search.js} +22 -9
  81. package/dist/theme/augment.d.ts +8 -0
  82. package/dist/theme/augment.js +1 -0
  83. package/dist/theme/interface/components.d.ts +8 -0
  84. package/dist/theme/interface/components.js +1 -0
  85. package/dist/utils/dateFormat.d.ts +9 -0
  86. package/dist/utils/dateFormat.js +29 -0
  87. package/dist/utils/formConstants.d.ts +9 -0
  88. package/dist/utils/formConstants.js +29 -0
  89. package/dist/utils/valueFormat.d.ts +9 -0
  90. package/dist/utils/valueFormat.js +27 -0
  91. package/package.json +11 -10
  92. package/dist/components/Form/components/RequestSelect.d.ts +0 -50
  93. package/dist/components/Form/components/RequestSelect.js +0 -58
  94. package/dist/components/Form/hooks/useForm.d.ts +0 -11
  95. package/dist/components/Form/hooks/useForm.js +0 -32
  96. package/dist/components/Form/index.d.ts +0 -33
  97. package/dist/components/Form/index.js +0 -479
  98. package/dist/components/Form/style.d.ts +0 -6
  99. package/dist/components/Form/utils/config.d.ts +0 -9
  100. package/dist/components/Form/utils/config.js +0 -30
  101. package/dist/components/Form/utils/dateFormat.d.ts +0 -22
  102. package/dist/components/Form/utils/dateFormat.js +0 -45
  103. package/dist/components/ListToolBar/index.d.ts +0 -60
  104. package/dist/components/ListToolBar/index.js +0 -123
  105. package/dist/components/ListToolBar/style.d.ts +0 -6
  106. package/dist/components/ScrollBar/Bar/index.d.ts +0 -49
  107. package/dist/components/ScrollBar/Bar/index.js +0 -71
  108. package/dist/components/ScrollBar/Bar/props.d.ts +0 -25
  109. package/dist/components/ScrollBar/Bar/props.js +0 -18
  110. package/dist/components/ScrollBar/Thumb/index.d.ts +0 -40
  111. package/dist/components/ScrollBar/Thumb/props.d.ts +0 -20
  112. package/dist/components/ScrollBar/Thumb/props.js +0 -18
  113. package/dist/components/TableCell/index.d.ts +0 -37
  114. package/dist/components/TableCell/index.js +0 -72
  115. package/dist/components/ToolBar/FullscreenIcon.d.ts +0 -7
  116. package/dist/components/ToolBar/FullscreenIcon.js +0 -14
  117. package/dist/components/ToolBar/index.d.ts +0 -34
  118. package/dist/components/ToolBar/index.js +0 -100
  119. package/dist/hooks/tryOnActivated.d.ts +0 -6
  120. package/dist/hooks/tryOnActivated.js +0 -14
  121. package/dist/hooks/useDebounceFn.d.ts +0 -8
  122. package/dist/hooks/useDebounceFn.js +0 -34
  123. package/dist/hooks/useScrollArea.d.ts +0 -24
  124. package/dist/hooks/useScrollArea.js +0 -104
  125. package/dist/props.d.ts +0 -340
  126. package/dist/props.js +0 -251
  127. package/dist/types/ColumnTypings.d.ts +0 -127
  128. package/dist/types/ColumnTypings.js +0 -1
  129. package/dist/types/SlotsTypings.d.ts +0 -63
  130. package/dist/types/SlotsTypings.js +0 -13
  131. package/dist/types/TableTypings.d.ts +0 -359
  132. package/dist/types/TableTypings.js +0 -1
  133. package/dist/types/index.d.ts +0 -9
  134. package/dist/types/index.js +0 -1
  135. package/dist/utils/utils.d.ts +0 -10
  136. package/dist/utils/utils.js +0 -91
@@ -1,73 +1,95 @@
1
- import { computed, isRef, reactive, ref, watch } from "vue";
2
- import { cloneDeep, deepMerge, isObject, useDeepMerge } from "@gx-design-vue/pro-utils";
3
-
1
+ import { computed, reactive, ref, toValue, watch } from "vue";
2
+ import { merge } from "@gx-design-vue/pro-utils";
4
3
  //#region src/hooks/useTable.ts
4
+ const EMPTY_ARRAY = [];
5
5
  function useTable(tableRef, options) {
6
- function getTableState() {
7
- const defaultState = {
8
- params: {},
9
- searchMap: []
10
- };
11
- if (options?.state) {
12
- if (isRef(options.state) && isObject(options.state.value)) return deepMerge(defaultState, cloneDeep(options.state.value));
13
- else if (isObject(options.state) && !isRef(options.state)) return deepMerge(defaultState, cloneDeep(options.state));
6
+ const tableState = reactive({});
7
+ const syncedStateKeys = /* @__PURE__ */ new Set();
8
+ function syncTableState(state = {}) {
9
+ const nextState = merge({}, state);
10
+ for (const key of syncedStateKeys) if (!(key in nextState)) {
11
+ delete tableState[key];
12
+ syncedStateKeys.delete(key);
14
13
  }
15
- return defaultState;
14
+ Object.assign(tableState, nextState);
15
+ for (const key of Object.keys(nextState)) syncedStateKeys.add(key);
16
+ if (options?.request) tableState.request = options.request;
16
17
  }
17
- const tableState = reactive(deepMerge(getTableState(), { request: options?.request }));
18
- if (options?.state) watch(() => options.state && isRef(options.state) ? options.state.value : options.state, () => {
19
- updateTableState();
20
- }, { deep: true });
18
+ watch(() => toValue(options?.state), (newState) => {
19
+ syncTableState(newState ?? {});
20
+ }, {
21
+ deep: true,
22
+ immediate: true
23
+ });
21
24
  const actionRef = computed(() => {
22
- if (tableRef.value) return tableRef.value.actionRef();
23
- return {};
25
+ return tableRef.value?.actionRef?.() ?? {};
24
26
  });
25
27
  const formRef = computed(() => {
26
- if (tableRef.value) return tableRef.value.formRef();
27
- return {};
28
- });
29
- const requestSearch = computed(() => {
30
- return {
31
- ...actionRef.value.pageInfo || {},
32
- ...formRef.value.getFormSearch?.() || {}
33
- };
28
+ return tableRef.value?.formRef?.() ?? {};
34
29
  });
35
- const loading = ref(!!actionRef.value.loading?.value);
36
- watch(() => actionRef.value.loading?.value, (val) => {
30
+ const requestSearch = computed(() => ({
31
+ ...actionRef.value?.pageInfo || {},
32
+ ...formRef.value?.getFormSearch?.() || {}
33
+ }));
34
+ const loading = ref(false);
35
+ watch(() => actionRef.value?.loading?.value, (val) => {
37
36
  loading.value = !!val;
38
37
  });
39
38
  watch(loading, (val) => {
40
39
  actionRef.value?.setLoading?.(!!val);
41
40
  });
42
- function updateTableState() {
43
- useDeepMerge(tableState, getTableState());
41
+ function reload(info) {
42
+ actionRef.value?.reload?.(info);
43
+ }
44
+ function setTableDataList(data) {
45
+ actionRef.value?.setTableDataList?.(data);
46
+ }
47
+ function operateTableDataRow(props) {
48
+ actionRef.value?.operateTableDataRow?.(props);
49
+ }
50
+ function setPageInfo(pagination, filters, sorter, extra) {
51
+ actionRef.value?.setPageInfo?.(pagination, filters, sorter, extra);
52
+ }
53
+ function setPagination(pagination) {
54
+ actionRef.value?.setPagination?.(pagination);
55
+ }
56
+ function reloadAndReset(options) {
57
+ actionRef.value?.reloadAndReset?.(options);
58
+ }
59
+ function setLoading(value) {
60
+ loading.value = value;
44
61
  }
62
+ const selectedKeys = computed(() => actionRef.value?.selectedKeys?.value ?? []);
63
+ const selectedItems = computed(() => actionRef.value?.selectedItems?.value ?? []);
64
+ const rowsSelection = {
65
+ clear: () => actionRef.value?.rowsSelection?.clear?.(),
66
+ select: (record, selected) => actionRef.value?.rowsSelection?.select?.(record, selected),
67
+ selectAll: (records, selected) => actionRef.value?.rowsSelection?.selectAll?.(records, selected),
68
+ remove: (keys) => actionRef.value?.rowsSelection?.remove?.(keys),
69
+ sync: () => actionRef.value?.rowsSelection?.sync?.()
70
+ };
45
71
  function updateSearchMap(key, value) {
46
- if (tableState.searchMap) tableState.searchMap = cloneDeep(tableState.searchMap).map((item) => {
47
- if (item.name === key) return deepMerge(item, value);
48
- return item;
49
- });
72
+ if (tableState.searchMap) tableState.searchMap = tableState.searchMap.map((item) => item.name === key ? merge({}, item, value) : item);
50
73
  }
51
74
  return {
52
- formRef,
75
+ loading,
76
+ dataSource: computed(() => actionRef.value?.dataSource?.value ?? EMPTY_ARRAY),
77
+ requestSearch,
78
+ selectedKeys,
79
+ selectedItems,
80
+ rowsSelection,
53
81
  actionRef,
82
+ formRef,
83
+ reload,
84
+ setTableDataList,
85
+ operateTableDataRow,
86
+ setPageInfo,
87
+ setPagination,
88
+ reloadAndReset,
89
+ setLoading,
54
90
  tableState,
55
- requestSearch,
56
- loading,
57
- dataSource: computed(() => actionRef?.value?.dataSource?.value || []),
58
- selectedKeys: computed(() => actionRef?.value?.selectedKeys?.value || []),
59
- selectedItems: computed(() => actionRef?.value?.selectedItems?.value || []),
60
- rowsSelection: actionRef?.value?.rowsSelection,
61
- setTableDataList: (data) => actionRef.value?.setTableDataList?.(data),
62
- reloadAndReset: (options) => actionRef.value?.reloadAndReset?.(options),
63
- setPageInfo: (pagination, filters, sorter, extra) => actionRef.value?.setPageInfo?.(pagination, filters, sorter, extra),
64
- setPagination: (pageInfo) => actionRef.value?.setPagination?.(pageInfo),
65
- setLoading: (value) => loading.value = value,
66
- operateTableDataRow: (params) => actionRef.value?.operateTableDataRow?.(params),
67
- reload: (info) => actionRef.value?.reload?.(info),
68
91
  updateSearchMap
69
92
  };
70
93
  }
71
-
72
94
  //#endregion
73
- export { useTable };
95
+ export { useTable };
@@ -1,86 +1,19 @@
1
- import { ProFieldValueFormat, ProFieldValueType, ProSchemaValueEnumType, ProSearchMap } from "../types/ColumnTypings.js";
2
- import { ProTableProps } from "../types/TableTypings.js";
1
+ import { ProColumnType, ProSearchMap } from "../interface.js";
3
2
  import { ComputedRef, Ref } from "vue";
4
- import * as _gx_design_vue_pro_utils0 from "@gx-design-vue/pro-utils";
5
- import { RecordType } from "@gx-design-vue/pro-utils";
6
3
 
7
4
  //#region src/hooks/useTableForm.d.ts
8
- declare function handleFormDefaultValue(data: ProSearchMap[]): RecordType;
9
- declare function useTableForm({
10
- searchMap,
11
- columns
12
- }: {
13
- searchMap: Ref<ProTableProps['searchMap']>;
14
- columns: ComputedRef<ProTableProps['columns']>;
15
- }): {
16
- formCols: Ref<{
17
- name: string;
18
- order?: number;
19
- valueType?: ProFieldValueType;
20
- valueFormat?: ProFieldValueFormat;
21
- placeholder?: string | string[];
22
- allowClear?: boolean;
23
- showSearch?: boolean;
24
- showToday?: boolean;
25
- rangeStartName?: string;
26
- rangeEndName?: string;
27
- use12Hours?: boolean;
28
- loading?: boolean;
29
- showTime?: RecordType | boolean;
30
- initialValue?: any;
31
- valueKey?: string;
32
- request?: {
33
- fetch?: () => Promise<ProSchemaValueEnumType[]>;
34
- manual?: boolean;
35
- debounceTime?: number;
36
- };
37
- label?: string;
38
- labelWidth?: string | number;
39
- labelAlign?: "center" | "left" | "right";
40
- field?: {
41
- [x: string]: any;
42
- rules?: RegExp;
43
- };
44
- valueEnum?: {
45
- label: _gx_design_vue_pro_utils0.VueNode | JSX.Element;
46
- value: any;
47
- disabled?: boolean;
48
- }[];
49
- }[], ProSearchMap<"text", string>[] | {
50
- name: string;
51
- order?: number;
52
- valueType?: ProFieldValueType;
53
- valueFormat?: ProFieldValueFormat;
54
- placeholder?: string | string[];
55
- allowClear?: boolean;
56
- showSearch?: boolean;
57
- showToday?: boolean;
58
- rangeStartName?: string;
59
- rangeEndName?: string;
60
- use12Hours?: boolean;
61
- loading?: boolean;
62
- showTime?: RecordType | boolean;
63
- initialValue?: any;
64
- valueKey?: string;
65
- request?: {
66
- fetch?: () => Promise<ProSchemaValueEnumType[]>;
67
- manual?: boolean;
68
- debounceTime?: number;
69
- };
70
- label?: string;
71
- labelWidth?: string | number;
72
- labelAlign?: "center" | "left" | "right";
73
- field?: {
74
- [x: string]: any;
75
- rules?: RegExp;
76
- };
77
- valueEnum?: {
78
- label: _gx_design_vue_pro_utils0.VueNode | JSX.Element;
79
- value: any;
80
- disabled?: boolean;
81
- }[];
82
- }[]>;
83
- defaultFormSearch: Ref<RecordType, RecordType>;
84
- };
5
+ interface UseTableFormOptions {
6
+ searchMap: ComputedRef<ProSearchMap[]>;
7
+ columns: ComputedRef<ProColumnType[]>;
8
+ }
9
+ interface UseTableFormReturn {
10
+ formColumns: ComputedRef<ProSearchMap[]>;
11
+ defaultFormSearch: Ref<Record<string, any>>;
12
+ formState: Ref<Record<string, any>>;
13
+ getFormSearch: () => Record<string, any>;
14
+ resetFormState: () => void;
15
+ changeFormState: (key: string, value: any) => void;
16
+ }
17
+ declare function useTableForm(options: UseTableFormOptions): UseTableFormReturn;
85
18
  //#endregion
86
- export { handleFormDefaultValue, useTableForm };
19
+ export { UseTableFormOptions, UseTableFormReturn, useTableForm };
@@ -1,69 +1,107 @@
1
- import { ref, watch } from "vue";
2
- import { isArray } from "@gx-design-vue/pro-utils";
3
-
1
+ import { computed, ref, toRaw, watch } from "vue";
2
+ import { cloneDeep } from "@gx-design-vue/pro-utils";
4
3
  //#region src/hooks/useTableForm.ts
5
- function handleFormDefaultValue(data) {
6
- const defaulState = {};
7
- data.forEach((item) => {
8
- let initialValue = item.initialValue;
9
- const valueEmptyArray = ["treeSelect", "numberRange"];
10
- if (item.valueType) {
11
- if (!initialValue && valueEmptyArray.includes(item.valueType)) initialValue = [];
12
- }
13
- if (item.name) defaulState[item.name] = initialValue;
14
- if (item.valueType === "dateRange") {
15
- if (item.rangeStartName || item.rangeEndName) {
16
- defaulState[item.rangeStartName || "start"] = isArray(initialValue) ? initialValue[0] : void 0;
17
- defaulState[item.rangeEndName || "end"] = isArray(initialValue) ? initialValue[1] : void 0;
18
- delete defaulState[item.name];
19
- }
4
+ function sortFormItemsByOrder(items) {
5
+ let maxOrder = items.reduce((max, item) => {
6
+ return item.order !== void 0 ? Math.max(max, item.order) : max;
7
+ }, 0);
8
+ const sorted = items.map((item) => {
9
+ if (item.order === void 0) {
10
+ maxOrder += 1;
11
+ return {
12
+ ...item,
13
+ order: maxOrder
14
+ };
20
15
  }
16
+ return item;
21
17
  });
22
- return defaulState;
18
+ sorted.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
19
+ return sorted;
23
20
  }
24
- function useTableForm({ searchMap, columns }) {
25
- const formCols = ref([]);
26
- const defaultFormSearch = ref({});
27
- function updateFormData(data) {
28
- data.forEach((item) => {
29
- if (formCols.value.some((el) => el.name === item.name)) formCols.value = formCols.value.map((el) => {
30
- if (el.name === item.name) return {
31
- ...el,
32
- ...item
33
- };
34
- return el;
35
- });
36
- else formCols.value.push(item);
37
- });
38
- const defaultParams = handleFormDefaultValue(data);
39
- defaultFormSearch.value = {
40
- ...defaultFormSearch.value,
41
- ...defaultParams
42
- };
21
+ function computeDefaultFormValues(columns) {
22
+ const defaults = {};
23
+ for (const col of columns) {
24
+ const valueType = col.valueType ?? "text";
25
+ if (col.initialValue !== void 0) defaults[col.name] = col.initialValue;
26
+ else if (valueType === "numberRange") defaults[col.name] = [];
27
+ else if (valueType === "treeSelect" && (col.field?.treeCheckable || col.field?.multiple)) defaults[col.name] = [];
28
+ else if (valueType === "cascader" && col.field?.multiple) defaults[col.name] = [];
29
+ else if (valueType === "dateRange") if (col.rangeStartName || col.rangeEndName) {
30
+ defaults[col.rangeStartName || "start"] = void 0;
31
+ defaults[col.rangeEndName || "end"] = void 0;
32
+ } else defaults[col.name] = void 0;
43
33
  }
44
- watch(() => searchMap.value, () => {
45
- const searchData = [];
46
- searchMap.value?.forEach((item) => searchData.push(item));
47
- if (searchData.length) updateFormData(searchData);
48
- }, {
49
- deep: true,
50
- immediate: true
34
+ return defaults;
35
+ }
36
+ function useTableForm(options) {
37
+ const { searchMap, columns } = options;
38
+ const formColumns = computed(() => {
39
+ const colsFromSearchMap = searchMap.value;
40
+ const colsFromColumns = columns.value.filter((col) => col.searchConfig).map((col) => ({
41
+ ...col.searchConfig,
42
+ order: col.searchConfig.order ?? col.order ?? 0
43
+ }));
44
+ return sortFormItemsByOrder([...colsFromSearchMap, ...colsFromColumns]);
51
45
  });
52
- watch(() => columns.value, () => {
53
- const searchData = [];
54
- if (columns.value && columns.value?.length) columns.value.forEach((item) => {
55
- if (item.searchConfig) searchData.push(item.searchConfig);
56
- });
57
- if (searchData.length) updateFormData(searchData);
46
+ const defaultFormSearch = computed(() => {
47
+ return computeDefaultFormValues(formColumns.value);
48
+ });
49
+ const formState = ref({});
50
+ watch(() => defaultFormSearch.value, (newDefaults) => {
51
+ formState.value = cloneDeep(toRaw(newDefaults));
58
52
  }, {
59
53
  deep: true,
60
54
  immediate: true
61
55
  });
56
+ function getFormSearch() {
57
+ const searchParams = cloneDeep(toRaw(formState.value));
58
+ for (const record of formColumns.value) {
59
+ const valueType = record.valueType ?? "text";
60
+ const name = record.name;
61
+ if (valueType === "text") searchParams[name] = formState.value[name] ?? record.initialValue;
62
+ if (valueType === "dateRange" && (record.rangeStartName || record.rangeEndName)) {
63
+ const rangeValue = searchParams[name];
64
+ searchParams[record.rangeStartName || "start"] = Array.isArray(rangeValue) ? rangeValue[0] : void 0;
65
+ searchParams[record.rangeEndName || "end"] = Array.isArray(rangeValue) ? rangeValue[1] : void 0;
66
+ delete searchParams[name];
67
+ }
68
+ if (valueType === "cascader" && record.valueKey === "single") {
69
+ const value = searchParams[name];
70
+ searchParams[name] = Array.isArray(value) ? value[value.length - 1] : void 0;
71
+ }
72
+ if (valueType === "treeSelect" && Array.isArray(formState.value[name])) {
73
+ const keyField = record.valueKey === "text" ? "label" : "value";
74
+ searchParams[name] = formState.value[name].length > 0 ? formState.value[name].map((item) => item[keyField]).join(",") : void 0;
75
+ }
76
+ if (valueType === "numberRange") {
77
+ const value = searchParams[name];
78
+ searchParams[name] = Array.isArray(value) && value.some((val) => val !== void 0 && val !== null && val !== "") ? value : void 0;
79
+ }
80
+ }
81
+ return searchParams;
82
+ }
83
+ function resetFormState() {
84
+ const defaults = cloneDeep(toRaw(defaultFormSearch.value));
85
+ formState.value = defaults;
86
+ for (const record of formColumns.value) if (record.valueType === "dateRange" && (record.rangeStartName || record.rangeEndName)) {
87
+ const startKey = record.rangeStartName || "start";
88
+ const endKey = record.rangeEndName || "end";
89
+ const startValue = defaults[startKey];
90
+ const endValue = defaults[endKey];
91
+ if (startValue !== void 0 || endValue !== void 0) formState.value[record.name] = [startValue, endValue];
92
+ }
93
+ }
94
+ function changeFormState(key, value) {
95
+ if (key) formState.value[key] = value;
96
+ }
62
97
  return {
63
- formCols,
64
- defaultFormSearch
98
+ formColumns,
99
+ defaultFormSearch,
100
+ formState,
101
+ getFormSearch,
102
+ resetFormState,
103
+ changeFormState
65
104
  };
66
105
  }
67
-
68
106
  //#endregion
69
- export { handleFormDefaultValue, useTableForm };
107
+ export { useTableForm };
@@ -1,35 +1,37 @@
1
- import { ProColumnsType } from "../types/ColumnTypings.js";
2
- import { ProTableProps, TableScroll } from "../types/TableTypings.js";
3
- import { ComputedRef, Ref } from "vue";
4
- import { Breakpoint } from "@gx-design-vue/pro-utils";
1
+ import { ProColumnType, ProTableScrollPolicy } from "../interface.js";
2
+ import { ComputedRef } from "vue";
3
+ import { Breakpoint, RecordType } from "@gx-design-vue/pro-utils";
4
+ import { TableProps } from "antdv-next";
5
5
 
6
6
  //#region src/hooks/useTableScroll.d.ts
7
- interface ConfigScroll {
8
- scroll: Ref<ProTableProps['scroll']>;
9
- autoScroll: Ref<ProTableProps['autoScroll']>;
10
- modalScroll: Ref<ProTableProps['modalScroll']>;
11
- neverScroll: Ref<ProTableProps['neverScroll']>;
12
- rowSelection: Ref<ProTableProps['rowSelection']>;
13
- scrollBreakpoint: Ref<ProTableProps['scrollBreakpoint']>;
7
+ interface NormalizedTableScrollPolicy {
8
+ mode: 'auto' | 'manual' | 'disabled';
9
+ breakpoint: Breakpoint | number;
10
+ modal: boolean;
11
+ modalY: {
12
+ desktop: number;
13
+ mobile: number;
14
+ };
15
+ actionFixed: boolean | 'auto';
14
16
  }
15
- type useTableScrollType = {
16
- columns: ComputedRef<ProColumnsType>;
17
- innerWidth: Ref<number>;
18
- screens: Ref<Partial<Record<Breakpoint, boolean>>>;
19
- } & ConfigScroll;
20
- declare function useTableScroll({
21
- scroll,
22
- columns,
23
- autoScroll,
24
- modalScroll,
25
- neverScroll,
26
- rowSelection,
27
- screens,
28
- innerWidth,
29
- scrollBreakpoint
30
- }: useTableScrollType): {
31
- proScroll: ComputedRef<TableScroll>;
32
- breakpoint: ComputedRef<boolean>;
33
- };
17
+ interface UseTableScrollOptions<T = RecordType> {
18
+ scroll: ComputedRef<TableProps<T>['scroll'] | undefined>;
19
+ columns: ComputedRef<ProColumnType<T>[]>;
20
+ rowSelection: ComputedRef<TableProps<T>['rowSelection'] | undefined>;
21
+ screens: ComputedRef<Record<string, boolean>>;
22
+ screenWidth: ComputedRef<number>;
23
+ scrollPolicy: ComputedRef<false | ProTableScrollPolicy | undefined>;
24
+ }
25
+ interface UseTableScrollReturn<T = RecordType> {
26
+ tableScroll: ComputedRef<TableProps<T>['scroll']>;
27
+ hasHorizontalScroll: ComputedRef<boolean>;
28
+ shouldFixActionColumn: ComputedRef<boolean>;
29
+ normalizedScrollPolicy: ComputedRef<NormalizedTableScrollPolicy>;
30
+ }
31
+ declare function normalizeScrollPolicy(scrollPolicy: false | ProTableScrollPolicy | undefined): NormalizedTableScrollPolicy;
32
+ declare function isLargeScreenByBreakpoint(breakpoint: Breakpoint | number, screens: Record<string, boolean>, screenWidth: number): boolean;
33
+ declare function getColumnWidthValue(column: ProColumnType<any>): number;
34
+ declare function getTableScrollX(columns: ProColumnType<any>[], hasRowSelection: boolean): number;
35
+ declare function useTableScroll<T = RecordType>(options: UseTableScrollOptions<T>): UseTableScrollReturn<T>;
34
36
  //#endregion
35
- export { useTableScroll };
37
+ export { NormalizedTableScrollPolicy, UseTableScrollOptions, UseTableScrollReturn, getColumnWidthValue, getTableScrollX, isLargeScreenByBreakpoint, normalizeScrollPolicy, useTableScroll };
@@ -1,36 +1,79 @@
1
- import { computed, unref } from "vue";
2
- import { cloneDeep, isBoolean, isNumber, isString, keysOf } from "@gx-design-vue/pro-utils";
3
-
1
+ import { computed } from "vue";
4
2
  //#region src/hooks/useTableScroll.ts
5
- function useTableScroll({ scroll, columns, autoScroll, modalScroll, neverScroll, rowSelection, screens, innerWidth, scrollBreakpoint }) {
6
- const breakpoint = computed(() => {
7
- if (scrollBreakpoint.value) return isNumber(scrollBreakpoint.value) ? innerWidth.value > scrollBreakpoint.value : isString(scrollBreakpoint.value) ? screens.value?.[scrollBreakpoint.value] : screens.value?.xl;
8
- return screens.value?.xl;
3
+ const DEFAULT_COLUMN_WIDTH = 150;
4
+ const ROW_SELECTION_WIDTH = 60;
5
+ const DEFAULT_MODAL_SCROLL_Y = {
6
+ desktop: 400,
7
+ mobile: 235
8
+ };
9
+ function normalizeScrollPolicy(scrollPolicy) {
10
+ if (scrollPolicy === false) return {
11
+ mode: "disabled",
12
+ breakpoint: "xl",
13
+ modal: false,
14
+ modalY: DEFAULT_MODAL_SCROLL_Y,
15
+ actionFixed: false
16
+ };
17
+ const modalY = typeof scrollPolicy?.modalY === "number" ? {
18
+ desktop: scrollPolicy.modalY,
19
+ mobile: scrollPolicy.modalY
20
+ } : {
21
+ desktop: scrollPolicy?.modalY?.desktop ?? DEFAULT_MODAL_SCROLL_Y.desktop,
22
+ mobile: scrollPolicy?.modalY?.mobile ?? DEFAULT_MODAL_SCROLL_Y.mobile
23
+ };
24
+ const mode = scrollPolicy?.mode ?? "auto";
25
+ return {
26
+ mode,
27
+ breakpoint: scrollPolicy?.breakpoint ?? "xl",
28
+ modal: mode === "auto" ? !!scrollPolicy?.modal : false,
29
+ modalY,
30
+ actionFixed: mode === "disabled" ? false : scrollPolicy?.actionFixed ?? "auto"
31
+ };
32
+ }
33
+ function isLargeScreenByBreakpoint(breakpoint, screens, screenWidth) {
34
+ return typeof breakpoint === "number" ? screenWidth >= breakpoint : !!screens[breakpoint];
35
+ }
36
+ function getColumnWidthValue(column) {
37
+ const width = Number.parseInt(String(column.width ?? ""), 10);
38
+ return Number.isFinite(width) && width > 0 ? width : DEFAULT_COLUMN_WIDTH;
39
+ }
40
+ function getTableScrollX(columns, hasRowSelection) {
41
+ return columns.reduce((total, column) => {
42
+ return total + getColumnWidthValue(column);
43
+ }, 0) + (hasRowSelection ? ROW_SELECTION_WIDTH : 0);
44
+ }
45
+ function useTableScroll(options) {
46
+ const normalizedScrollPolicy = computed(() => normalizeScrollPolicy(options.scrollPolicy.value));
47
+ const isLargeScreen = computed(() => {
48
+ const policy = normalizedScrollPolicy.value;
49
+ return isLargeScreenByBreakpoint(policy.breakpoint, options.screens.value, options.screenWidth.value);
50
+ });
51
+ const autoScrollX = computed(() => {
52
+ return getTableScrollX(options.columns.value, !!options.rowSelection.value);
53
+ });
54
+ const tableScroll = computed(() => {
55
+ const policy = normalizedScrollPolicy.value;
56
+ const explicitScroll = options.scroll.value;
57
+ if (policy.mode === "disabled") return {};
58
+ if (policy.mode === "manual") return explicitScroll ?? {};
59
+ const nextScroll = { ...explicitScroll ?? {} };
60
+ if (!nextScroll.x && !isLargeScreen.value) nextScroll.x = autoScrollX.value;
61
+ if (policy.modal && !nextScroll.y) nextScroll.y = isLargeScreen.value ? policy.modalY.desktop : policy.modalY.mobile;
62
+ return nextScroll;
9
63
  });
10
- const scrollX = computed(() => {
11
- let width = 0;
12
- const rowSelectWidth = unref(rowSelection) ? 60 : 0;
13
- const NORMAL_WIDTH = 150;
14
- const viewColumns = cloneDeep(unref(columns));
15
- viewColumns.forEach((item) => {
16
- width += Number.parseInt(String(item.width)) || 0;
17
- });
18
- const len = viewColumns.filter((item) => !Reflect.has(item, "width")).length;
19
- if (len !== 0) width += len * NORMAL_WIDTH;
20
- if (rowSelectWidth) width += rowSelectWidth;
21
- return width;
64
+ const hasHorizontalScroll = computed(() => {
65
+ return !!tableScroll.value?.x;
22
66
  });
23
67
  return {
24
- proScroll: computed(() => {
25
- if (neverScroll.value) return {};
26
- if (scroll.value && keysOf(scroll.value).length) return unref(scroll);
27
- if (modalScroll.value) return { y: scroll.value?.y || (screens.value?.xl ? 400 : 235) };
28
- if (!autoScroll.value) return {};
29
- return breakpoint.value ? {} : isBoolean(breakpoint.value) ? { x: scrollX.value } : {};
68
+ tableScroll,
69
+ hasHorizontalScroll,
70
+ shouldFixActionColumn: computed(() => {
71
+ const policy = normalizedScrollPolicy.value;
72
+ if (policy.mode === "disabled" || policy.actionFixed === false) return false;
73
+ return hasHorizontalScroll.value;
30
74
  }),
31
- breakpoint
75
+ normalizedScrollPolicy
32
76
  };
33
77
  }
34
-
35
78
  //#endregion
36
- export { useTableScroll };
79
+ export { getColumnWidthValue, getTableScrollX, isLargeScreenByBreakpoint, normalizeScrollPolicy, useTableScroll };
@@ -1,10 +1,20 @@
1
- import { Ref } from "vue";
2
- import { SizeType } from "@gx-design-vue/pro-utils";
1
+ import { ProTableSizeType } from "../interface.js";
2
+ import { ComputedRef } from "vue";
3
3
 
4
4
  //#region src/hooks/useTableSize.d.ts
5
- declare function useTableSize(options: {
6
- size: Ref<SizeType>;
7
- onChange: (value: SizeType) => void;
8
- }): [Ref<SizeType>, (value: SizeType) => void];
5
+ interface UseTableSizeOptions {
6
+ size: ComputedRef<ProTableSizeType | undefined>;
7
+ onChange?: (size: ProTableSizeType) => void;
8
+ }
9
+ interface UseTableSizeReturn {
10
+ tableSize: ComputedRef<ProTableSizeType>;
11
+ setTableSize: (size: ProTableSizeType) => void;
12
+ }
13
+ /**
14
+ * Table 尺寸状态管理。
15
+ * 纯 computed 实现,无 ref + watch 链。
16
+ * setTableSize 校验合法值后才触发 onChange 回调。
17
+ */
18
+ declare function useTableSize(options: UseTableSizeOptions): UseTableSizeReturn;
9
19
  //#endregion
10
- export { useTableSize };
20
+ export { UseTableSizeOptions, UseTableSizeReturn, useTableSize };
@@ -1,14 +1,26 @@
1
- import { ref, watch } from "vue";
2
-
1
+ import { computed } from "vue";
3
2
  //#region src/hooks/useTableSize.ts
3
+ const VALID_SIZES = new Set([
4
+ "small",
5
+ "medium",
6
+ "middle",
7
+ "large"
8
+ ]);
9
+ const DEFAULT_SIZE = "middle";
10
+ /**
11
+ * Table 尺寸状态管理。
12
+ * 纯 computed 实现,无 ref + watch 链。
13
+ * setTableSize 校验合法值后才触发 onChange 回调。
14
+ */
4
15
  function useTableSize(options) {
5
- const tableSize = ref(options.size.value || "middle");
6
- watch(() => options.size.value, (value) => tableSize.value = value);
7
- function setTableSize(value) {
8
- tableSize.value = value || tableSize.value;
16
+ const tableSize = computed(() => options.size.value ?? DEFAULT_SIZE);
17
+ function setTableSize(size) {
18
+ if (VALID_SIZES.has(size)) options.onChange?.(size);
9
19
  }
10
- return [tableSize, setTableSize];
20
+ return {
21
+ tableSize,
22
+ setTableSize
23
+ };
11
24
  }
12
-
13
25
  //#endregion
14
- export { useTableSize };
26
+ export { useTableSize };