This commit is contained in:
parent
c9bea020fa
commit
6434a37598
|
@ -39,7 +39,7 @@ quasar.iconMapFn = (iconName) => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<RouterView />
|
<RouterView />
|
||||||
<VnScroll mode="window" />
|
<VnScroll/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|
|
@ -190,13 +190,14 @@ const tableModes = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const onVirtualScroll = ({ to }) => {
|
const onVirtualScroll = ({ to }) => {
|
||||||
const virtualScrollContainer = tableRef.value?.$el?.querySelector('.q-table__middle');
|
handleScroll();
|
||||||
if (virtualScrollContainer) {
|
const virtualScrollContainer = tableRef.value?.$el?.querySelector('.q-table__middle');
|
||||||
virtualScrollContainer.dispatchEvent(new CustomEvent('scroll'));
|
if (virtualScrollContainer) {
|
||||||
if (vnScrollRef.value) {
|
virtualScrollContainer.dispatchEvent(new CustomEvent('scroll'));
|
||||||
vnScrollRef.value.updateScrollContainer(virtualScrollContainer);
|
if (vnScrollRef.value) {
|
||||||
|
vnScrollRef.value.updateScrollContainer(virtualScrollContainer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
|
@ -336,7 +337,13 @@ function handleOnDataSaved(_) {
|
||||||
if (_.onDataSaved) _.onDataSaved({ CrudModelRef: CrudModelRef.value });
|
if (_.onDataSaved) _.onDataSaved({ CrudModelRef: CrudModelRef.value });
|
||||||
else $props.create.onDataSaved(_);
|
else $props.create.onDataSaved(_);
|
||||||
}
|
}
|
||||||
|
function handleScroll() {
|
||||||
|
if ($props.crudModel.disableInfiniteScroll) return;
|
||||||
|
const tMiddle = tableRef.value.$el.querySelector('.q-table__middle');
|
||||||
|
const { scrollHeight, scrollTop, clientHeight } = tMiddle;
|
||||||
|
const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) <= 40;
|
||||||
|
if (isAtBottom) CrudModelRef.value.vnPaginateRef.paginate();
|
||||||
|
}
|
||||||
function handleSelection({ evt, added, rows: selectedRows }, rows) {
|
function handleSelection({ evt, added, rows: selectedRows }, rows) {
|
||||||
if (evt?.shiftKey && added) {
|
if (evt?.shiftKey && added) {
|
||||||
const rowIndex = selectedRows[0].$index;
|
const rowIndex = selectedRows[0].$index;
|
||||||
|
@ -1090,7 +1097,6 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
ref="vnScrollRef"
|
ref="vnScrollRef"
|
||||||
v-if="isTableMode"
|
v-if="isTableMode"
|
||||||
:scroll-target="tableRef?.$el?.querySelector('.q-table__middle')"
|
:scroll-target="tableRef?.$el?.querySelector('.q-table__middle')"
|
||||||
mode="table"
|
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<i18n>
|
<i18n>
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue';
|
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue';
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
scrollTarget: { type: [String, Object], default: 'window' },
|
scrollTarget: { type: [String, Object], default: 'window' }
|
||||||
mode: { type: String, default: 'window' }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const scrollPosition = ref(0);
|
const scrollPosition = ref(0);
|
||||||
|
@ -13,7 +12,7 @@ let scrollContainer = null;
|
||||||
const onScroll = () => {
|
const onScroll = () => {
|
||||||
if (!scrollContainer) return;
|
if (!scrollContainer) return;
|
||||||
scrollPosition.value =
|
scrollPosition.value =
|
||||||
props.mode === 'table'
|
typeof props.scrollTarget === 'object'
|
||||||
? scrollContainer.scrollTop
|
? scrollContainer.scrollTop
|
||||||
: window.scrollY;
|
: window.scrollY;
|
||||||
};
|
};
|
||||||
|
@ -46,27 +45,17 @@ defineExpose({
|
||||||
const initScrollContainer = async () => {
|
const initScrollContainer = async () => {
|
||||||
await nextTick();
|
await nextTick();
|
||||||
|
|
||||||
if (props.mode === 'table') {
|
if (typeof props.scrollTarget === 'object') {
|
||||||
if (typeof props.scrollTarget === 'object') {
|
scrollContainer = props.scrollTarget;
|
||||||
scrollContainer = props.scrollTarget;
|
|
||||||
} else {
|
|
||||||
scrollContainer = document.querySelector(props.scrollTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!scrollContainer && props.scrollTarget !== 'window') {
|
|
||||||
setTimeout(initScrollContainer, 100);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
scrollContainer = window;
|
scrollContainer = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrollContainer) {
|
if (!scrollContainer) return
|
||||||
scrollContainer.addEventListener('scroll', onScroll);
|
scrollContainer.addEventListener('scroll', onScroll);
|
||||||
onScroll();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initScrollContainer();
|
initScrollContainer();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue