@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.
- package/dist/ProTable.d.ts +14 -493
- package/dist/ProTable.js +818 -512
- package/dist/components/ScrollBar/Bar.d.ts +81 -0
- package/dist/components/ScrollBar/Bar.js +84 -0
- package/dist/components/ScrollBar/Thumb.d.ts +52 -0
- package/dist/components/ScrollBar/{Thumb/index.js → Thumb.js} +67 -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 +55 -0
- package/dist/components/SearchForm/CollapseToggle.js +47 -0
- package/dist/components/SearchForm/FormItemContainer.d.ts +75 -0
- package/dist/components/SearchForm/FormItemContainer.js +225 -0
- package/dist/components/SearchForm/FormItemWrapper.d.ts +82 -0
- package/dist/components/SearchForm/FormItemWrapper.js +62 -0
- package/dist/components/SearchForm/SearchForm.d.ts +130 -0
- package/dist/components/SearchForm/SearchForm.js +319 -0
- package/dist/components/SearchForm/index.d.ts +2 -0
- package/dist/components/SearchForm/index.js +2 -0
- package/dist/components/Toolbar/FullscreenIcon.d.ts +26 -0
- package/dist/components/Toolbar/FullscreenIcon.js +22 -0
- package/dist/components/Toolbar/ListToolBar.d.ts +111 -0
- package/dist/components/Toolbar/ListToolBar.js +101 -0
- package/dist/components/Toolbar/index.d.ts +103 -0
- package/dist/components/Toolbar/index.js +101 -0
- package/dist/components/Toolbar/style.d.ts +8 -0
- package/dist/components/{ListToolBar → Toolbar}/style.js +32 -27
- package/dist/context/TableContext.d.ts +15 -27
- package/dist/context/TableContext.js +3 -5
- package/dist/hooks/index.d.ts +16 -0
- package/dist/hooks/index.js +16 -0
- package/dist/hooks/useBreakpoints.d.ts +13 -0
- package/dist/hooks/useBreakpoints.js +57 -0
- package/dist/hooks/useCellRender.d.ts +13 -0
- package/dist/hooks/useCellRender.js +28 -0
- package/dist/hooks/useColumnResize.d.ts +30 -0
- package/dist/hooks/useColumnResize.js +110 -0
- package/dist/hooks/useColumns.d.ts +35 -24
- package/dist/hooks/useColumns.js +89 -58
- package/dist/hooks/useFetchData.d.ts +40 -65
- package/dist/hooks/useFetchData.js +157 -174
- 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/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 +72 -50
- package/dist/hooks/useTableForm.d.ts +15 -82
- package/dist/hooks/useTableForm.js +93 -55
- 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 +10 -7
- package/dist/index.js +9 -4
- package/dist/interface.d.ts +499 -0
- package/dist/interface.js +1 -0
- package/dist/pro-table.esm.js +3579 -3834
- package/dist/pro-table.js +1 -1
- package/dist/style/fit-page.d.ts +4 -2
- package/dist/style/fit-page.js +10 -5
- package/dist/style/index.d.ts +4 -6
- package/dist/style/index.js +24 -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/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/dateFormat.d.ts +9 -0
- package/dist/utils/dateFormat.js +29 -0
- package/dist/utils/formConstants.d.ts +9 -0
- package/dist/utils/formConstants.js +29 -0
- package/dist/utils/valueFormat.d.ts +9 -0
- package/dist/utils/valueFormat.js +27 -0
- package/package.json +11 -10
- 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 -127
- 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
|
@@ -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 };
|
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Ref } from "vue";
|
|
1
|
+
import { ComputedRef } from "vue";
|
|
3
2
|
import { RecordType } from "@gx-design-vue/pro-utils";
|
|
4
|
-
import {
|
|
5
|
-
import { Key } from "ant-design-vue/es/vc-table/interface";
|
|
3
|
+
import { Key, TableRowSelection } from "antdv-next/dist/table/interface";
|
|
6
4
|
|
|
7
5
|
//#region src/hooks/useRowSelection.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
interface UseRowSelectionOptions<T = RecordType> {
|
|
7
|
+
rowKey: ComputedRef<string>;
|
|
8
|
+
rowSelection: ComputedRef<TableRowSelection<T> | undefined>;
|
|
9
|
+
dataSource: ComputedRef<T[]>;
|
|
10
|
+
}
|
|
11
|
+
interface UseRowSelectionReturn<T = RecordType> {
|
|
12
|
+
selectedRowKeys: ComputedRef<Key[]>;
|
|
13
|
+
selectedItems: ComputedRef<T[]>;
|
|
14
|
+
mergedRowSelection: ComputedRef<TableRowSelection<T> | undefined>;
|
|
15
|
+
select: (record: T, selected: boolean) => void;
|
|
16
|
+
selectAll: (records: T[], selected: boolean) => void;
|
|
17
|
+
remove: (keys: Key[]) => void;
|
|
18
|
+
clear: () => void;
|
|
19
|
+
sync: () => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 行选择状态管理。内部使用 reactive Map 作为唯一数据源,
|
|
23
|
+
* selectedRowKeys / selectedItems 均从 Map 派生,保证 keys 与 items 永远同步。
|
|
24
|
+
*
|
|
25
|
+
* antdv-next 已废弃 onSelectAll / onSelectInvert / onSelectNone,
|
|
26
|
+
* 所有选中变化统一通过 onChange 回调,因此 mergedRowSelection 只拦截 onChange,
|
|
27
|
+
* 不拦截 onSelect / onSelectAll。
|
|
28
|
+
*/
|
|
29
|
+
declare function useRowSelection<T = RecordType>(options: UseRowSelectionOptions<T>): UseRowSelectionReturn<T>;
|
|
18
30
|
//#endregion
|
|
19
|
-
export { useRowSelection };
|
|
31
|
+
export { UseRowSelectionOptions, UseRowSelectionReturn, useRowSelection };
|
|
@@ -1,89 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { arrayUnique, cloneDeep } from "@gx-design-vue/pro-utils";
|
|
3
|
-
|
|
1
|
+
import { computed, onScopeDispose, reactive, watch } from "vue";
|
|
4
2
|
//#region src/hooks/useRowSelection.ts
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
selectedKeys.value = [record[rowKey.value]];
|
|
27
|
-
selectedItems.value = [record];
|
|
3
|
+
function getKey(record, rowKey) {
|
|
4
|
+
return record[rowKey];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 行选择状态管理。内部使用 reactive Map 作为唯一数据源,
|
|
8
|
+
* selectedRowKeys / selectedItems 均从 Map 派生,保证 keys 与 items 永远同步。
|
|
9
|
+
*
|
|
10
|
+
* antdv-next 已废弃 onSelectAll / onSelectInvert / onSelectNone,
|
|
11
|
+
* 所有选中变化统一通过 onChange 回调,因此 mergedRowSelection 只拦截 onChange,
|
|
12
|
+
* 不拦截 onSelect / onSelectAll。
|
|
13
|
+
*/
|
|
14
|
+
function useRowSelection(options) {
|
|
15
|
+
const selectedMap = reactive(/* @__PURE__ */ new Map());
|
|
16
|
+
const stopWatch = watch(() => options.rowSelection.value?.selectedRowKeys, (keys) => {
|
|
17
|
+
if (!keys) return;
|
|
18
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
19
|
+
const currentDataSource = options.dataSource.value;
|
|
20
|
+
for (const key of keys) {
|
|
21
|
+
const existing = selectedMap.get(key);
|
|
22
|
+
const matched = currentDataSource.find((record) => getKey(record, options.rowKey.value) === key);
|
|
23
|
+
newMap.set(key, matched ?? existing);
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
selectedMap.clear();
|
|
26
|
+
for (const [key, item] of newMap) selectedMap.set(key, item);
|
|
27
|
+
}, { immediate: true });
|
|
28
|
+
onScopeDispose(() => stopWatch());
|
|
29
|
+
const selectedRowKeys = computed(() => Array.from(selectedMap.keys()));
|
|
30
|
+
const selectedItems = computed(() => Array.from(selectedMap.values()).filter((item) => item != null));
|
|
31
|
+
function emitChange(type) {
|
|
32
|
+
options.rowSelection.value?.onChange?.(selectedRowKeys.value, selectedItems.value, { type });
|
|
33
|
+
}
|
|
34
|
+
function select(record, selected) {
|
|
35
|
+
const key = getKey(record, options.rowKey.value);
|
|
36
|
+
const selectionType = options.rowSelection.value?.type ?? "checkbox";
|
|
37
|
+
if (selected) if (selectionType === "radio") {
|
|
38
|
+
selectedMap.clear();
|
|
39
|
+
selectedMap.set(key, record);
|
|
40
|
+
} else selectedMap.set(key, record);
|
|
41
|
+
else selectedMap.delete(key);
|
|
42
|
+
emitChange(selected ? selectionType === "radio" ? "single" : "multiple" : "none");
|
|
43
|
+
}
|
|
44
|
+
function selectAll(records, selected) {
|
|
45
|
+
if (selected) for (const record of records) selectedMap.set(getKey(record, options.rowKey.value), record);
|
|
46
|
+
else for (const record of records) selectedMap.delete(getKey(record, options.rowKey.value));
|
|
47
|
+
emitChange(selected ? "all" : "none");
|
|
48
|
+
}
|
|
49
|
+
function remove(keys) {
|
|
50
|
+
for (const key of keys) selectedMap.delete(key);
|
|
51
|
+
emitChange("none");
|
|
52
|
+
}
|
|
53
|
+
function clear() {
|
|
54
|
+
selectedMap.clear();
|
|
55
|
+
emitChange("none");
|
|
56
|
+
}
|
|
57
|
+
/** 从当前 dataSource 补全 Map 中 value 为空的条目(分页切换后调用) */
|
|
58
|
+
function sync() {
|
|
59
|
+
const currentDataSource = options.dataSource.value;
|
|
60
|
+
const rowKeyField = options.rowKey.value;
|
|
61
|
+
for (const [key, item] of selectedMap) if (item == null) {
|
|
62
|
+
const matched = currentDataSource.find((record) => getKey(record, rowKeyField) === key);
|
|
63
|
+
if (matched) selectedMap.set(key, matched);
|
|
32
64
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return item;
|
|
46
|
-
});
|
|
47
|
-
else changeRows.map((item) => {
|
|
48
|
-
if (selectedKeys.value.includes(item?.[rowKey.value])) {
|
|
49
|
-
selectedKeys.value = selectedKeys.value.filter((el) => el !== item[rowKey.value]);
|
|
50
|
-
selectedItems.value = selectedItems.value.filter((el) => el[rowKey.value] !== item[rowKey.value]);
|
|
51
|
-
}
|
|
52
|
-
return item;
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
const removeRowKeys = (keys) => {
|
|
56
|
-
selectedKeys.value = selectedKeys.value.filter((el) => !keys.includes(el));
|
|
57
|
-
selectedItems.value = selectedItems.value.filter((el) => !keys.includes(el?.[rowKey.value || ""]));
|
|
58
|
-
changeRowKey();
|
|
59
|
-
};
|
|
60
|
-
const syncSelectedRows = (dataList) => {
|
|
61
|
-
if (rowKey.value) {
|
|
62
|
-
if (selectedKeys.value.length !== selectedItems.value.length) {
|
|
63
|
-
const itemsKeys = selectedItems.value.map((item) => item[rowKey.value]);
|
|
64
|
-
const notIncludes = selectedKeys.value.filter((item) => !itemsKeys.includes(item));
|
|
65
|
-
dataList.forEach((item) => {
|
|
66
|
-
if (notIncludes.includes(item[rowKey.value])) selectedItems.value.push(cloneDeep(item));
|
|
67
|
-
});
|
|
68
|
-
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 处理 antdv Table 的 onChange 回调。
|
|
68
|
+
* antd 传入的 rows 只包含当前页数据,需与已有 Map 合并以保留跨页选中项。
|
|
69
|
+
*/
|
|
70
|
+
function handleAntdChange(keys, rows, info) {
|
|
71
|
+
const rowKeyField = options.rowKey.value;
|
|
72
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
const fromRows = rows.find((record) => getKey(record, rowKeyField) === key);
|
|
75
|
+
const existing = selectedMap.get(key);
|
|
76
|
+
newMap.set(key, fromRows ?? existing);
|
|
69
77
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
changeRowKey();
|
|
75
|
-
};
|
|
78
|
+
selectedMap.clear();
|
|
79
|
+
for (const [key, item] of newMap) selectedMap.set(key, item);
|
|
80
|
+
options.rowSelection.value?.onChange?.(selectedRowKeys.value, selectedItems.value, info);
|
|
81
|
+
}
|
|
76
82
|
return {
|
|
77
|
-
|
|
83
|
+
selectedRowKeys,
|
|
78
84
|
selectedItems,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
mergedRowSelection: computed(() => {
|
|
86
|
+
const rowSelectionConfig = options.rowSelection.value;
|
|
87
|
+
if (!rowSelectionConfig) return void 0;
|
|
88
|
+
return {
|
|
89
|
+
...rowSelectionConfig,
|
|
90
|
+
selectedRowKeys: selectedRowKeys.value,
|
|
91
|
+
onChange: handleAntdChange
|
|
92
|
+
};
|
|
93
|
+
}),
|
|
94
|
+
select,
|
|
95
|
+
selectAll,
|
|
96
|
+
remove,
|
|
97
|
+
clear,
|
|
98
|
+
sync
|
|
85
99
|
};
|
|
86
100
|
}
|
|
87
|
-
|
|
88
101
|
//#endregion
|
|
89
|
-
export { useRowSelection };
|
|
102
|
+
export { useRowSelection };
|
package/dist/hooks/useTable.d.ts
CHANGED
|
@@ -1,90 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ProCoreActionType, ProCoreFormType, ProTableProps, ProTableRef, ProTableRowSelection, RequestConfig, RequestFunction } from "../types/TableTypings.js";
|
|
3
|
-
import { BaseTableProps } from "../props.js";
|
|
1
|
+
import { PageState, ProCoreActionType, ProCoreFormType, ProSearchMap, ProTablePaginationConfig, ProTableProps, ProTableRef, RequestFunction, RowSelectionActions } from "../interface.js";
|
|
4
2
|
import { ComputedRef, MaybeRef, Reactive, Ref } from "vue";
|
|
5
|
-
import {
|
|
3
|
+
import { FilterValue, SorterResult, TableCurrentDataSource } from "antdv-next/dist/table/interface";
|
|
6
4
|
|
|
7
5
|
//#region src/hooks/useTable.d.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
rowKey?: keyof T;
|
|
15
|
-
title?: (data: T[]) => any;
|
|
16
|
-
footer?: (data: T[]) => any;
|
|
17
|
-
postData?: (data: T[]) => any;
|
|
18
|
-
rowExpandable?: (record: T) => boolean;
|
|
19
|
-
transformCellText?: (opt: {
|
|
20
|
-
text: any;
|
|
21
|
-
column: ProColumnType<T, R>;
|
|
22
|
-
record: any;
|
|
23
|
-
index: number;
|
|
24
|
-
}) => any;
|
|
25
|
-
expandIcon?: (props: {
|
|
26
|
-
prefixCls: string;
|
|
27
|
-
expanded: boolean;
|
|
28
|
-
record: T;
|
|
29
|
-
expandable: boolean;
|
|
30
|
-
onExpand: (record: T, event: MouseEvent) => void;
|
|
31
|
-
}) => any;
|
|
32
|
-
customRow?: (data: T, index?: number, column?: ProColumnType<T, R>) => any;
|
|
33
|
-
customHeaderRow?: (data: T, index?: number, column?: ProColumnType<T, R>) => any;
|
|
34
|
-
expandedRowRender: (opt: {
|
|
35
|
-
record: T;
|
|
36
|
-
index: number;
|
|
37
|
-
indent: number;
|
|
38
|
-
expanded: boolean;
|
|
39
|
-
}) => any;
|
|
40
|
-
rowClassName?: string | ((record: T, index: number, indent: number) => string);
|
|
41
|
-
onReset?: (params?: Partial<R>) => void;
|
|
42
|
-
onReload?: (params?: Partial<R>) => void;
|
|
43
|
-
onSubmit?: (params?: Partial<R>) => void;
|
|
44
|
-
onExpand?: (expanded: boolean, record: T) => void;
|
|
45
|
-
onResizeColumn?: (w: number, col: ProColumnType<T, R>) => void;
|
|
46
|
-
onBeforeSearchSubmit?: RequestFunction<T, R>;
|
|
47
|
-
};
|
|
48
|
-
type BaseTableState<T extends object = RecordType, R extends object = RecordType> = Omit<ProTableProps<T, R>, 'request'>;
|
|
49
|
-
interface UseTableReturn<T extends object = RecordType, R extends object = RecordType> {
|
|
50
|
-
/** @name loading 状态,可以直接进行修改 */
|
|
6
|
+
interface UseTableOptions<T = any, R = any> {
|
|
7
|
+
state?: MaybeRef<Partial<ProTableProps<T, R>>> | Reactive<Partial<ProTableProps<T, R>>>;
|
|
8
|
+
request?: RequestFunction<T, R>;
|
|
9
|
+
}
|
|
10
|
+
interface UseTableReturn<T = any, R = any> {
|
|
11
|
+
/** loading 状态,可直接赋值 */
|
|
51
12
|
loading: Ref<boolean>;
|
|
52
|
-
/**
|
|
13
|
+
/** 只读表格数据 */
|
|
53
14
|
dataSource: ComputedRef<T[]>;
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
/**
|
|
15
|
+
/** 表格请求参数(含分页 + 表单搜索参数) */
|
|
16
|
+
requestSearch: ComputedRef<Partial<R> & Partial<PageState>>;
|
|
17
|
+
/** 表格行选择 keys */
|
|
18
|
+
selectedKeys: ComputedRef<(string | number)[]>;
|
|
19
|
+
/** 表格行选择 rows */
|
|
20
|
+
selectedItems: ComputedRef<T[]>;
|
|
21
|
+
/** 表格行选择操作 */
|
|
22
|
+
rowsSelection: RowSelectionActions<T>;
|
|
23
|
+
/** action 表格实例 */
|
|
24
|
+
actionRef: ComputedRef<ProCoreActionType<T, R>>;
|
|
25
|
+
/** form 查询表单实例 */
|
|
26
|
+
formRef: ComputedRef<ProCoreFormType<R>>;
|
|
27
|
+
/** 主动刷新 */
|
|
63
28
|
reload: ProCoreActionType<T, R>['reload'];
|
|
64
|
-
/**
|
|
29
|
+
/** 更新表格数据 */
|
|
65
30
|
setTableDataList: ProCoreActionType<T, R>['setTableDataList'];
|
|
66
|
-
/**
|
|
31
|
+
/** 更新表格行数据 */
|
|
67
32
|
operateTableDataRow: ProCoreActionType<T, R>['operateTableDataRow'];
|
|
68
|
-
/**
|
|
69
|
-
setPageInfo:
|
|
70
|
-
/**
|
|
33
|
+
/** 设置翻页、排序、筛选并刷新 */
|
|
34
|
+
setPageInfo: (pagination: ProTablePaginationConfig, filters?: Record<string, FilterValue | null>, sorter?: SorterResult | SorterResult[], extra?: TableCurrentDataSource) => void;
|
|
35
|
+
/** 设置翻页 */
|
|
71
36
|
setPagination: ProCoreActionType<T, R>['setPagination'];
|
|
72
|
-
/**
|
|
37
|
+
/** 刷新并清空表单,重置为第一页 */
|
|
73
38
|
reloadAndReset: ProCoreActionType<T, R>['reloadAndReset'];
|
|
74
|
-
/**
|
|
39
|
+
/** 改变 loading 状态 */
|
|
75
40
|
setLoading: ProCoreActionType<T, R>['setLoading'];
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
|
|
80
|
-
/** @name 表格参数,用于传递给ProTable组件使用,可以对其进行修改 */
|
|
81
|
-
tableState: Reactive<ProTableState<T, R>>;
|
|
82
|
-
/** @name 更新表格参数 SearchMap,key为SearchMap唯一字段,value是更新的参数,会merge */
|
|
83
|
-
updateSearchMap: (key: keyof R | keyof T, value: Partial<ProSearchMap<any>>) => void;
|
|
41
|
+
/** 表格参数,传递给 ProTable 组件 */
|
|
42
|
+
tableState: Reactive<Partial<ProTableProps<T, R>>>;
|
|
43
|
+
/** 更新 searchMap 中指定字段的配置 */
|
|
44
|
+
updateSearchMap: (key: keyof T | keyof R, value: Partial<ProSearchMap<any>>) => void;
|
|
84
45
|
}
|
|
85
|
-
declare function useTable<T
|
|
86
|
-
state?: MaybeRef<BaseTableState<T, R>> | Reactive<BaseTableState<T, R>> | ComputedRef<BaseTableState<T, R>>;
|
|
87
|
-
request?: RequestFunction<T, R>;
|
|
88
|
-
}): UseTableReturn<T, R>;
|
|
46
|
+
declare function useTable<T = any, R = any>(tableRef: Ref<ProTableRef<T, R> | undefined>, options?: UseTableOptions<T, R>): UseTableReturn<T, R>;
|
|
89
47
|
//#endregion
|
|
90
|
-
export {
|
|
48
|
+
export { UseTableOptions, UseTableReturn, useTable };
|