@gx-design-vue/pro-table 0.2.0-alpha.2 → 0.2.0-alpha.21
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 -493
- package/dist/ProTable.js +902 -511
- package/dist/components/Drag/Handle.d.ts +90 -0
- package/dist/components/Drag/Handle.js +64 -0
- package/dist/components/Drag/Tbody.d.ts +17 -0
- package/dist/components/Drag/Tbody.js +27 -0
- package/dist/components/EllipsisText/index.d.ts +50 -0
- package/dist/components/EllipsisText/index.js +65 -0
- package/dist/components/ScrollBar/Bar.d.ts +79 -0
- package/dist/components/ScrollBar/Bar.js +84 -0
- package/dist/components/ScrollBar/Thumb.d.ts +50 -0
- package/dist/components/ScrollBar/{Thumb/index.js → Thumb.js} +67 -58
- package/dist/components/ScrollBar/context.d.ts +3 -4
- package/dist/components/ScrollBar/context.js +3 -5
- package/dist/components/ScrollBar/util.d.ts +6 -5
- package/dist/components/ScrollBar/util.js +1 -14
- package/dist/components/SearchForm/CollapseToggle.d.ts +53 -0
- package/dist/components/SearchForm/CollapseToggle.js +47 -0
- package/dist/components/SearchForm/FormItemContainer.d.ts +73 -0
- package/dist/components/SearchForm/FormItemContainer.js +225 -0
- package/dist/components/SearchForm/FormItemWrapper.d.ts +80 -0
- package/dist/components/SearchForm/FormItemWrapper.js +62 -0
- package/dist/components/SearchForm/SearchForm.d.ts +128 -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 +24 -0
- package/dist/components/Toolbar/FullscreenIcon.js +22 -0
- package/dist/components/Toolbar/ListToolBar.d.ts +109 -0
- package/dist/components/Toolbar/ListToolBar.js +101 -0
- package/dist/components/Toolbar/index.d.ts +101 -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 -5
- package/dist/hooks/index.d.ts +19 -0
- package/dist/hooks/index.js +19 -0
- package/dist/hooks/useAutoScroll.d.ts +32 -0
- package/dist/hooks/useAutoScroll.js +127 -0
- package/dist/hooks/useBreakpoints.d.ts +13 -0
- package/dist/hooks/useBreakpoints.js +65 -0
- package/dist/hooks/useCellRender.d.ts +13 -0
- package/dist/hooks/useCellRender.js +40 -0
- package/dist/hooks/useColumnResize.d.ts +29 -0
- package/dist/hooks/useColumnResize.js +112 -0
- package/dist/hooks/useColumns.d.ts +35 -24
- package/dist/hooks/useColumns.js +89 -58
- package/dist/hooks/useDragHandleColumn.d.ts +26 -0
- package/dist/hooks/useDragHandleColumn.js +52 -0
- package/dist/hooks/useEllipsis.d.ts +20 -0
- package/dist/hooks/useEllipsis.js +51 -0
- package/dist/hooks/useFetchData.d.ts +42 -65
- package/dist/hooks/useFetchData.js +160 -176
- 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 +27 -11
- package/dist/hooks/usePagination.d.ts +10 -7
- package/dist/hooks/usePagination.js +38 -29
- package/dist/hooks/useRequestOptions.d.ts +18 -0
- package/dist/hooks/useRequestOptions.js +39 -0
- package/dist/hooks/useRowDrag.d.ts +42 -0
- package/dist/hooks/useRowDrag.js +268 -0
- package/dist/hooks/useRowSelection.d.ts +27 -15
- package/dist/hooks/useRowSelection.js +93 -80
- package/dist/hooks/useTable.d.ts +35 -77
- package/dist/hooks/useTable.js +76 -49
- package/dist/hooks/useTableForm.d.ts +17 -82
- package/dist/hooks/useTableForm.js +137 -52
- package/dist/hooks/useTableScroll.d.ts +33 -31
- package/dist/hooks/useTableScroll.js +71 -28
- package/dist/hooks/useTableSize.d.ts +17 -7
- package/dist/hooks/useTableSize.js +21 -9
- package/dist/index.d.ts +11 -7
- package/dist/index.js +10 -4
- package/dist/interface.d.ts +537 -0
- package/dist/interface.js +1 -0
- package/dist/pro-table.esm.js +8897 -4012
- package/dist/pro-table.js +4 -1
- package/dist/style/ellipsis.d.ts +13 -0
- package/dist/style/ellipsis.js +16 -0
- package/dist/style/fit-page.d.ts +4 -2
- package/dist/style/fit-page.js +10 -5
- package/dist/style/index.d.ts +3 -7
- package/dist/style/index.js +38 -76
- package/dist/style/list.d.ts +4 -2
- package/dist/style/list.js +2 -12
- package/dist/style/resizable.d.ts +8 -0
- package/dist/style/resizable.js +18 -0
- package/dist/style/row-drag.d.ts +8 -0
- package/dist/style/row-drag.js +44 -0
- package/dist/style/scroll.d.ts +4 -2
- package/dist/style/scroll.js +9 -9
- package/dist/style/search.d.ts +8 -0
- package/dist/{components/Form/style.js → style/search.js} +22 -9
- package/dist/theme/augment.d.ts +8 -0
- package/dist/theme/augment.js +1 -0
- package/dist/theme/interface/components.d.ts +8 -0
- package/dist/theme/interface/components.js +1 -0
- package/dist/utils/arrayMove.d.ts +9 -0
- package/dist/utils/arrayMove.js +15 -0
- package/dist/utils/dateFormat.d.ts +9 -0
- package/dist/utils/dateFormat.js +29 -0
- package/dist/utils/ellipsis.d.ts +19 -0
- package/dist/utils/ellipsis.js +30 -0
- package/dist/utils/flipAnimate.d.ts +25 -0
- package/dist/utils/flipAnimate.js +40 -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 +23 -11
- package/dist/components/Form/components/RequestSelect.d.ts +0 -50
- package/dist/components/Form/components/RequestSelect.js +0 -58
- package/dist/components/Form/hooks/useForm.d.ts +0 -11
- package/dist/components/Form/hooks/useForm.js +0 -32
- package/dist/components/Form/index.d.ts +0 -33
- package/dist/components/Form/index.js +0 -479
- 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 -30
- package/dist/components/Form/utils/dateFormat.d.ts +0 -22
- package/dist/components/Form/utils/dateFormat.js +0 -45
- package/dist/components/ListToolBar/index.d.ts +0 -60
- 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 -71
- package/dist/components/ScrollBar/Bar/props.d.ts +0 -25
- package/dist/components/ScrollBar/Bar/props.js +0 -18
- 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 -18
- package/dist/components/TableCell/index.d.ts +0 -37
- package/dist/components/TableCell/index.js +0 -72
- package/dist/components/ToolBar/FullscreenIcon.d.ts +0 -7
- package/dist/components/ToolBar/FullscreenIcon.js +0 -14
- package/dist/components/ToolBar/index.d.ts +0 -34
- package/dist/components/ToolBar/index.js +0 -100
- package/dist/hooks/tryOnActivated.d.ts +0 -6
- package/dist/hooks/tryOnActivated.js +0 -14
- package/dist/hooks/useDebounceFn.d.ts +0 -8
- package/dist/hooks/useDebounceFn.js +0 -34
- package/dist/hooks/useScrollArea.d.ts +0 -24
- package/dist/hooks/useScrollArea.js +0 -104
- package/dist/props.d.ts +0 -340
- package/dist/props.js +0 -251
- package/dist/types/ColumnTypings.d.ts +0 -129
- package/dist/types/ColumnTypings.js +0 -1
- package/dist/types/SlotsTypings.d.ts +0 -63
- package/dist/types/SlotsTypings.js +0 -13
- package/dist/types/TableTypings.d.ts +0 -359
- package/dist/types/TableTypings.js +0 -1
- package/dist/types/index.d.ts +0 -9
- package/dist/types/index.js +0 -1
- package/dist/utils/utils.d.ts +0 -10
- package/dist/utils/utils.js +0 -91
package/dist/hooks/useTable.js
CHANGED
|
@@ -1,73 +1,100 @@
|
|
|
1
|
-
import { computed,
|
|
2
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const tableState = reactive({
|
|
7
|
+
params: {},
|
|
8
|
+
searchMap: []
|
|
9
|
+
});
|
|
10
|
+
const syncedStateKeys = /* @__PURE__ */ new Set();
|
|
11
|
+
function syncTableState(state = {}) {
|
|
12
|
+
for (const key of syncedStateKeys) if (!(key in state)) {
|
|
13
|
+
delete tableState[key];
|
|
14
|
+
syncedStateKeys.delete(key);
|
|
15
|
+
}
|
|
16
|
+
for (const key of Object.keys(state)) {
|
|
17
|
+
const nextValue = state[key];
|
|
18
|
+
if (nextValue !== tableState[key]) tableState[key] = nextValue;
|
|
19
|
+
syncedStateKeys.add(key);
|
|
14
20
|
}
|
|
15
|
-
|
|
21
|
+
if (options?.request) tableState.request = options.request;
|
|
16
22
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
watch(() => toValue(options?.state), (newState) => {
|
|
24
|
+
syncTableState(newState ?? {});
|
|
25
|
+
}, {
|
|
26
|
+
deep: true,
|
|
27
|
+
immediate: true
|
|
28
|
+
});
|
|
21
29
|
const actionRef = computed(() => {
|
|
22
|
-
|
|
23
|
-
return {};
|
|
30
|
+
return tableRef.value?.actionRef?.() ?? {};
|
|
24
31
|
});
|
|
25
32
|
const formRef = computed(() => {
|
|
26
|
-
|
|
27
|
-
return {};
|
|
33
|
+
return tableRef.value?.formRef?.() ?? {};
|
|
28
34
|
});
|
|
29
|
-
const requestSearch = computed(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
const loading = ref(!!actionRef.value?.loading?.value);
|
|
35
|
+
const requestSearch = computed(() => ({
|
|
36
|
+
...actionRef.value?.pageInfo || {},
|
|
37
|
+
...formRef.value?.getFormSearch?.() || {}
|
|
38
|
+
}));
|
|
39
|
+
const loading = ref(false);
|
|
36
40
|
watch(() => actionRef.value?.loading?.value, (val) => {
|
|
37
41
|
loading.value = !!val;
|
|
38
42
|
});
|
|
39
43
|
watch(loading, (val) => {
|
|
40
44
|
actionRef.value?.setLoading?.(!!val);
|
|
41
45
|
});
|
|
42
|
-
function
|
|
43
|
-
|
|
46
|
+
function reload(info) {
|
|
47
|
+
actionRef.value?.reload?.(info);
|
|
48
|
+
}
|
|
49
|
+
function setTableDataList(data) {
|
|
50
|
+
actionRef.value?.setTableDataList?.(data);
|
|
51
|
+
}
|
|
52
|
+
function operateTableDataRow(props) {
|
|
53
|
+
actionRef.value?.operateTableDataRow?.(props);
|
|
54
|
+
}
|
|
55
|
+
function setPageInfo(pagination, filters, sorter, extra) {
|
|
56
|
+
actionRef.value?.setPageInfo?.(pagination, filters, sorter, extra);
|
|
57
|
+
}
|
|
58
|
+
function setPagination(pagination) {
|
|
59
|
+
actionRef.value?.setPagination?.(pagination);
|
|
60
|
+
}
|
|
61
|
+
function reloadAndReset(options) {
|
|
62
|
+
actionRef.value?.reloadAndReset?.(options);
|
|
44
63
|
}
|
|
64
|
+
function setLoading(value) {
|
|
65
|
+
loading.value = value;
|
|
66
|
+
}
|
|
67
|
+
const selectedKeys = computed(() => actionRef.value?.selectedKeys?.value ?? []);
|
|
68
|
+
const selectedItems = computed(() => actionRef.value?.selectedItems?.value ?? []);
|
|
69
|
+
const rowsSelection = {
|
|
70
|
+
clear: () => actionRef.value?.rowsSelection?.clear?.(),
|
|
71
|
+
select: (record, selected) => actionRef.value?.rowsSelection?.select?.(record, selected),
|
|
72
|
+
selectAll: (records, selected) => actionRef.value?.rowsSelection?.selectAll?.(records, selected),
|
|
73
|
+
remove: (keys) => actionRef.value?.rowsSelection?.remove?.(keys),
|
|
74
|
+
sync: () => actionRef.value?.rowsSelection?.sync?.()
|
|
75
|
+
};
|
|
45
76
|
function updateSearchMap(key, value) {
|
|
46
|
-
if (tableState.searchMap) tableState.searchMap =
|
|
47
|
-
if (item.name === key) return deepMerge(item, value);
|
|
48
|
-
return item;
|
|
49
|
-
});
|
|
77
|
+
if (tableState.searchMap) tableState.searchMap = tableState.searchMap.map((item) => item.name === key ? merge({}, item, value) : item);
|
|
50
78
|
}
|
|
51
79
|
return {
|
|
52
|
-
|
|
80
|
+
loading,
|
|
81
|
+
dataSource: computed(() => actionRef.value?.dataSource?.value ?? EMPTY_ARRAY),
|
|
82
|
+
requestSearch,
|
|
83
|
+
selectedKeys,
|
|
84
|
+
selectedItems,
|
|
85
|
+
rowsSelection,
|
|
53
86
|
actionRef,
|
|
87
|
+
formRef,
|
|
88
|
+
reload,
|
|
89
|
+
setTableDataList,
|
|
90
|
+
operateTableDataRow,
|
|
91
|
+
setPageInfo,
|
|
92
|
+
setPagination,
|
|
93
|
+
reloadAndReset,
|
|
94
|
+
setLoading,
|
|
54
95
|
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
96
|
updateSearchMap
|
|
69
97
|
};
|
|
70
98
|
}
|
|
71
|
-
|
|
72
99
|
//#endregion
|
|
73
|
-
export { useTable };
|
|
100
|
+
export { useTable };
|
|
@@ -1,86 +1,21 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
params: ComputedRef<Record<string, any> | undefined>;
|
|
9
|
+
}
|
|
10
|
+
interface UseTableFormReturn {
|
|
11
|
+
formColumns: ComputedRef<ProSearchMap[]>;
|
|
12
|
+
formParamKeys: ComputedRef<string[]>;
|
|
13
|
+
defaultFormSearch: Ref<Record<string, any>>;
|
|
14
|
+
formState: Ref<Record<string, any>>;
|
|
15
|
+
getFormSearch: () => Record<string, any>;
|
|
16
|
+
resetFormState: () => void;
|
|
17
|
+
changeFormState: (key: string, value: any) => void;
|
|
18
|
+
}
|
|
19
|
+
declare function useTableForm(options: UseTableFormOptions): UseTableFormReturn;
|
|
85
20
|
//#endregion
|
|
86
|
-
export {
|
|
21
|
+
export { UseTableFormOptions, UseTableFormReturn, useTableForm };
|
|
@@ -1,69 +1,154 @@
|
|
|
1
|
-
import { ref, watch } from "vue";
|
|
2
|
-
import {
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (item.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
4
|
+
function hasOwnValue(target, key) {
|
|
5
|
+
return !!target && Object.hasOwn(target, key);
|
|
6
|
+
}
|
|
7
|
+
function sortFormItemsByOrder(items) {
|
|
8
|
+
let maxOrder = items.reduce((max, item) => {
|
|
9
|
+
return item.order !== void 0 ? Math.max(max, item.order) : max;
|
|
10
|
+
}, 0);
|
|
11
|
+
const sorted = items.map((item) => {
|
|
12
|
+
if (item.order === void 0) {
|
|
13
|
+
maxOrder += 1;
|
|
14
|
+
return {
|
|
15
|
+
...item,
|
|
16
|
+
order: maxOrder
|
|
17
|
+
};
|
|
20
18
|
}
|
|
19
|
+
return item;
|
|
21
20
|
});
|
|
22
|
-
|
|
21
|
+
sorted.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
22
|
+
return sorted;
|
|
23
|
+
}
|
|
24
|
+
function computeDefaultFormValues(columns, params) {
|
|
25
|
+
const defaults = {};
|
|
26
|
+
for (const col of columns) {
|
|
27
|
+
const valueType = col.valueType ?? "text";
|
|
28
|
+
const name = col.name;
|
|
29
|
+
if (valueType === "dateRange" && (col.rangeStartName || col.rangeEndName)) {
|
|
30
|
+
const startKey = col.rangeStartName || "start";
|
|
31
|
+
const endKey = col.rangeEndName || "end";
|
|
32
|
+
defaults[startKey] = hasOwnValue(params, startKey) ? params[startKey] : void 0;
|
|
33
|
+
defaults[endKey] = hasOwnValue(params, endKey) ? params[endKey] : void 0;
|
|
34
|
+
} else if (hasOwnValue(params, name)) defaults[name] = params[name];
|
|
35
|
+
else if (col.initialValue !== void 0) defaults[col.name] = col.initialValue;
|
|
36
|
+
else if (valueType === "numberRange") defaults[col.name] = [];
|
|
37
|
+
else if (valueType === "treeSelect" && (col.field?.treeCheckable || col.field?.multiple)) defaults[col.name] = [];
|
|
38
|
+
else if (valueType === "cascader" && col.field?.multiple) defaults[col.name] = [];
|
|
39
|
+
else if (valueType === "dateRange") defaults[col.name] = void 0;
|
|
40
|
+
}
|
|
41
|
+
return defaults;
|
|
23
42
|
}
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
};
|
|
43
|
+
function buildFormStateFromDefaults(defaults, columns) {
|
|
44
|
+
const state = cloneDeep(toRaw(defaults));
|
|
45
|
+
for (const record of columns) if (record.valueType === "dateRange" && (record.rangeStartName || record.rangeEndName)) {
|
|
46
|
+
const startKey = record.rangeStartName || "start";
|
|
47
|
+
const endKey = record.rangeEndName || "end";
|
|
48
|
+
const startValue = defaults[startKey];
|
|
49
|
+
const endValue = defaults[endKey];
|
|
50
|
+
if (startValue !== void 0 || endValue !== void 0) state[record.name] = [startValue, endValue];
|
|
43
51
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
function useTableForm(options) {
|
|
55
|
+
const { searchMap, columns, params } = options;
|
|
56
|
+
const formColumns = computed(() => {
|
|
57
|
+
const colsFromSearchMap = searchMap.value ?? [];
|
|
58
|
+
const searchMapNames = new Set(colsFromSearchMap.map((item) => item.name));
|
|
59
|
+
const colsFromColumns = columns.value.filter((col) => col.searchConfig).map((col) => ({
|
|
60
|
+
...col.searchConfig,
|
|
61
|
+
order: col.searchConfig.order ?? col.order ?? 0
|
|
62
|
+
})).filter((col) => !searchMapNames.has(col.name));
|
|
63
|
+
return sortFormItemsByOrder([...colsFromSearchMap, ...colsFromColumns]);
|
|
64
|
+
});
|
|
65
|
+
const formParamKeys = computed(() => {
|
|
66
|
+
const keys = /* @__PURE__ */ new Set();
|
|
67
|
+
for (const record of formColumns.value) {
|
|
68
|
+
if (record.name !== void 0) keys.add(record.name);
|
|
69
|
+
if (record.valueType === "dateRange" && (record.rangeStartName || record.rangeEndName)) {
|
|
70
|
+
keys.add(record.rangeStartName || "start");
|
|
71
|
+
keys.add(record.rangeEndName || "end");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return [...keys];
|
|
75
|
+
});
|
|
76
|
+
const defaultFormSearch = computed(() => {
|
|
77
|
+
return computeDefaultFormValues(formColumns.value, params.value);
|
|
78
|
+
});
|
|
79
|
+
const formState = ref({});
|
|
80
|
+
watch(() => defaultFormSearch.value, (newDefaults) => {
|
|
81
|
+
const nextState = { ...formState.value };
|
|
82
|
+
const defaultState = buildFormStateFromDefaults(newDefaults, formColumns.value);
|
|
83
|
+
for (const key of Object.keys(defaultState)) if (!hasOwnValue(nextState, key)) nextState[key] = defaultState[key];
|
|
84
|
+
formState.value = nextState;
|
|
48
85
|
}, {
|
|
49
86
|
deep: true,
|
|
50
87
|
immediate: true
|
|
51
88
|
});
|
|
52
|
-
watch(() =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
89
|
+
watch(() => params.value, (newParams) => {
|
|
90
|
+
if (!newParams) return;
|
|
91
|
+
const nextState = { ...formState.value };
|
|
92
|
+
for (const record of formColumns.value) {
|
|
93
|
+
const name = record.name;
|
|
94
|
+
if (record.valueType === "dateRange" && (record.rangeStartName || record.rangeEndName)) {
|
|
95
|
+
const startKey = record.rangeStartName || "start";
|
|
96
|
+
const endKey = record.rangeEndName || "end";
|
|
97
|
+
if (hasOwnValue(newParams, startKey) || hasOwnValue(newParams, endKey)) {
|
|
98
|
+
const startValue = newParams[startKey];
|
|
99
|
+
const endValue = newParams[endKey];
|
|
100
|
+
nextState[name] = startValue !== void 0 || endValue !== void 0 ? [startValue, endValue] : void 0;
|
|
101
|
+
}
|
|
102
|
+
} else if (hasOwnValue(newParams, name)) nextState[name] = newParams[name];
|
|
103
|
+
}
|
|
104
|
+
formState.value = nextState;
|
|
58
105
|
}, {
|
|
59
106
|
deep: true,
|
|
60
107
|
immediate: true
|
|
61
108
|
});
|
|
109
|
+
function getFormSearch() {
|
|
110
|
+
const searchParams = {};
|
|
111
|
+
for (const record of formColumns.value) {
|
|
112
|
+
const valueType = record.valueType ?? "text";
|
|
113
|
+
const name = record.name;
|
|
114
|
+
searchParams[name] = cloneDeep(toRaw(formState.value[name]));
|
|
115
|
+
if (valueType === "text") searchParams[name] = formState.value[name] ?? record.initialValue;
|
|
116
|
+
if (valueType === "dateRange" && (record.rangeStartName || record.rangeEndName)) {
|
|
117
|
+
const rangeValue = searchParams[name];
|
|
118
|
+
searchParams[record.rangeStartName || "start"] = Array.isArray(rangeValue) ? rangeValue[0] : void 0;
|
|
119
|
+
searchParams[record.rangeEndName || "end"] = Array.isArray(rangeValue) ? rangeValue[1] : void 0;
|
|
120
|
+
delete searchParams[name];
|
|
121
|
+
}
|
|
122
|
+
if (valueType === "cascader" && record.valueKey === "single") {
|
|
123
|
+
const value = searchParams[name];
|
|
124
|
+
searchParams[name] = Array.isArray(value) ? value[value.length - 1] : void 0;
|
|
125
|
+
}
|
|
126
|
+
if (valueType === "treeSelect" && Array.isArray(formState.value[name])) {
|
|
127
|
+
const keyField = record.valueKey === "text" ? "label" : "value";
|
|
128
|
+
searchParams[name] = formState.value[name].length > 0 ? formState.value[name].map((item) => item[keyField]).join(",") : void 0;
|
|
129
|
+
}
|
|
130
|
+
if (valueType === "numberRange") {
|
|
131
|
+
const value = searchParams[name];
|
|
132
|
+
searchParams[name] = Array.isArray(value) && value.some((val) => val !== void 0 && val !== null && val !== "") ? value : void 0;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return searchParams;
|
|
136
|
+
}
|
|
137
|
+
function resetFormState() {
|
|
138
|
+
formState.value = buildFormStateFromDefaults(cloneDeep(toRaw(defaultFormSearch.value)), formColumns.value);
|
|
139
|
+
}
|
|
140
|
+
function changeFormState(key, value) {
|
|
141
|
+
if (key) formState.value[key] = value;
|
|
142
|
+
}
|
|
62
143
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
144
|
+
formColumns,
|
|
145
|
+
formParamKeys,
|
|
146
|
+
defaultFormSearch,
|
|
147
|
+
formState,
|
|
148
|
+
getFormSearch,
|
|
149
|
+
resetFormState,
|
|
150
|
+
changeFormState
|
|
65
151
|
};
|
|
66
152
|
}
|
|
67
|
-
|
|
68
153
|
//#endregion
|
|
69
|
-
export {
|
|
154
|
+
export { useTableForm };
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
11
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
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
|
-
|
|
75
|
+
normalizedScrollPolicy
|
|
32
76
|
};
|
|
33
77
|
}
|
|
34
|
-
|
|
35
78
|
//#endregion
|
|
36
|
-
export { useTableScroll };
|
|
79
|
+
export { getColumnWidthValue, getTableScrollX, isLargeScreenByBreakpoint, normalizeScrollPolicy, useTableScroll };
|