| | |
| | | <template> |
| | | <el-scrollbar |
| | | ref="scrollContainer" |
| | | :vertical="false" |
| | | class="scroll-container" |
| | | @wheel.prevent="handleScroll" |
| | | > |
| | | <slot /> |
| | | </el-scrollbar> |
| | | </template> |
| | | |
| | | <script setup> |
| | | <script setup lang="ts"> |
| | | import useTagsViewStore from '@/store/modules/tagsView' |
| | | |
| | | import { ElScrollbar } from 'element-plus'; |
| | | import { TagView } from 'vue-router' |
| | | const tagAndTagSpacing = ref(4); |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | const scrollWrapper = computed(() => proxy.$refs.scrollContainer.$refs.wrapRef); |
| | | const scrollContainerRef = ref(ElScrollbar) |
| | | const scrollWrapper = computed(() => scrollContainerRef.value.$refs.wrapRef); |
| | | |
| | | onMounted(() => { |
| | | scrollWrapper.value.addEventListener('scroll', emitScroll, true) |
| | |
| | | scrollWrapper.value.removeEventListener('scroll', emitScroll) |
| | | }) |
| | | |
| | | function handleScroll(e) { |
| | | const eventDelta = e.wheelDelta || -e.deltaY * 40 |
| | | const handleScroll = (e: WheelEvent) => { |
| | | const eventDelta = (e as any).wheelDelta || -e.deltaY * 40 |
| | | const $scrollWrapper = scrollWrapper.value; |
| | | $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4 |
| | | } |
| | | const emits = defineEmits() |
| | | const emits = defineEmits(['scroll']) |
| | | const emitScroll = () => { |
| | | emits('scroll') |
| | | } |
| | |
| | | const tagsViewStore = useTagsViewStore() |
| | | const visitedViews = computed(() => tagsViewStore.visitedViews); |
| | | |
| | | function moveToTarget(currentTag) { |
| | | const $container = proxy.$refs.scrollContainer.$el |
| | | const moveToTarget = (currentTag: TagView) => { |
| | | const $container = scrollContainerRef.value.$el |
| | | const $containerWidth = $container.offsetWidth |
| | | const $scrollWrapper = scrollWrapper.value; |
| | | |
| | |
| | | } else if (lastTag === currentTag) { |
| | | $scrollWrapper.scrollLeft = $scrollWrapper.scrollWidth - $containerWidth |
| | | } else { |
| | | const tagListDom = document.getElementsByClassName('tags-view-item'); |
| | | const tagListDom: any = document.getElementsByClassName('tags-view-item'); |
| | | const currentIndex = visitedViews.value.findIndex(item => item === currentTag) |
| | | let prevTag = null |
| | | let nextTag = null |
| | | |
| | | for (const k in tagListDom) { |
| | | if (k !== 'length' && Object.hasOwnProperty.call(tagListDom, k)) { |
| | | if (tagListDom[k].dataset.path === visitedViews.value[currentIndex - 1].path) { |
| | |
| | | }) |
| | | </script> |
| | | |
| | | <style lang='scss' scoped> |
| | | <template> |
| | | <el-scrollbar ref="scrollContainerRef" :vertical="false" class="scroll-container" @wheel.prevent="handleScroll"> |
| | | <slot /> |
| | | </el-scrollbar> |
| | | </template> |
| | | |
| | | <style lang="scss" scoped> |
| | | .scroll-container { |
| | | white-space: nowrap; |
| | | position: relative; |
| | |
| | | height: 49px; |
| | | } |
| | | } |
| | | </style> |
| | | </style> |