兰宝车间质量管理系统-前端
LiuHao
2023-04-02 251d2411f235e23209d57173857e05b637729ce8
src/layout/components/TagsView/ScrollPane.vue
@@ -1,21 +1,11 @@
<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)
@@ -24,12 +14,12 @@
  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')
}
@@ -37,8 +27,8 @@
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;
@@ -56,10 +46,11 @@
  } 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) {
@@ -89,7 +80,13 @@
})
</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;
@@ -102,4 +99,4 @@
    height: 49px;
  }
}
</style>
</style>