bl-common-vue3 3.8.116 → 3.8.117
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/package.json +1 -1
- package/src/components/CustomTable/index.vue +230 -16
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="table-warp">
|
|
2
|
+
<div ref="tableWarpRef" class="table-warp">
|
|
3
3
|
<div
|
|
4
|
+
ref="titleHeaderRef"
|
|
4
5
|
class="visitoeTitleHeader"
|
|
5
6
|
v-if="displayTitleCollapsed && filterList?.length"
|
|
6
7
|
:style="{ marginBottom: isTitleCollapsed ? '10px' : '0' }">
|
|
@@ -1592,6 +1593,10 @@ export default defineComponent({
|
|
|
1592
1593
|
type: Number,
|
|
1593
1594
|
default: 0,
|
|
1594
1595
|
},
|
|
1596
|
+
autoTableHeight: {
|
|
1597
|
+
type: Boolean,
|
|
1598
|
+
default: false,
|
|
1599
|
+
},
|
|
1595
1600
|
titleRowAlign: {
|
|
1596
1601
|
type: String,
|
|
1597
1602
|
default: "middle",
|
|
@@ -1875,12 +1880,165 @@ export default defineComponent({
|
|
|
1875
1880
|
const columnSlots = ref([]);
|
|
1876
1881
|
const buttonIconSlots = ref([]);
|
|
1877
1882
|
const isInDrawer = ref(false);
|
|
1883
|
+
const tableWarpRef = ref(null);
|
|
1884
|
+
const titleHeaderRef = ref(null);
|
|
1878
1885
|
const tableRef = ref(null);
|
|
1879
1886
|
const filterRef = ref(null);
|
|
1880
1887
|
const isTitleCollapsed = ref(props.displayTitleCollapsed);
|
|
1888
|
+
const autoTableHeightRaf = ref(0);
|
|
1889
|
+
const tableHeightTimer = ref(0);
|
|
1890
|
+
const autoTableHeightObserver = ref(null);
|
|
1891
|
+
const autoTableHeightBottomOffset = 11;
|
|
1892
|
+
const autoTableHeightMinBody = 80;
|
|
1881
1893
|
const toggleTitle = () => {
|
|
1882
1894
|
isTitleCollapsed.value = !isTitleCollapsed.value;
|
|
1895
|
+
scheduleTableHeightRecalc();
|
|
1896
|
+
};
|
|
1897
|
+
|
|
1898
|
+
const isVisibleFlowElement = (el) => {
|
|
1899
|
+
if (!el || el.nodeType !== 1) {
|
|
1900
|
+
return false;
|
|
1901
|
+
}
|
|
1902
|
+
const style = window.getComputedStyle(el);
|
|
1903
|
+
if (style.display === "none" || style.visibility === "hidden") {
|
|
1904
|
+
return false;
|
|
1905
|
+
}
|
|
1906
|
+
if (style.position === "absolute" || style.position === "fixed") {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
const rect = el.getBoundingClientRect();
|
|
1910
|
+
return rect.width > 0 && rect.height > 0;
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1913
|
+
const hasVisibleNextFlowSibling = (el) => {
|
|
1914
|
+
let nextSibling = el?.nextElementSibling;
|
|
1915
|
+
while (nextSibling) {
|
|
1916
|
+
if (isVisibleFlowElement(nextSibling)) {
|
|
1917
|
+
return true;
|
|
1918
|
+
}
|
|
1919
|
+
nextSibling = nextSibling.nextElementSibling;
|
|
1920
|
+
}
|
|
1921
|
+
return false;
|
|
1922
|
+
};
|
|
1923
|
+
|
|
1924
|
+
const hasUnsafeAutoTableHeightContainer = (el) => {
|
|
1925
|
+
return ["ant-drawer", "ant-modal", "ant-tabs-tabpane"].some((className) =>
|
|
1926
|
+
utils.hasParentWithClass(el, className)
|
|
1927
|
+
);
|
|
1928
|
+
};
|
|
1929
|
+
|
|
1930
|
+
const getAutoTableHeightBoundaryBottom = (el) => {
|
|
1931
|
+
const viewportHeight =
|
|
1932
|
+
window.innerHeight || document.documentElement?.clientHeight || 0;
|
|
1933
|
+
let parent = el?.parentElement;
|
|
1934
|
+
while (parent && parent !== document.body) {
|
|
1935
|
+
const style = window.getComputedStyle(parent);
|
|
1936
|
+
if (["auto", "scroll", "overlay"].includes(style.overflowY)) {
|
|
1937
|
+
const rect = parent.getBoundingClientRect();
|
|
1938
|
+
return Math.min(rect.bottom, viewportHeight);
|
|
1939
|
+
}
|
|
1940
|
+
parent = parent.parentElement;
|
|
1941
|
+
}
|
|
1942
|
+
return viewportHeight;
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
const clearAutoTableHeightObserver = () => {
|
|
1946
|
+
if (autoTableHeightObserver.value) {
|
|
1947
|
+
autoTableHeightObserver.value.disconnect();
|
|
1948
|
+
autoTableHeightObserver.value = null;
|
|
1949
|
+
}
|
|
1950
|
+
};
|
|
1951
|
+
|
|
1952
|
+
const isAutoTableHeightSafe = () => {
|
|
1953
|
+
if (!props.autoTableHeight || props.tableHeight) {
|
|
1954
|
+
return false;
|
|
1955
|
+
}
|
|
1956
|
+
const rootEl = tableWarpRef.value;
|
|
1957
|
+
if (!rootEl || !rootEl.parentElement) {
|
|
1958
|
+
return false;
|
|
1959
|
+
}
|
|
1960
|
+
if (hasUnsafeAutoTableHeightContainer(rootEl)) {
|
|
1961
|
+
return false;
|
|
1962
|
+
}
|
|
1963
|
+
let currentEl = rootEl;
|
|
1964
|
+
while (currentEl && currentEl !== document.body) {
|
|
1965
|
+
if (hasVisibleNextFlowSibling(currentEl)) {
|
|
1966
|
+
return false;
|
|
1967
|
+
}
|
|
1968
|
+
currentEl = currentEl.parentElement;
|
|
1969
|
+
}
|
|
1970
|
+
return true;
|
|
1971
|
+
};
|
|
1972
|
+
|
|
1973
|
+
const scheduleTableHeightRecalc = () => {
|
|
1974
|
+
if (autoTableHeightRaf.value) {
|
|
1975
|
+
cancelAnimationFrame(autoTableHeightRaf.value);
|
|
1976
|
+
}
|
|
1977
|
+
autoTableHeightRaf.value = requestAnimationFrame(() => {
|
|
1978
|
+
autoTableHeightRaf.value = 0;
|
|
1979
|
+
getTableHeight();
|
|
1980
|
+
});
|
|
1981
|
+
};
|
|
1982
|
+
|
|
1983
|
+
const setupAutoTableHeightObserver = () => {
|
|
1984
|
+
clearAutoTableHeightObserver();
|
|
1985
|
+
if (!isAutoTableHeightSafe()) {
|
|
1986
|
+
return;
|
|
1987
|
+
}
|
|
1988
|
+
const rootEl = tableWarpRef.value;
|
|
1989
|
+
const parentEl = rootEl?.parentElement;
|
|
1990
|
+
if (!rootEl || !parentEl || typeof ResizeObserver === "undefined") {
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
autoTableHeightObserver.value = new ResizeObserver(() => {
|
|
1994
|
+
scheduleTableHeightRecalc();
|
|
1995
|
+
});
|
|
1996
|
+
autoTableHeightObserver.value.observe(rootEl);
|
|
1997
|
+
autoTableHeightObserver.value.observe(parentEl);
|
|
1998
|
+
autoTableHeightObserver.value.observe(document.body);
|
|
1999
|
+
if (titleHeaderRef.value) {
|
|
2000
|
+
autoTableHeightObserver.value.observe(titleHeaderRef.value);
|
|
2001
|
+
}
|
|
2002
|
+
if (filterRef.value) {
|
|
2003
|
+
autoTableHeightObserver.value.observe(filterRef.value);
|
|
2004
|
+
}
|
|
2005
|
+
let prevSibling = rootEl.previousElementSibling;
|
|
2006
|
+
while (prevSibling) {
|
|
2007
|
+
if (isVisibleFlowElement(prevSibling)) {
|
|
2008
|
+
autoTableHeightObserver.value.observe(prevSibling);
|
|
2009
|
+
}
|
|
2010
|
+
prevSibling = prevSibling.previousElementSibling;
|
|
2011
|
+
}
|
|
2012
|
+
};
|
|
2013
|
+
|
|
2014
|
+
const getTableTitleHeight = () => {
|
|
2015
|
+
return (
|
|
2016
|
+
tableRef.value?.$el.getElementsByClassName("ant-table-title")[0]
|
|
2017
|
+
?.offsetHeight || 0
|
|
2018
|
+
);
|
|
2019
|
+
};
|
|
2020
|
+
|
|
2021
|
+
const getTableHeaderHeight = () => {
|
|
2022
|
+
return (
|
|
2023
|
+
tableRef.value?.$el.getElementsByClassName("ant-table-thead")[0]
|
|
2024
|
+
?.offsetHeight || 0
|
|
2025
|
+
);
|
|
1883
2026
|
};
|
|
2027
|
+
|
|
2028
|
+
const getTablePaginationHeight = () => {
|
|
2029
|
+
let pagHeight =
|
|
2030
|
+
tableRef.value?.$el.getElementsByClassName("ant-pagination")[0]
|
|
2031
|
+
?.offsetHeight || 0;
|
|
2032
|
+
if (pagHeight) {
|
|
2033
|
+
pagHeight += 32;
|
|
2034
|
+
}
|
|
2035
|
+
return pagHeight;
|
|
2036
|
+
};
|
|
2037
|
+
|
|
2038
|
+
const getFilterHeight = () => {
|
|
2039
|
+
return filterRef.value?.offsetHeight || 0;
|
|
2040
|
+
};
|
|
2041
|
+
|
|
1884
2042
|
const closeTages = (key) => {
|
|
1885
2043
|
for (let i = 0; i < state.filterList?.length; i++) {
|
|
1886
2044
|
if (state.filterList[i].field === key) {
|
|
@@ -2814,29 +2972,28 @@ export default defineComponent({
|
|
|
2814
2972
|
};
|
|
2815
2973
|
|
|
2816
2974
|
const getTableHeight = () => {
|
|
2817
|
-
|
|
2975
|
+
if (tableHeightTimer.value) {
|
|
2976
|
+
clearTimeout(tableHeightTimer.value);
|
|
2977
|
+
}
|
|
2978
|
+
tableHeightTimer.value = setTimeout(() => {
|
|
2979
|
+
tableHeightTimer.value = 0;
|
|
2818
2980
|
nextTick(() => {
|
|
2981
|
+
const tableEl = tableRef.value?.$el;
|
|
2982
|
+
if (!tableEl) {
|
|
2983
|
+
return;
|
|
2984
|
+
}
|
|
2819
2985
|
if (props.tableHeight) {
|
|
2820
|
-
let tTitleHeight =
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
let
|
|
2824
|
-
tableRef.value.$el.getElementsByClassName("ant-table-thead")[0]
|
|
2825
|
-
?.offsetHeight || 0;
|
|
2826
|
-
let tPagHeight =
|
|
2827
|
-
tableRef.value.$el.getElementsByClassName("ant-pagination")[0]
|
|
2828
|
-
?.offsetHeight || 0;
|
|
2829
|
-
let filterHeight = filterRef.value?.offsetHeight || 0;
|
|
2830
|
-
if (tPagHeight) {
|
|
2831
|
-
tPagHeight = tPagHeight + 32; // 分页的margin距离
|
|
2832
|
-
}
|
|
2986
|
+
let tTitleHeight = getTableTitleHeight();
|
|
2987
|
+
let tHeaderHeight = getTableHeaderHeight();
|
|
2988
|
+
let tPagHeight = getTablePaginationHeight();
|
|
2989
|
+
let filterHeight = getFilterHeight();
|
|
2833
2990
|
if (utils.isEnv()) {
|
|
2834
2991
|
console.log(
|
|
2835
2992
|
props.tableHeight,
|
|
2836
2993
|
tTitleHeight,
|
|
2837
2994
|
tHeaderHeight,
|
|
2838
2995
|
tPagHeight,
|
|
2839
|
-
|
|
2996
|
+
tableEl.getElementsByClassName("ant-table-thead")[0],
|
|
2840
2997
|
"0000000000000000000"
|
|
2841
2998
|
);
|
|
2842
2999
|
}
|
|
@@ -2846,9 +3003,33 @@ export default defineComponent({
|
|
|
2846
3003
|
tHeaderHeight -
|
|
2847
3004
|
tPagHeight -
|
|
2848
3005
|
filterHeight;
|
|
3006
|
+
tableScrollHeight = Math.max(0, Math.floor(tableScrollHeight));
|
|
2849
3007
|
if (state.tableScrollHeight !== tableScrollHeight) {
|
|
2850
3008
|
state.tableScrollHeight = tableScrollHeight;
|
|
2851
3009
|
}
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
if (props.autoTableHeight && isAutoTableHeightSafe()) {
|
|
3013
|
+
const tableTop = tableEl.getBoundingClientRect()?.top || 0;
|
|
3014
|
+
const boundaryBottom = getAutoTableHeightBoundaryBottom(tableEl);
|
|
3015
|
+
let tableScrollHeight =
|
|
3016
|
+
boundaryBottom -
|
|
3017
|
+
tableTop -
|
|
3018
|
+
getTableTitleHeight() -
|
|
3019
|
+
getTableHeaderHeight() -
|
|
3020
|
+
getTablePaginationHeight() -
|
|
3021
|
+
autoTableHeightBottomOffset;
|
|
3022
|
+
tableScrollHeight = Math.max(
|
|
3023
|
+
autoTableHeightMinBody,
|
|
3024
|
+
Math.ceil(tableScrollHeight)
|
|
3025
|
+
);
|
|
3026
|
+
if (state.tableScrollHeight !== tableScrollHeight) {
|
|
3027
|
+
state.tableScrollHeight = tableScrollHeight;
|
|
3028
|
+
}
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
if (state.tableScrollHeight !== 0) {
|
|
3032
|
+
state.tableScrollHeight = 0;
|
|
2852
3033
|
}
|
|
2853
3034
|
});
|
|
2854
3035
|
}, 0);
|
|
@@ -3580,6 +3761,7 @@ export default defineComponent({
|
|
|
3580
3761
|
|
|
3581
3762
|
const handleResize = () => {
|
|
3582
3763
|
state.isMobile = window.innerWidth < 768;
|
|
3764
|
+
scheduleTableHeightRecalc();
|
|
3583
3765
|
};
|
|
3584
3766
|
|
|
3585
3767
|
let num = 1;
|
|
@@ -3811,20 +3993,50 @@ export default defineComponent({
|
|
|
3811
3993
|
watch(
|
|
3812
3994
|
() => props.tableHeight,
|
|
3813
3995
|
() => {
|
|
3996
|
+
setupAutoTableHeightObserver();
|
|
3814
3997
|
getTableHeight();
|
|
3815
3998
|
}
|
|
3816
3999
|
);
|
|
3817
4000
|
|
|
4001
|
+
watch(
|
|
4002
|
+
() => props.autoTableHeight,
|
|
4003
|
+
() => {
|
|
4004
|
+
setupAutoTableHeightObserver();
|
|
4005
|
+
scheduleTableHeightRecalc();
|
|
4006
|
+
}
|
|
4007
|
+
);
|
|
4008
|
+
|
|
4009
|
+
watch(
|
|
4010
|
+
() => [state.filterList.length, isTitleCollapsed.value],
|
|
4011
|
+
() => {
|
|
4012
|
+
nextTick(() => {
|
|
4013
|
+
setupAutoTableHeightObserver();
|
|
4014
|
+
scheduleTableHeightRecalc();
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
);
|
|
4018
|
+
|
|
3818
4019
|
onMounted(() => {
|
|
3819
4020
|
createColumnSlots();
|
|
3820
4021
|
createButtonIconSlots();
|
|
3821
4022
|
window.addEventListener("resize", handleResize);
|
|
3822
4023
|
handleResize();
|
|
4024
|
+
setupAutoTableHeightObserver();
|
|
4025
|
+
scheduleTableHeightRecalc();
|
|
3823
4026
|
init();
|
|
3824
4027
|
});
|
|
3825
4028
|
|
|
3826
4029
|
onBeforeUnmount(() => {
|
|
3827
4030
|
window.removeEventListener("resize", handleResize);
|
|
4031
|
+
clearAutoTableHeightObserver();
|
|
4032
|
+
if (autoTableHeightRaf.value) {
|
|
4033
|
+
cancelAnimationFrame(autoTableHeightRaf.value);
|
|
4034
|
+
autoTableHeightRaf.value = 0;
|
|
4035
|
+
}
|
|
4036
|
+
if (tableHeightTimer.value) {
|
|
4037
|
+
clearTimeout(tableHeightTimer.value);
|
|
4038
|
+
tableHeightTimer.value = 0;
|
|
4039
|
+
}
|
|
3828
4040
|
});
|
|
3829
4041
|
|
|
3830
4042
|
const initColumns = () => {
|
|
@@ -4084,6 +4296,8 @@ export default defineComponent({
|
|
|
4084
4296
|
columnSlots,
|
|
4085
4297
|
actionBtnShow,
|
|
4086
4298
|
actionBtnDisabled,
|
|
4299
|
+
tableWarpRef,
|
|
4300
|
+
titleHeaderRef,
|
|
4087
4301
|
tableRef,
|
|
4088
4302
|
isInDrawer,
|
|
4089
4303
|
realColumns,
|