@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BarExpose } from "../components/ScrollBar/Bar.js";
|
|
2
|
+
import { ComputedRef, Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/useFitPage.d.ts
|
|
5
|
+
interface UseFitPageOptions {
|
|
6
|
+
fitPage: ComputedRef<boolean>;
|
|
7
|
+
cardEl: Ref<HTMLElement | undefined>;
|
|
8
|
+
prefixCls: ComputedRef<string>;
|
|
9
|
+
}
|
|
10
|
+
interface UseFitPageReturn {
|
|
11
|
+
scrollY: ComputedRef<number>;
|
|
12
|
+
overflowHidden: ComputedRef<boolean>;
|
|
13
|
+
fullPageClass: ComputedRef<string>;
|
|
14
|
+
scrollEl: Ref<HTMLElement | undefined>;
|
|
15
|
+
barRef: Ref<BarExpose | undefined>;
|
|
16
|
+
}
|
|
17
|
+
declare function useFitPage(options: UseFitPageOptions): UseFitPageReturn;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { UseFitPageOptions, UseFitPageReturn, useFitPage };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useProvideScrollBarContext } from "../components/ScrollBar/context.js";
|
|
2
|
+
import { computed, ref, watchEffect } from "vue";
|
|
3
|
+
import { useElementSize, useMutationObserver, useResizeObserver, useScroll } from "@vueuse/core";
|
|
4
|
+
import { onMountedOrActivated } from "@gx-design-vue/pro-hooks";
|
|
5
|
+
//#region src/hooks/useFitPage.ts
|
|
6
|
+
function queryChildElements(card, prefixCls, targets) {
|
|
7
|
+
targets.toolbarEl.value = card.querySelector(`.${prefixCls}-list-toolbar`) ?? void 0;
|
|
8
|
+
targets.headerEl.value = card.querySelector(".ant-table-header") ?? void 0;
|
|
9
|
+
targets.pageEl.value = card.querySelector(".ant-table-pagination") ?? void 0;
|
|
10
|
+
targets.scrollEl.value = card.querySelector(".ant-table-body") ?? void 0;
|
|
11
|
+
targets.bodyInnerEl.value = card.querySelector(".ant-table-body > table") ?? void 0;
|
|
12
|
+
}
|
|
13
|
+
function getElementBlockMargin(el) {
|
|
14
|
+
if (!el) return 0;
|
|
15
|
+
const style = getComputedStyle(el);
|
|
16
|
+
return (Number.parseFloat(style.marginTop) || 0) + (Number.parseFloat(style.marginBottom) || 0);
|
|
17
|
+
}
|
|
18
|
+
function useFitPage(options) {
|
|
19
|
+
const { fitPage, cardEl, prefixCls } = options;
|
|
20
|
+
const barRef = ref();
|
|
21
|
+
const toolbarEl = ref();
|
|
22
|
+
const headerEl = ref();
|
|
23
|
+
const pageEl = ref();
|
|
24
|
+
const scrollEl = ref();
|
|
25
|
+
const bodyInnerEl = ref();
|
|
26
|
+
const childRefs = {
|
|
27
|
+
toolbarEl,
|
|
28
|
+
headerEl,
|
|
29
|
+
pageEl,
|
|
30
|
+
scrollEl,
|
|
31
|
+
bodyInnerEl
|
|
32
|
+
};
|
|
33
|
+
const { height: cardHeight } = useElementSize(cardEl);
|
|
34
|
+
const { height: toolbarHeight } = useElementSize(toolbarEl);
|
|
35
|
+
const { height: headerHeight } = useElementSize(headerEl);
|
|
36
|
+
const { height: pageHeight } = useElementSize(pageEl);
|
|
37
|
+
const { height: bodyContentHeight } = useElementSize(bodyInnerEl);
|
|
38
|
+
useMutationObserver(cardEl, () => {
|
|
39
|
+
if (cardEl.value) queryChildElements(cardEl.value, prefixCls.value, childRefs);
|
|
40
|
+
}, {
|
|
41
|
+
childList: true,
|
|
42
|
+
subtree: true
|
|
43
|
+
});
|
|
44
|
+
onMountedOrActivated(() => {
|
|
45
|
+
if (cardEl.value) queryChildElements(cardEl.value, prefixCls.value, childRefs);
|
|
46
|
+
});
|
|
47
|
+
const toolbarMargin = computed(() => getElementBlockMargin(toolbarEl.value));
|
|
48
|
+
const pageMargin = computed(() => {
|
|
49
|
+
return getElementBlockMargin(pageEl.value);
|
|
50
|
+
});
|
|
51
|
+
const scrollY = computed(() => {
|
|
52
|
+
if (!cardEl.value || !fitPage.value) return 0;
|
|
53
|
+
const tableHeight = cardHeight.value - toolbarHeight.value - toolbarMargin.value - headerHeight.value - pageHeight.value - pageMargin.value;
|
|
54
|
+
return Math.max(0, tableHeight);
|
|
55
|
+
});
|
|
56
|
+
const overflowHidden = computed(() => {
|
|
57
|
+
if (!scrollY.value || !fitPage.value) return false;
|
|
58
|
+
return bodyContentHeight.value <= scrollY.value;
|
|
59
|
+
});
|
|
60
|
+
const fullPageClass = computed(() => {
|
|
61
|
+
return fitPage.value ? `${prefixCls.value}-full-page` : "";
|
|
62
|
+
});
|
|
63
|
+
watchEffect(() => {
|
|
64
|
+
if (!scrollEl.value) return;
|
|
65
|
+
if (fitPage.value && scrollY.value > 0) scrollEl.value.style.height = `${scrollY.value}px`;
|
|
66
|
+
else scrollEl.value.style.height = "";
|
|
67
|
+
});
|
|
68
|
+
useScroll(scrollEl, { onScroll: () => {
|
|
69
|
+
if (scrollEl.value) barRef.value?.handleScroll(scrollEl.value);
|
|
70
|
+
} });
|
|
71
|
+
useResizeObserver(scrollEl, () => {
|
|
72
|
+
barRef.value?.update();
|
|
73
|
+
});
|
|
74
|
+
useProvideScrollBarContext({
|
|
75
|
+
className: `${prefixCls.value}-scroll`,
|
|
76
|
+
tableHeaderHeight: headerHeight,
|
|
77
|
+
tableScrollYHeight: scrollY,
|
|
78
|
+
scrollbarElement: cardEl,
|
|
79
|
+
wrapElement: scrollEl
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
scrollY,
|
|
83
|
+
overflowHidden,
|
|
84
|
+
fullPageClass,
|
|
85
|
+
scrollEl,
|
|
86
|
+
barRef
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export { useFitPage };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/useKeepAliveReload.d.ts
|
|
4
|
+
interface UseKeepAliveReloadOptions {
|
|
5
|
+
enabled: ComputedRef<boolean>;
|
|
6
|
+
reload: () => void;
|
|
7
|
+
}
|
|
8
|
+
interface UseKeepAliveReloadReturn {
|
|
9
|
+
hasActivated: Ref<boolean>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 安全的 onActivated 包装:无组件实例时直接执行回调。
|
|
13
|
+
*/
|
|
14
|
+
declare function tryOnActivated(callback: () => void): void;
|
|
15
|
+
/**
|
|
16
|
+
* Keep-alive 页面重新进入时触发数据请求。
|
|
17
|
+
* 首次激活仅标记状态,后续激活且 enabled 为 true 时调用 reload。
|
|
18
|
+
*/
|
|
19
|
+
declare function useKeepAliveReload(options: UseKeepAliveReloadOptions): UseKeepAliveReloadReturn;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { UseKeepAliveReloadOptions, UseKeepAliveReloadReturn, tryOnActivated, useKeepAliveReload };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getCurrentInstance, nextTick, onActivated, ref } from "vue";
|
|
2
|
+
//#region src/hooks/useKeepAliveReload.ts
|
|
3
|
+
/**
|
|
4
|
+
* 安全的 onActivated 包装:无组件实例时直接执行回调。
|
|
5
|
+
*/
|
|
6
|
+
function tryOnActivated(callback) {
|
|
7
|
+
if (getCurrentInstance()) onActivated(callback);
|
|
8
|
+
else nextTick(callback);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Keep-alive 页面重新进入时触发数据请求。
|
|
12
|
+
* 首次激活仅标记状态,后续激活且 enabled 为 true 时调用 reload。
|
|
13
|
+
*/
|
|
14
|
+
function useKeepAliveReload(options) {
|
|
15
|
+
const hasActivated = ref(false);
|
|
16
|
+
tryOnActivated(() => {
|
|
17
|
+
if (hasActivated.value) {
|
|
18
|
+
if (options.enabled.value) options.reload();
|
|
19
|
+
} else hasActivated.value = true;
|
|
20
|
+
});
|
|
21
|
+
return { hasActivated };
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { tryOnActivated, useKeepAliveReload };
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Ref } from "vue";
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
3
2
|
|
|
4
3
|
//#region src/hooks/useLoading.d.ts
|
|
5
|
-
|
|
6
|
-
loading:
|
|
7
|
-
|
|
8
|
-
}
|
|
4
|
+
interface UseLoadingOptions {
|
|
5
|
+
loading: ComputedRef<boolean | {
|
|
6
|
+
spinning?: boolean;
|
|
7
|
+
} | undefined>;
|
|
8
|
+
onChange?: (loading: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
interface UseLoadingReturn {
|
|
11
|
+
loading: Ref<boolean>;
|
|
12
|
+
setLoading: (value: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Table loading 状态管理。
|
|
16
|
+
* 支持 boolean 和 SpinProps 对象两种 loading prop 形式,
|
|
17
|
+
* 内部始终维护 boolean 状态,外部 prop 变化时自动同步。
|
|
18
|
+
*/
|
|
19
|
+
declare function useLoading(options: UseLoadingOptions): UseLoadingReturn;
|
|
9
20
|
//#endregion
|
|
10
|
-
export { useLoading };
|
|
21
|
+
export { UseLoadingOptions, UseLoadingReturn, useLoading };
|
package/dist/hooks/useLoading.js
CHANGED
|
@@ -1,20 +1,36 @@
|
|
|
1
1
|
import { ref, watch } from "vue";
|
|
2
2
|
import { isBoolean, isObject } from "@gx-design-vue/pro-utils";
|
|
3
|
-
|
|
4
3
|
//#region src/hooks/useLoading.ts
|
|
4
|
+
/** 从 boolean 或 SpinProps 对象中提取 spinning 状态 */
|
|
5
|
+
function toSpinning(value, fallback = false) {
|
|
6
|
+
if (isBoolean(value)) return value;
|
|
7
|
+
if (isObject(value)) return value.spinning ?? fallback;
|
|
8
|
+
return fallback;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Table loading 状态管理。
|
|
12
|
+
* 支持 boolean 和 SpinProps 对象两种 loading prop 形式,
|
|
13
|
+
* 内部始终维护 boolean 状态,外部 prop 变化时自动同步。
|
|
14
|
+
*/
|
|
5
15
|
function useLoading(options) {
|
|
6
|
-
const loading = ref(
|
|
7
|
-
watch(() => options.loading.value, (
|
|
8
|
-
|
|
16
|
+
const loading = ref(toSpinning(options.loading.value));
|
|
17
|
+
watch(() => options.loading.value, (propValue) => {
|
|
18
|
+
const next = toSpinning(propValue, loading.value);
|
|
19
|
+
if (next !== loading.value) {
|
|
20
|
+
loading.value = next;
|
|
21
|
+
options.onChange?.(next);
|
|
22
|
+
}
|
|
9
23
|
});
|
|
10
|
-
function getStatus(value, defaultValue = false) {
|
|
11
|
-
return isBoolean(value) ? value : isObject(value) ? value?.spinning ?? defaultValue : defaultValue;
|
|
12
|
-
}
|
|
13
24
|
function setLoading(value) {
|
|
14
|
-
loading.value
|
|
25
|
+
if (loading.value !== value) {
|
|
26
|
+
loading.value = value;
|
|
27
|
+
options.onChange?.(value);
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
loading,
|
|
32
|
+
setLoading
|
|
33
|
+
};
|
|
17
34
|
}
|
|
18
|
-
|
|
19
35
|
//#endregion
|
|
20
|
-
export { useLoading };
|
|
36
|
+
export { useLoading };
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PageState, ProTablePagination, ProTableProps } from "../types/TableTypings.js";
|
|
1
|
+
import { PageState, ProTablePagination, ProTablePaginationConfig } from "../interface.js";
|
|
3
2
|
import { Ref } from "vue";
|
|
4
3
|
|
|
5
4
|
//#region src/hooks/usePagination.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* 分页状态管理。
|
|
7
|
+
* 合并用户分页配置与默认值,分离 UI 分页展示与请求分页参数。
|
|
8
|
+
* setPagination 只同步 current/pageSize/total 到 requestPagination,避免 UI 字段污染请求参数。
|
|
9
|
+
*/
|
|
6
10
|
declare function usePagination({
|
|
7
|
-
pagination
|
|
8
|
-
pageItemRender
|
|
11
|
+
pagination
|
|
9
12
|
}: {
|
|
10
|
-
pagination: Ref<
|
|
11
|
-
pageItemRender: PageItemRender;
|
|
13
|
+
pagination: Ref<ProTablePagination | undefined>;
|
|
12
14
|
}): {
|
|
13
15
|
paginationInfo: Ref<ProTablePagination | false>;
|
|
16
|
+
paginationAlign: Ref<'start' | 'center' | 'end'>;
|
|
14
17
|
requestPagination: PageState;
|
|
15
|
-
setPagination: (info: Partial<
|
|
18
|
+
setPagination: (info: Partial<ProTablePaginationConfig>) => void;
|
|
16
19
|
};
|
|
17
20
|
//#endregion
|
|
18
21
|
export { usePagination };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { reactive, ref,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/hooks/usePagination.tsx
|
|
1
|
+
import { computed, reactive, ref, watch } from "vue";
|
|
2
|
+
import { isNumber, merge } from "@gx-design-vue/pro-utils";
|
|
3
|
+
//#region src/hooks/usePagination.ts
|
|
5
4
|
const defaultPagination = {
|
|
6
5
|
current: 1,
|
|
7
6
|
pageSize: 10,
|
|
8
|
-
size: "default",
|
|
9
7
|
showQuickJumper: true,
|
|
10
8
|
showSizeChanger: true,
|
|
11
9
|
pageSizeOptions: [
|
|
@@ -15,48 +13,59 @@ const defaultPagination = {
|
|
|
15
13
|
"100"
|
|
16
14
|
]
|
|
17
15
|
};
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* 分页状态管理。
|
|
18
|
+
* 合并用户分页配置与默认值,分离 UI 分页展示与请求分页参数。
|
|
19
|
+
* setPagination 只同步 current/pageSize/total 到 requestPagination,避免 UI 字段污染请求参数。
|
|
20
|
+
*/
|
|
21
|
+
function usePagination({ pagination }) {
|
|
19
22
|
const paginationInfo = ref({ ...defaultPagination });
|
|
20
23
|
const requestPagination = reactive({
|
|
21
|
-
current: defaultPagination.current
|
|
22
|
-
pageSize: defaultPagination.pageSize
|
|
24
|
+
current: defaultPagination.current,
|
|
25
|
+
pageSize: defaultPagination.pageSize,
|
|
23
26
|
total: 0
|
|
24
27
|
});
|
|
25
|
-
watch(() => pagination.value, () => {
|
|
26
|
-
if (
|
|
28
|
+
watch(() => pagination.value, (paginationValue) => {
|
|
29
|
+
if (paginationValue === false) {
|
|
27
30
|
paginationInfo.value = false;
|
|
28
31
|
return;
|
|
29
32
|
}
|
|
30
|
-
const
|
|
31
|
-
page,
|
|
32
|
-
type,
|
|
33
|
-
originalElement
|
|
34
|
-
}) : null } : null;
|
|
35
|
-
const pageInfo = {
|
|
33
|
+
const merged = {
|
|
36
34
|
...defaultPagination,
|
|
37
|
-
...
|
|
38
|
-
...itemRenderProps || {}
|
|
35
|
+
...paginationValue || {}
|
|
39
36
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
forInObject(requestPagination, (key) => {
|
|
43
|
-
if (isNumber(pageInfo[key])) requestPagination[key] = pageInfo[key];
|
|
44
|
-
});
|
|
37
|
+
paginationInfo.value = merged;
|
|
38
|
+
syncRequestPagination(merged);
|
|
45
39
|
}, {
|
|
46
|
-
deep:
|
|
40
|
+
deep: true,
|
|
47
41
|
immediate: true
|
|
48
42
|
});
|
|
49
|
-
function
|
|
43
|
+
function syncRequestPagination(info) {
|
|
44
|
+
if (isNumber(info.current)) requestPagination.current = info.current;
|
|
45
|
+
if (isNumber(info.pageSize)) requestPagination.pageSize = info.pageSize;
|
|
46
|
+
if (isNumber(info.total)) requestPagination.total = info.total;
|
|
47
|
+
}
|
|
48
|
+
function setPagination(info) {
|
|
50
49
|
if (paginationInfo.value === false) return;
|
|
51
|
-
paginationInfo.value =
|
|
52
|
-
|
|
50
|
+
paginationInfo.value = merge({}, paginationInfo.value, info);
|
|
51
|
+
syncRequestPagination(info);
|
|
53
52
|
}
|
|
54
53
|
return {
|
|
55
54
|
paginationInfo,
|
|
55
|
+
paginationAlign: computed(() => {
|
|
56
|
+
const paginationConfig = paginationInfo.value;
|
|
57
|
+
if (!paginationConfig) return "end";
|
|
58
|
+
const placementList = paginationConfig.placement;
|
|
59
|
+
if (!Array.isArray(placementList)) return "end";
|
|
60
|
+
const matchedPlacement = placementList.find((item) => item.includes("bottom") || item.includes("top"));
|
|
61
|
+
if (!matchedPlacement) return "end";
|
|
62
|
+
if (matchedPlacement.includes("Start")) return "start";
|
|
63
|
+
if (matchedPlacement.includes("Center")) return "center";
|
|
64
|
+
return "end";
|
|
65
|
+
}),
|
|
56
66
|
requestPagination,
|
|
57
67
|
setPagination
|
|
58
68
|
};
|
|
59
69
|
}
|
|
60
|
-
|
|
61
70
|
//#endregion
|
|
62
|
-
export { usePagination };
|
|
71
|
+
export { usePagination };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ProSchemaValueEnumType } from "../interface.js";
|
|
2
|
+
import { Ref } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/hooks/useRequestOptions.d.ts
|
|
5
|
+
interface UseRequestOptionsParams {
|
|
6
|
+
fetch?: () => Promise<ProSchemaValueEnumType[]>;
|
|
7
|
+
manual?: boolean;
|
|
8
|
+
debounceTime?: number;
|
|
9
|
+
}
|
|
10
|
+
interface UseRequestOptionsReturn {
|
|
11
|
+
optionList: Ref<ProSchemaValueEnumType[]>;
|
|
12
|
+
loading: Ref<boolean>;
|
|
13
|
+
status: Ref<'idle' | 'loading' | 'success' | 'error'>;
|
|
14
|
+
fetchOptions: () => Promise<ProSchemaValueEnumType[] | undefined>;
|
|
15
|
+
}
|
|
16
|
+
declare function useRequestOptions(params: UseRequestOptionsParams): UseRequestOptionsReturn;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { UseRequestOptionsParams, UseRequestOptionsReturn, useRequestOptions };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { onUnmounted, ref } from "vue";
|
|
2
|
+
import { useDebounceFn } from "@vueuse/core";
|
|
3
|
+
//#region src/hooks/useRequestOptions.ts
|
|
4
|
+
function useRequestOptions(params) {
|
|
5
|
+
const optionList = ref([]);
|
|
6
|
+
const loading = ref(false);
|
|
7
|
+
const status = ref("idle");
|
|
8
|
+
const debouncedFetch = useDebounceFn(async () => {
|
|
9
|
+
if (!params.fetch) return;
|
|
10
|
+
loading.value = true;
|
|
11
|
+
status.value = "loading";
|
|
12
|
+
try {
|
|
13
|
+
const result = await params.fetch();
|
|
14
|
+
optionList.value = result ?? [];
|
|
15
|
+
status.value = "success";
|
|
16
|
+
return result;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error("[useRequestOptions] fetch error:", error);
|
|
19
|
+
status.value = "error";
|
|
20
|
+
optionList.value = [];
|
|
21
|
+
return;
|
|
22
|
+
} finally {
|
|
23
|
+
loading.value = false;
|
|
24
|
+
}
|
|
25
|
+
}, params.debounceTime ?? 10);
|
|
26
|
+
if (params.fetch && !params.manual) debouncedFetch();
|
|
27
|
+
onUnmounted(() => {
|
|
28
|
+
optionList.value = [];
|
|
29
|
+
loading.value = false;
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
optionList,
|
|
33
|
+
loading,
|
|
34
|
+
status,
|
|
35
|
+
fetchOptions: debouncedFetch
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { useRequestOptions };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ProTableRowDragOptions } from "../interface.js";
|
|
2
|
+
import { ComputedRef, Ref } from "vue";
|
|
3
|
+
import { RecordType } from "@gx-design-vue/pro-utils";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/useRowDrag.d.ts
|
|
6
|
+
interface UseRowDragOptions<T = RecordType> {
|
|
7
|
+
/** tbody DOM 引用(通过 components.body.wrapper 覆写拿到) */
|
|
8
|
+
tbodyEl: Ref<HTMLElement | undefined>;
|
|
9
|
+
/** 表格滚动容器(用于垂直自动滚动) */
|
|
10
|
+
scrollEl: Ref<HTMLElement | undefined>;
|
|
11
|
+
/** 数据源(只读 computed) */
|
|
12
|
+
dataSource: ComputedRef<T[]>;
|
|
13
|
+
/** 行唯一标识字段 */
|
|
14
|
+
rowKey: ComputedRef<string>;
|
|
15
|
+
/** 行拖拽配置(含 disabled 谓词) */
|
|
16
|
+
rowDraggable: ComputedRef<boolean | ProTableRowDragOptions | undefined>;
|
|
17
|
+
/** 拖拽排序完成回调(仅通知重排结果,由调用方决定是否回写数据源) */
|
|
18
|
+
onSortEnd?: (from: number, to: number, newData: T[], record: T) => void;
|
|
19
|
+
}
|
|
20
|
+
/** onRow 返回的行属性(对标 antdv 的 CellAttributes 子集) */
|
|
21
|
+
type RowDragCellProps = Record<string, any>;
|
|
22
|
+
interface UseRowDragReturn {
|
|
23
|
+
isDragging: Ref<boolean>;
|
|
24
|
+
draggingRowKey: Ref<string | number>;
|
|
25
|
+
/** 返回 onRow 函数(antdv Table 的 onRow 签名) */
|
|
26
|
+
getRowProps: (record: any, index: number) => RowDragCellProps;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 表格行拖拽排序 —— 精简复刻 `useTabDrag` 的垂直版本。
|
|
30
|
+
*
|
|
31
|
+
* - 仅从把手列(`[data-drag-handle]`)发起拖拽,单元格交互不受影响
|
|
32
|
+
* - 移动阈值(3px)区分点击与拖拽
|
|
33
|
+
* - 拖拽行 `transform: translateY(delta)` 跟随指针
|
|
34
|
+
* - 同列表其他行按虚拟插入位置实时 `translate` 让位(CSS translate 属性 + WAAPI)
|
|
35
|
+
* - drop 锚点用最近中心法(被拖行中心 Y 与全量各行中心比距离取最近者;含自身,半身位即换位)
|
|
36
|
+
* - 松手 → onSortEnd(仅 emit 排序结果,由使用方回写数据源)→ nextTick 用 flipAnimate 平滑归位
|
|
37
|
+
* - 拖拽结束后捕获抑制下一次 click
|
|
38
|
+
* - 指针接近滚动容器上下边缘时自动滚动(垂直版 detectScrollIntent)
|
|
39
|
+
*/
|
|
40
|
+
declare function useRowDrag<T = RecordType>(options: UseRowDragOptions<T>): UseRowDragReturn;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { RowDragCellProps, UseRowDragOptions, UseRowDragReturn, useRowDrag };
|