feat: refs #8655 added button for scrolling up
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
c3c8a78fd8
commit
69452e2627
|
@ -2,6 +2,7 @@
|
|||
import { onMounted } from 'vue';
|
||||
import { useQuasar, Dark } from 'quasar';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnScroll from './components/common/VnScroll.vue';
|
||||
|
||||
const quasar = useQuasar();
|
||||
const { availableLocales, locale, fallbackLocale } = useI18n();
|
||||
|
@ -38,6 +39,7 @@ quasar.iconMapFn = (iconName) => {
|
|||
|
||||
<template>
|
||||
<RouterView />
|
||||
<VnScroll />
|
||||
</template>
|
||||
|
||||
<style lang="scss">
|
||||
|
|
|
@ -164,6 +164,7 @@ const editingField = ref(null);
|
|||
const isTableMode = computed(() => mode.value == TABLE_MODE);
|
||||
const selectRegex = /select/;
|
||||
const emit = defineEmits(['onFetch', 'update:selected', 'saveChanges']);
|
||||
const showButton = ref(false);
|
||||
const tableModes = [
|
||||
{
|
||||
icon: 'view_column',
|
||||
|
@ -178,6 +179,20 @@ const tableModes = [
|
|||
disable: $props.disableOption?.card,
|
||||
},
|
||||
];
|
||||
const scrollToTop = () => {
|
||||
if (tableRef.value) {
|
||||
const virtualScrollContainer = tableRef.value.$el.querySelector('.q-table__middle');
|
||||
if (isTableMode) {
|
||||
virtualScrollContainer.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
showButton.value = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onVirtualScroll = ({ index }) => {
|
||||
showButton.value = index !== 0;
|
||||
handleScroll();
|
||||
};
|
||||
|
||||
onBeforeMount(() => {
|
||||
const urlParams = route.query[$props.searchUrl];
|
||||
|
@ -586,6 +601,16 @@ function removeTextValue(data, getChanges) {
|
|||
}
|
||||
</script>
|
||||
<template>
|
||||
<QBtn
|
||||
v-show="showButton"
|
||||
round
|
||||
color="primary"
|
||||
icon="arrow_upward"
|
||||
class="scroll-to-top"
|
||||
@click="scrollToTop"
|
||||
>
|
||||
<QTooltip>{{ $t('globals.scrollToTop') }}</QTooltip>
|
||||
</QBtn>
|
||||
<RightMenu v-if="$props.rightSearch">
|
||||
<template #right-panel>
|
||||
<VnTableFilter
|
||||
|
@ -624,9 +649,9 @@ function removeTextValue(data, getChanges) {
|
|||
ref="tableRef"
|
||||
v-bind="table"
|
||||
:class="[
|
||||
'vnTable',
|
||||
table ? 'selection-cell' : '',
|
||||
$props.footer ? 'last-row-sticky' : '',
|
||||
'vnTable',
|
||||
table ? 'selection-cell' : '',
|
||||
$props.footer ? 'last-row-sticky' : '',
|
||||
]"
|
||||
wrap-cells
|
||||
:columns="splittedColumns.columns"
|
||||
|
@ -638,7 +663,7 @@ function removeTextValue(data, getChanges) {
|
|||
flat
|
||||
:style="isTableMode && `max-height: ${tableHeight}`"
|
||||
:virtual-scroll="isTableMode"
|
||||
@virtual-scroll="handleScroll"
|
||||
@virtual-scroll="onVirtualScroll"
|
||||
@row-click="(_, row) => rowClickFunction && rowClickFunction(row)"
|
||||
@update:selected="emit('update:selected', $event)"
|
||||
@selection="(details) => handleSelection(details, rows)"
|
||||
|
@ -1217,4 +1242,11 @@ es:
|
|||
label.header-filter > .q-field__inner > .q-field__control {
|
||||
padding: inherit;
|
||||
}
|
||||
|
||||
.scroll-to-top {
|
||||
position: fixed;
|
||||
top: 70px;
|
||||
left: 50%;
|
||||
z-index: 1000;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<script setup>
|
||||
import { ref, onMounted, onUnmounted, watch } from 'vue';
|
||||
|
||||
const scrollPosition = ref(0);
|
||||
const showButton = ref(false);
|
||||
|
||||
const onScroll = () => {
|
||||
scrollPosition.value = window.scrollY;
|
||||
};
|
||||
|
||||
watch(scrollPosition, (newValue) => {
|
||||
showButton.value = newValue > 0;
|
||||
});
|
||||
|
||||
const scrollToTop = () => {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('scroll', onScroll);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('scroll', onScroll);
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
<QBtn
|
||||
v-if="showButton"
|
||||
round
|
||||
color="primary"
|
||||
icon="arrow_upward"
|
||||
class="scroll-to-top"
|
||||
@click="scrollToTop"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.scroll-to-top {
|
||||
position: fixed;
|
||||
top: 70px;
|
||||
left: 50%;
|
||||
z-index: 1000;
|
||||
}
|
||||
</style>
|
Loading…
Reference in New Issue