@gct-paas/v-ben 0.1.6-dev.2 → 0.1.6-dev.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/index.min.css +1 -1
- package/dist/loader.esm.min.js +2 -1
- package/es/components/index.mjs +1 -0
- package/es/components/v-ben-button/src/PopConfirmButton.vue_vue_type_script_lang.mjs +1 -1
- package/es/components/v-ben-table/index.d.ts +2 -0
- package/es/components/v-ben-table/index.mjs +1 -0
- package/es/components/v-ben-table/src/BasicTable.vue.d.ts +28 -22
- package/es/components/v-ben-table/src/BasicTable.vue.mjs +12 -21
- package/es/components/v-ben-table/src/BasicTable.vue_vue_type_script_lang.mjs +84 -14
- package/es/components/v-ben-table/src/BasicTable.vue_vue_type_style_index_0_lang.css +50 -0
- package/es/components/v-ben-table/src/components/TableAction.vue_vue_type_script_setup_true_lang.mjs +3 -9
- package/es/components/v-ben-table/src/components/TableAction.vue_vue_type_style_index_0_lang.css +1 -0
- package/es/components/v-ben-table/src/components/TableActionAuto.vue_vue_type_script_setup_true_lang.mjs +3 -9
- package/es/components/v-ben-table/src/components/TableActionAuto.vue_vue_type_style_index_0_lang.css +1 -0
- package/es/components/v-ben-table/src/const.d.ts +10 -0
- package/es/components/v-ben-table/src/const.mjs +14 -0
- package/es/components/v-ben-table/src/hooks/useColumns.d.ts +7 -0
- package/es/components/v-ben-table/src/hooks/useColumns.mjs +143 -0
- package/es/components/v-ben-table/src/hooks/usePagination.d.ts +10 -0
- package/es/components/v-ben-table/src/hooks/usePagination.mjs +63 -0
- package/es/components/v-ben-table/src/hooks/useTable.d.ts +6 -0
- package/es/components/v-ben-table/src/hooks/useTable.mjs +21 -0
- package/es/components/v-ben-table/src/hooks/useTableExpand.d.ts +14 -0
- package/es/components/v-ben-table/src/hooks/useTableExpand.mjs +54 -0
- package/es/components/v-ben-table/src/hooks/useTableScroll.d.ts +17 -0
- package/es/components/v-ben-table/src/hooks/useTableScroll.mjs +126 -0
- package/es/components/v-ben-table/src/props.d.ts +2 -0
- package/es/components/v-ben-table/src/props.mjs +39 -1
- package/es/components/v-ben-table/src/types/pagination.d.ts +1 -1
- package/es/components/v-ben-table/src/utils/dom-utils.d.ts +13 -0
- package/es/components/v-ben-table/src/utils/dom-utils.mjs +36 -0
- package/es/hooks/useDesign.mjs +10 -0
- package/es/index.mjs +2 -1
- package/package.json +7 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BasicColumn, BasicTableProps } from '../types/table';
|
|
2
|
+
import { PaginationProps } from '../types/pagination';
|
|
3
|
+
import { ComputedRef } from 'vue';
|
|
4
|
+
export declare function useColumns(propsRef: ComputedRef<BasicTableProps>, getPaginationRef: ComputedRef<boolean | PaginationProps>): {
|
|
5
|
+
getColumnsRef: ComputedRef<BasicColumn[]>;
|
|
6
|
+
getViewColumns: ComputedRef<BasicColumn[]>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { isBoolean, isFunction } from "../../../../utils/is.mjs";
|
|
2
|
+
import { ACTION_COLUMN_FLAG, INDEX_COLUMN_FLAG } from "../const.mjs";
|
|
3
|
+
import { computed, ref, unref, watch } from "vue";
|
|
4
|
+
import { cloneDeep } from "lodash-es";
|
|
5
|
+
import { permission, t } from "@gct-paas/core";
|
|
6
|
+
//#region src/components/v-ben-table/src/hooks/useColumns.ts
|
|
7
|
+
function handleItem(item, ellipsis) {
|
|
8
|
+
const { key, dataIndex, children } = item;
|
|
9
|
+
item.align = item.align || "left";
|
|
10
|
+
if (ellipsis) {
|
|
11
|
+
if (!key && dataIndex !== void 0) item.key = Array.isArray(dataIndex) ? dataIndex.join(".") : String(dataIndex);
|
|
12
|
+
if (!isBoolean(item.ellipsis)) Object.assign(item, { ellipsis: { showTitle: false } });
|
|
13
|
+
}
|
|
14
|
+
if (children && children.length) handleChildren(children, !!ellipsis);
|
|
15
|
+
const originalCustomCell = item.customCell;
|
|
16
|
+
/** 只有内容超出的时候才出 title */
|
|
17
|
+
item.customCell = (record, rowIndex) => {
|
|
18
|
+
return {
|
|
19
|
+
...originalCustomCell && originalCustomCell(record, rowIndex),
|
|
20
|
+
onMouseenter(event) {
|
|
21
|
+
if (!item.ellipsis) return;
|
|
22
|
+
const el = event.target;
|
|
23
|
+
if (el.scrollWidth > el.clientWidth) el.setAttribute("title", el.textContent ?? "");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function handleChildren(children, ellipsis) {
|
|
29
|
+
if (!children) return;
|
|
30
|
+
children.forEach((item) => {
|
|
31
|
+
const { children: childCols } = item;
|
|
32
|
+
handleItem(item, ellipsis);
|
|
33
|
+
handleChildren(childCols, ellipsis);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function handleIndexColumn(propsRef, getPaginationRef, columns) {
|
|
37
|
+
const { showIndexColumn, indexColumnProps, isTreeTable } = unref(propsRef);
|
|
38
|
+
let pushIndexColumns = false;
|
|
39
|
+
if (unref(isTreeTable)) return;
|
|
40
|
+
columns.forEach(() => {
|
|
41
|
+
const indIndex = columns.findIndex((column) => column.flag === INDEX_COLUMN_FLAG);
|
|
42
|
+
if (showIndexColumn) pushIndexColumns = indIndex === -1;
|
|
43
|
+
else if (!showIndexColumn && indIndex !== -1) columns.splice(indIndex, 1);
|
|
44
|
+
});
|
|
45
|
+
if (!pushIndexColumns) return;
|
|
46
|
+
const isFixedLeft = columns.some((item) => item.fixed === "left");
|
|
47
|
+
columns.unshift({
|
|
48
|
+
flag: INDEX_COLUMN_FLAG,
|
|
49
|
+
width: 70,
|
|
50
|
+
title: t("sys.component.table.index"),
|
|
51
|
+
align: "center",
|
|
52
|
+
customRender: ({ index }) => {
|
|
53
|
+
const getPagination = unref(getPaginationRef);
|
|
54
|
+
if (isBoolean(getPagination)) return `${index + 1}`;
|
|
55
|
+
const { current = 1, pageSize = 20 } = getPagination;
|
|
56
|
+
return ((current < 1 ? 1 : current) - 1) * pageSize + index + 1;
|
|
57
|
+
},
|
|
58
|
+
...isFixedLeft ? { fixed: "left" } : {},
|
|
59
|
+
...indexColumnProps
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function handleActionColumn(propsRef, columns) {
|
|
63
|
+
const { actionColumn } = unref(propsRef);
|
|
64
|
+
if (!actionColumn) return;
|
|
65
|
+
const hasIndex = columns.findIndex((column) => column.flag === ACTION_COLUMN_FLAG);
|
|
66
|
+
if (hasIndex === -1) columns.push({
|
|
67
|
+
...columns[hasIndex],
|
|
68
|
+
fixed: "right",
|
|
69
|
+
...actionColumn,
|
|
70
|
+
flag: ACTION_COLUMN_FLAG
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function sortFixedColumn(columns) {
|
|
74
|
+
const fixedLeftColumns = [];
|
|
75
|
+
const fixedRightColumns = [];
|
|
76
|
+
const defColumns = [];
|
|
77
|
+
for (const column of columns) {
|
|
78
|
+
if (column.fixed === "left") {
|
|
79
|
+
fixedLeftColumns.push(column);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (column.fixed === "right") {
|
|
83
|
+
fixedRightColumns.push(column);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
defColumns.push(column);
|
|
87
|
+
}
|
|
88
|
+
return [
|
|
89
|
+
...fixedLeftColumns,
|
|
90
|
+
...defColumns,
|
|
91
|
+
...fixedRightColumns
|
|
92
|
+
].filter((item) => !item.defaultHidden);
|
|
93
|
+
}
|
|
94
|
+
function hasColumnAuth(auth) {
|
|
95
|
+
if (!auth) return true;
|
|
96
|
+
if (Array.isArray(auth)) return auth.some((key) => permission.has(String(key)));
|
|
97
|
+
return permission.has(String(auth));
|
|
98
|
+
}
|
|
99
|
+
function isIfShow(column) {
|
|
100
|
+
const ifShow = column.ifShow;
|
|
101
|
+
if (isBoolean(ifShow)) return ifShow;
|
|
102
|
+
if (isFunction(ifShow)) return ifShow(column);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
function useColumns(propsRef, getPaginationRef) {
|
|
106
|
+
const columnsRef = ref(unref(propsRef).columns);
|
|
107
|
+
const getColumnsRef = computed(() => {
|
|
108
|
+
const columns = cloneDeep(unref(columnsRef));
|
|
109
|
+
handleIndexColumn(propsRef, getPaginationRef, columns);
|
|
110
|
+
handleActionColumn(propsRef, columns);
|
|
111
|
+
if (!columns) return [];
|
|
112
|
+
const { ellipsis } = unref(propsRef);
|
|
113
|
+
columns.forEach((item) => {
|
|
114
|
+
const { customRender, slots } = item;
|
|
115
|
+
handleItem(item, Reflect.has(item, "ellipsis") ? !!item.ellipsis : !!ellipsis && !customRender && !slots);
|
|
116
|
+
});
|
|
117
|
+
return columns;
|
|
118
|
+
});
|
|
119
|
+
const getViewColumns = computed(() => {
|
|
120
|
+
const viewColumns = sortFixedColumn(unref(getColumnsRef));
|
|
121
|
+
const mapFn = (column) => {
|
|
122
|
+
const { slots } = column;
|
|
123
|
+
if (!slots || !slots?.title) {
|
|
124
|
+
column.customTitle = column.title;
|
|
125
|
+
Reflect.deleteProperty(column, "title");
|
|
126
|
+
}
|
|
127
|
+
return column;
|
|
128
|
+
};
|
|
129
|
+
return cloneDeep(viewColumns).filter((column) => hasColumnAuth(column.auth) && isIfShow(column)).map((column) => {
|
|
130
|
+
if (column.children?.length) column.children = column.children.map(mapFn);
|
|
131
|
+
return mapFn(column);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
watch(() => unref(propsRef).columns, (columns) => {
|
|
135
|
+
columnsRef.value = columns;
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
getColumnsRef,
|
|
139
|
+
getViewColumns
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
export { useColumns };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PaginationProps } from '../types/pagination';
|
|
2
|
+
import { BasicTableProps } from '../types/table';
|
|
3
|
+
import { ComputedRef } from 'vue';
|
|
4
|
+
export declare function usePagination(refProps: ComputedRef<BasicTableProps>): {
|
|
5
|
+
getPagination: () => boolean | PaginationProps;
|
|
6
|
+
getPaginationInfo: ComputedRef<boolean | PaginationProps>;
|
|
7
|
+
setShowPagination: (flag: boolean) => Promise<void>;
|
|
8
|
+
getShowPagination: () => boolean;
|
|
9
|
+
setPagination: (info: Partial<PaginationProps>) => void;
|
|
10
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isBoolean } from "../../../../utils/is.mjs";
|
|
2
|
+
import { PAGE_SIZE_OPTIONS } from "../const.mjs";
|
|
3
|
+
import { computed, h, ref, unref, watch } from "vue";
|
|
4
|
+
import { t } from "@gct-paas/core";
|
|
5
|
+
import { LeftOutlined, RightOutlined } from "@ant-design/icons-vue";
|
|
6
|
+
//#region src/components/v-ben-table/src/hooks/usePagination.ts
|
|
7
|
+
function itemRender({ page, type, originalElement }) {
|
|
8
|
+
if (type === "prev") return page === 0 ? null : h(LeftOutlined);
|
|
9
|
+
if (type === "next") return page === 1 ? null : h(RightOutlined);
|
|
10
|
+
return originalElement;
|
|
11
|
+
}
|
|
12
|
+
function usePagination(refProps) {
|
|
13
|
+
const configRef = ref({});
|
|
14
|
+
const show = ref(true);
|
|
15
|
+
watch(() => unref(refProps).pagination, (pagination) => {
|
|
16
|
+
if (!isBoolean(pagination) && pagination) configRef.value = {
|
|
17
|
+
...unref(configRef),
|
|
18
|
+
...pagination
|
|
19
|
+
};
|
|
20
|
+
}, { deep: true });
|
|
21
|
+
const getPaginationInfo = computed(() => {
|
|
22
|
+
const { pagination } = unref(refProps);
|
|
23
|
+
if (!unref(show) || isBoolean(pagination) && !pagination) return false;
|
|
24
|
+
return {
|
|
25
|
+
current: 1,
|
|
26
|
+
pageSize: 20,
|
|
27
|
+
size: "small",
|
|
28
|
+
defaultPageSize: 20,
|
|
29
|
+
showTotal: (total) => t("sys.component.table.total", { total }),
|
|
30
|
+
showSizeChanger: true,
|
|
31
|
+
pageSizeOptions: PAGE_SIZE_OPTIONS,
|
|
32
|
+
itemRender,
|
|
33
|
+
showQuickJumper: true,
|
|
34
|
+
...isBoolean(pagination) ? {} : pagination ?? {},
|
|
35
|
+
...unref(configRef)
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
function setPagination(info) {
|
|
39
|
+
const paginationInfo = unref(getPaginationInfo);
|
|
40
|
+
configRef.value = {
|
|
41
|
+
...!isBoolean(paginationInfo) ? paginationInfo : {},
|
|
42
|
+
...info
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function getPagination() {
|
|
46
|
+
return unref(getPaginationInfo);
|
|
47
|
+
}
|
|
48
|
+
function getShowPagination() {
|
|
49
|
+
return unref(show);
|
|
50
|
+
}
|
|
51
|
+
async function setShowPagination(flag) {
|
|
52
|
+
show.value = flag;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
getPagination,
|
|
56
|
+
getPaginationInfo,
|
|
57
|
+
setShowPagination,
|
|
58
|
+
getShowPagination,
|
|
59
|
+
setPagination
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { usePagination };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { onUnmounted, ref, unref } from "vue";
|
|
2
|
+
//#region src/components/v-ben-table/src/hooks/useTable.ts
|
|
3
|
+
function useTable() {
|
|
4
|
+
const tableRef = ref(null);
|
|
5
|
+
function register(instance, _formInstance) {
|
|
6
|
+
onUnmounted(() => {
|
|
7
|
+
tableRef.value = null;
|
|
8
|
+
});
|
|
9
|
+
tableRef.value = instance;
|
|
10
|
+
}
|
|
11
|
+
function getTableInstance() {
|
|
12
|
+
const table = unref(tableRef);
|
|
13
|
+
if (!table) console.error("The table instance has not been obtained yet, please make sure the table is presented when performing the table operation!");
|
|
14
|
+
return table;
|
|
15
|
+
}
|
|
16
|
+
return [register, { expandAll: () => {
|
|
17
|
+
getTableInstance().expandAll();
|
|
18
|
+
} }];
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { useTable };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
import { BasicTableProps } from '../types/table';
|
|
3
|
+
export declare function useTableExpand(propsRef: ComputedRef<BasicTableProps>, tableData: ComputedRef<Recordable[]>, emit: (event: 'expanded-rows-change', keys: string[]) => void): {
|
|
4
|
+
getExpandOption: ComputedRef<{
|
|
5
|
+
expandedRowKeys?: undefined;
|
|
6
|
+
onExpandedRowsChange?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
expandedRowKeys: string[];
|
|
9
|
+
onExpandedRowsChange: (keys: string[]) => void;
|
|
10
|
+
}>;
|
|
11
|
+
expandAll: () => void;
|
|
12
|
+
expandRows: (keys: string[]) => void;
|
|
13
|
+
collapseAll: () => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { computed, ref, toRaw, unref } from "vue";
|
|
2
|
+
//#region src/components/v-ben-table/src/hooks/useTableExpand.ts
|
|
3
|
+
function useTableExpand(propsRef, tableData, emit) {
|
|
4
|
+
const { expandedRowKeys: propsExpandedRowKeys = [] } = unref(propsRef);
|
|
5
|
+
const expandedRowKeys = ref([...propsExpandedRowKeys]);
|
|
6
|
+
const getAutoCreateKey = computed(() => {
|
|
7
|
+
return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey;
|
|
8
|
+
});
|
|
9
|
+
const getRowKey = computed(() => {
|
|
10
|
+
const { rowKey } = unref(propsRef);
|
|
11
|
+
return unref(getAutoCreateKey) ? "key" : rowKey;
|
|
12
|
+
});
|
|
13
|
+
const getExpandOption = computed(() => {
|
|
14
|
+
const { isTreeTable } = unref(propsRef);
|
|
15
|
+
if (!isTreeTable) return {};
|
|
16
|
+
return {
|
|
17
|
+
expandedRowKeys: unref(expandedRowKeys),
|
|
18
|
+
onExpandedRowsChange: (keys) => {
|
|
19
|
+
expandedRowKeys.value = keys;
|
|
20
|
+
emit("expanded-rows-change", keys);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
function expandAll() {
|
|
25
|
+
expandedRowKeys.value = getAllKeys();
|
|
26
|
+
}
|
|
27
|
+
function expandRows(keys) {
|
|
28
|
+
const { isTreeTable } = unref(propsRef);
|
|
29
|
+
if (!isTreeTable) return;
|
|
30
|
+
expandedRowKeys.value = [...expandedRowKeys.value, ...keys];
|
|
31
|
+
}
|
|
32
|
+
function getAllKeys(data) {
|
|
33
|
+
const keys = [];
|
|
34
|
+
const { childrenColumnName } = unref(propsRef);
|
|
35
|
+
const childrenField = childrenColumnName || "children";
|
|
36
|
+
toRaw(data || unref(tableData)).forEach((item) => {
|
|
37
|
+
keys.push(String(item[unref(getRowKey)]));
|
|
38
|
+
const children = item[childrenField];
|
|
39
|
+
if (children?.length) keys.push(...getAllKeys(children));
|
|
40
|
+
});
|
|
41
|
+
return keys;
|
|
42
|
+
}
|
|
43
|
+
function collapseAll() {
|
|
44
|
+
expandedRowKeys.value = [];
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
getExpandOption,
|
|
48
|
+
expandAll,
|
|
49
|
+
expandRows,
|
|
50
|
+
collapseAll
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { useTableExpand };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PaginationProps } from '../types/pagination';
|
|
2
|
+
import { BasicColumn, BasicTableProps, TableRowSelection } from '../types/table';
|
|
3
|
+
import { ComputedRef, Ref } from 'vue';
|
|
4
|
+
type TableComponentRef = {
|
|
5
|
+
$el: HTMLElement;
|
|
6
|
+
} | null;
|
|
7
|
+
type FormComponentRef = {
|
|
8
|
+
$el: HTMLElement;
|
|
9
|
+
} | null;
|
|
10
|
+
export declare function useTableScroll(propsRef: ComputedRef<BasicTableProps>, tableElRef: Ref<TableComponentRef>, columnsRef: ComputedRef<BasicColumn[]>, rowSelectionRef: ComputedRef<TableRowSelection | null>, getPaginationRef: ComputedRef<PaginationProps | boolean>, getDataSourceRef: ComputedRef<Recordable[]>, wrapRef: Ref<HTMLElement | null>, formRef: Ref<FormComponentRef>): {
|
|
11
|
+
getScrollRef: ComputedRef<{
|
|
12
|
+
x?: number | string | true;
|
|
13
|
+
y?: number | string;
|
|
14
|
+
} | undefined>;
|
|
15
|
+
redoHeight: () => void;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { isBoolean } from "../../../../utils/is.mjs";
|
|
2
|
+
import { getViewportOffset } from "../utils/dom-utils.mjs";
|
|
3
|
+
import { computed, nextTick, onActivated, onMounted, ref, unref, watch } from "vue";
|
|
4
|
+
import { useDebounceFn, useEventListener } from "@vueuse/core";
|
|
5
|
+
//#region src/components/v-ben-table/src/hooks/useTableScroll.ts
|
|
6
|
+
function useTableScroll(propsRef, tableElRef, columnsRef, rowSelectionRef, getPaginationRef, getDataSourceRef, wrapRef, formRef) {
|
|
7
|
+
const tableHeightRef = ref(215);
|
|
8
|
+
const debounceRedoHeight = useDebounceFn(redoHeight, 100);
|
|
9
|
+
const getCanResize = computed(() => {
|
|
10
|
+
const { canResize, scroll } = unref(propsRef);
|
|
11
|
+
return canResize && !(scroll || {}).y;
|
|
12
|
+
});
|
|
13
|
+
watch(() => [unref(getCanResize), unref(getDataSourceRef)?.length], () => {
|
|
14
|
+
debounceRedoHeight();
|
|
15
|
+
}, { flush: "post" });
|
|
16
|
+
function redoHeight() {
|
|
17
|
+
nextTick(() => {
|
|
18
|
+
calcTableHeight();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function setHeight(height) {
|
|
22
|
+
tableHeightRef.value = height;
|
|
23
|
+
}
|
|
24
|
+
let paginationEl = null;
|
|
25
|
+
let footerEl = null;
|
|
26
|
+
let bodyEl = null;
|
|
27
|
+
async function calcTableHeight() {
|
|
28
|
+
const { resizeHeightOffset, maxHeight, isCanResizeParent, useSearchForm } = unref(propsRef);
|
|
29
|
+
const pagination = unref(getPaginationRef);
|
|
30
|
+
const tableData = unref(getDataSourceRef);
|
|
31
|
+
const table = unref(tableElRef);
|
|
32
|
+
if (!table) return;
|
|
33
|
+
const tableEl = table.$el;
|
|
34
|
+
if (!tableEl) return;
|
|
35
|
+
if (!bodyEl) {
|
|
36
|
+
bodyEl = tableEl.querySelector(".ant-table-body");
|
|
37
|
+
if (!bodyEl) return;
|
|
38
|
+
}
|
|
39
|
+
const hasScrollBarY = bodyEl.scrollHeight > bodyEl.clientHeight;
|
|
40
|
+
const hasScrollBarX = bodyEl.scrollWidth > bodyEl.clientWidth;
|
|
41
|
+
if (hasScrollBarY) {
|
|
42
|
+
if (tableEl.classList.contains("hide-scrollbar-y")) tableEl.classList.remove("hide-scrollbar-y");
|
|
43
|
+
} else if (!tableEl.classList.contains("hide-scrollbar-y")) tableEl.classList.add("hide-scrollbar-y");
|
|
44
|
+
if (hasScrollBarX) {
|
|
45
|
+
if (tableEl.classList.contains("hide-scrollbar-x")) tableEl.classList.remove("hide-scrollbar-x");
|
|
46
|
+
} else if (!tableEl.classList.contains("hide-scrollbar-x")) tableEl.classList.add("hide-scrollbar-x");
|
|
47
|
+
bodyEl.style.height = "unset";
|
|
48
|
+
if (!unref(getCanResize) || !unref(tableData) || tableData.length === 0) return;
|
|
49
|
+
await nextTick();
|
|
50
|
+
const headEl = tableEl.querySelector(".ant-table-thead ");
|
|
51
|
+
if (!headEl) return;
|
|
52
|
+
let paddingHeight = 32;
|
|
53
|
+
let paginationHeight = 12;
|
|
54
|
+
if (!isBoolean(pagination)) {
|
|
55
|
+
paginationEl = tableEl.querySelector(".ant-pagination");
|
|
56
|
+
if (paginationEl) {
|
|
57
|
+
const offsetHeight = paginationEl.offsetHeight;
|
|
58
|
+
paginationHeight += offsetHeight || 0;
|
|
59
|
+
} else paginationHeight += 24;
|
|
60
|
+
} else paginationHeight = -8;
|
|
61
|
+
let footerHeight = 0;
|
|
62
|
+
if (!isBoolean(pagination)) if (!footerEl) footerEl = tableEl.querySelector(".ant-table-footer");
|
|
63
|
+
else {
|
|
64
|
+
const offsetHeight = footerEl.offsetHeight;
|
|
65
|
+
footerHeight += offsetHeight || 0;
|
|
66
|
+
}
|
|
67
|
+
let headerHeight = 0;
|
|
68
|
+
if (headEl) headerHeight = headEl.offsetHeight;
|
|
69
|
+
let bottomIncludeBody = 0;
|
|
70
|
+
if (unref(wrapRef) && isCanResizeParent) {
|
|
71
|
+
const tablePadding = 12;
|
|
72
|
+
const formMargin = 16;
|
|
73
|
+
let paginationMargin = 10;
|
|
74
|
+
const wrapHeight = unref(wrapRef)?.offsetHeight ?? 0;
|
|
75
|
+
let formHeight = unref(formRef)?.$el.offsetHeight ?? 0;
|
|
76
|
+
if (formHeight) formHeight += formMargin;
|
|
77
|
+
if (isBoolean(pagination) && !pagination) paginationMargin = 0;
|
|
78
|
+
if (isBoolean(useSearchForm) && !useSearchForm) paddingHeight = 0;
|
|
79
|
+
const headerCellHeight = tableEl.querySelector(".ant-table-title")?.offsetHeight ?? 0;
|
|
80
|
+
bottomIncludeBody = wrapHeight - formHeight - headerCellHeight - tablePadding - paginationMargin;
|
|
81
|
+
} else bottomIncludeBody = getViewportOffset(headEl).bottomIncludeBody;
|
|
82
|
+
let height = bottomIncludeBody - (resizeHeightOffset || 0) - paddingHeight - paginationHeight - footerHeight - headerHeight;
|
|
83
|
+
height = (height > maxHeight ? maxHeight : height) ?? height;
|
|
84
|
+
setHeight(height);
|
|
85
|
+
if (pagination && !isBoolean(pagination)) {
|
|
86
|
+
const body = tableEl.querySelector(".ant-table-body");
|
|
87
|
+
if (body) body.style.height = `${height}px`;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
useEventListener(window, "resize", useDebounceFn(calcTableHeight, 280));
|
|
91
|
+
function mountCalcHeight() {
|
|
92
|
+
calcTableHeight();
|
|
93
|
+
nextTick(() => {
|
|
94
|
+
debounceRedoHeight();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
onMounted(mountCalcHeight);
|
|
98
|
+
onActivated(mountCalcHeight);
|
|
99
|
+
const getScrollX = computed(() => {
|
|
100
|
+
let width = 0;
|
|
101
|
+
if (unref(rowSelectionRef)) width += 60;
|
|
102
|
+
const NORMAL_WIDTH = 150;
|
|
103
|
+
const columns = unref(columnsRef).filter((item) => !item.defaultHidden);
|
|
104
|
+
columns.forEach((item) => {
|
|
105
|
+
width += Number.parseFloat(String(item.width)) || 0;
|
|
106
|
+
});
|
|
107
|
+
const len = columns.filter((item) => !Reflect.has(item, "width")).length;
|
|
108
|
+
if (len !== 0) width += len * NORMAL_WIDTH;
|
|
109
|
+
return (unref(tableElRef)?.$el?.offsetWidth ?? 0) > width ? void 0 : width;
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
getScrollRef: computed(() => {
|
|
113
|
+
const tableHeight = unref(tableHeightRef);
|
|
114
|
+
const { canResize, scroll } = unref(propsRef);
|
|
115
|
+
return {
|
|
116
|
+
x: unref(getScrollX),
|
|
117
|
+
y: canResize ? tableHeight : null,
|
|
118
|
+
scrollToFirstRowOnChange: false,
|
|
119
|
+
...scroll
|
|
120
|
+
};
|
|
121
|
+
}),
|
|
122
|
+
redoHeight
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
export { useTableScroll };
|
|
@@ -184,3 +184,5 @@ export declare const basicProps: {
|
|
|
184
184
|
default: boolean;
|
|
185
185
|
};
|
|
186
186
|
};
|
|
187
|
+
/** BasicTable 自有配置,不传给 ant-design-vue Table */
|
|
188
|
+
export declare const basicTableInternalPropKeys: readonly ["clickToRowSelect", "isTreeTable", "tableSetting", "inset", "showTableSetting", "autoCreateKey", "striped", "showSummary", "summaryFunc", "summaryData", "indentSize", "canColDrag", "api", "beforeFetch", "afterFetch", "handleSearchInfoFn", "immediate", "emptyDataIsShowTable", "searchInfo", "defSort", "useSearchForm", "showIndexColumn", "indexColumnProps", "actionColumn", "ellipsis", "isCanResizeParent", "canResize", "clearSelectOnPageChange", "resizeHeightOffset", "titleHelpMessage", "beforeEditSubmit", "rowDraggable", "supportSameLevel", "rowDragApi", "emptyFull"];
|
|
@@ -168,5 +168,43 @@ var basicProps = {
|
|
|
168
168
|
default: false
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
|
+
/** BasicTable 自有配置,不传给 ant-design-vue Table */
|
|
172
|
+
var basicTableInternalPropKeys = [
|
|
173
|
+
"clickToRowSelect",
|
|
174
|
+
"isTreeTable",
|
|
175
|
+
"tableSetting",
|
|
176
|
+
"inset",
|
|
177
|
+
"showTableSetting",
|
|
178
|
+
"autoCreateKey",
|
|
179
|
+
"striped",
|
|
180
|
+
"showSummary",
|
|
181
|
+
"summaryFunc",
|
|
182
|
+
"summaryData",
|
|
183
|
+
"indentSize",
|
|
184
|
+
"canColDrag",
|
|
185
|
+
"api",
|
|
186
|
+
"beforeFetch",
|
|
187
|
+
"afterFetch",
|
|
188
|
+
"handleSearchInfoFn",
|
|
189
|
+
"immediate",
|
|
190
|
+
"emptyDataIsShowTable",
|
|
191
|
+
"searchInfo",
|
|
192
|
+
"defSort",
|
|
193
|
+
"useSearchForm",
|
|
194
|
+
"showIndexColumn",
|
|
195
|
+
"indexColumnProps",
|
|
196
|
+
"actionColumn",
|
|
197
|
+
"ellipsis",
|
|
198
|
+
"isCanResizeParent",
|
|
199
|
+
"canResize",
|
|
200
|
+
"clearSelectOnPageChange",
|
|
201
|
+
"resizeHeightOffset",
|
|
202
|
+
"titleHelpMessage",
|
|
203
|
+
"beforeEditSubmit",
|
|
204
|
+
"rowDraggable",
|
|
205
|
+
"supportSameLevel",
|
|
206
|
+
"rowDragApi",
|
|
207
|
+
"emptyFull"
|
|
208
|
+
];
|
|
171
209
|
//#endregion
|
|
172
|
-
export { basicProps };
|
|
210
|
+
export { basicProps, basicTableInternalPropKeys };
|
|
@@ -66,7 +66,7 @@ export interface PaginationProps {
|
|
|
66
66
|
* to display the total number and range
|
|
67
67
|
* @type Function
|
|
68
68
|
*/
|
|
69
|
-
showTotal?: (total: number, range
|
|
69
|
+
showTotal?: (total: number, range?: [number, number]) => string;
|
|
70
70
|
/**
|
|
71
71
|
* specify the size of Pagination, can be set to small
|
|
72
72
|
* @default ''
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface IViewportOffsetResult {
|
|
2
|
+
left: number;
|
|
3
|
+
top: number;
|
|
4
|
+
right: number;
|
|
5
|
+
bottom: number;
|
|
6
|
+
rightIncludeBody: number;
|
|
7
|
+
bottomIncludeBody: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function getBoundingClientRect(element: Element): DOMRect | number;
|
|
10
|
+
/**
|
|
11
|
+
* 获取元素相对视口的偏移,用于计算表格可用高度
|
|
12
|
+
*/
|
|
13
|
+
export declare function getViewportOffset(element: Element): IViewportOffsetResult;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/components/v-ben-table/src/utils/dom-utils.ts
|
|
2
|
+
function getBoundingClientRect(element) {
|
|
3
|
+
if (!element || !element.getBoundingClientRect) return 0;
|
|
4
|
+
return element.getBoundingClientRect();
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 获取元素相对视口的偏移,用于计算表格可用高度
|
|
8
|
+
*/
|
|
9
|
+
function getViewportOffset(element) {
|
|
10
|
+
const doc = document.documentElement;
|
|
11
|
+
const docScrollLeft = doc.scrollLeft;
|
|
12
|
+
const docScrollTop = doc.scrollTop;
|
|
13
|
+
const docClientLeft = doc.clientLeft;
|
|
14
|
+
const docClientTop = doc.clientTop;
|
|
15
|
+
const pageXOffset = window.pageXOffset;
|
|
16
|
+
const pageYOffset = window.pageYOffset;
|
|
17
|
+
const { left: retLeft, top: rectTop, width: rectWidth, height: rectHeight } = getBoundingClientRect(element);
|
|
18
|
+
const scrollLeft = (pageXOffset || docScrollLeft) - (docClientLeft || 0);
|
|
19
|
+
const scrollTop = (pageYOffset || docScrollTop) - (docClientTop || 0);
|
|
20
|
+
const offsetLeft = retLeft + pageXOffset;
|
|
21
|
+
const offsetTop = rectTop + pageYOffset;
|
|
22
|
+
const left = offsetLeft - scrollLeft;
|
|
23
|
+
const top = offsetTop - scrollTop;
|
|
24
|
+
const clientWidth = window.document.documentElement.clientWidth;
|
|
25
|
+
const clientHeight = window.document.documentElement.clientHeight;
|
|
26
|
+
return {
|
|
27
|
+
left,
|
|
28
|
+
top,
|
|
29
|
+
right: clientWidth - rectWidth - left,
|
|
30
|
+
bottom: clientHeight - rectHeight - top,
|
|
31
|
+
rightIncludeBody: clientWidth - left,
|
|
32
|
+
bottomIncludeBody: clientHeight - top
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { getViewportOffset };
|
package/es/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@ import { is, isArray, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyStr,
|
|
|
2
2
|
import BasicTable_default from "./components/v-ben-table/src/BasicTable.vue.mjs";
|
|
3
3
|
import TableAction_default from "./components/v-ben-table/src/components/TableAction.vue.mjs";
|
|
4
4
|
import TableActionAuto_default from "./components/v-ben-table/src/components/TableActionAuto.vue.mjs";
|
|
5
|
+
import { useTable } from "./components/v-ben-table/src/hooks/useTable.mjs";
|
|
5
6
|
import custom_button_default from "./components/v-ben-button/src/custom-button.vue.mjs";
|
|
6
7
|
import { Button, PopConfirmButton } from "./components/v-ben-button/index.mjs";
|
|
7
8
|
import { Dropdown } from "./components/v-ben-dropdown/index.mjs";
|
|
@@ -9,4 +10,4 @@ import "./components/index.mjs";
|
|
|
9
10
|
//#region src/index.ts
|
|
10
11
|
function run() {}
|
|
11
12
|
//#endregion
|
|
12
|
-
export { BasicTable_default as BasicTable, Button, custom_button_default as CustomButton, Dropdown, PopConfirmButton, TableAction_default as TableAction, TableActionAuto_default as TableActionAuto, is, isArray, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyStr, isFunction, isMap, isNull, isNullAndUnDef, isNullOrUnDef, isNumber, isObject, isPromise, isRegExp, isString, isUnDef, isUrl, isWindow, run };
|
|
13
|
+
export { BasicTable_default as BasicTable, Button, custom_button_default as CustomButton, Dropdown, PopConfirmButton, TableAction_default as TableAction, TableActionAuto_default as TableActionAuto, is, isArray, isBoolean, isDate, isDef, isElement, isEmpty, isEmptyStr, isFunction, isMap, isNull, isNullAndUnDef, isNullOrUnDef, isNumber, isObject, isPromise, isRegExp, isString, isUnDef, isUrl, isWindow, run, useTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gct-paas/v-ben",
|
|
3
|
-
"version": "0.1.6-dev.
|
|
3
|
+
"version": "0.1.6-dev.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "paas 平台历史 v-ben 内容",
|
|
6
6
|
"loader": "dist/loader.esm.min.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "gct",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@ant-design/icons-vue": "^6.1.0",
|
|
35
|
-
"@gct-paas/api": "^0.1.
|
|
35
|
+
"@gct-paas/api": "^0.1.6-dev.14",
|
|
36
36
|
"@gct-paas/platform-icons": "^0.0.2",
|
|
37
37
|
"@icon-park/vue-next": "^1.4.2",
|
|
38
38
|
"@vueuse/core": "^14.1.0",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"sortablejs": "^1.15.7",
|
|
42
42
|
"vue": "^3.5.30",
|
|
43
43
|
"vue-types": "^6.0.0",
|
|
44
|
-
"@gct-paas/
|
|
45
|
-
"@gct-paas/
|
|
44
|
+
"@gct-paas/core": "0.1.6-dev.21",
|
|
45
|
+
"@gct-paas/scss": "0.1.6-dev.21"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@gct-paas/api": "^0.1.
|
|
48
|
+
"@gct-paas/api": "^0.1.6-dev.14",
|
|
49
49
|
"vue": ">=3",
|
|
50
|
-
"@gct-paas/
|
|
51
|
-
"@gct-paas/
|
|
50
|
+
"@gct-paas/scss": "0.1.6-dev.21",
|
|
51
|
+
"@gct-paas/core": "0.1.6-dev.21"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"dev": "cross-env NODE_ENV=development vite build --watch --config vite.dev.config.ts",
|