From 33dfb3bab2cff0f6559df6acfa9c93f147a19447 Mon Sep 17 00:00:00 2001 From: yuntian001 Date: Fri, 18 Aug 2023 21:10:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20tag=E6=BB=9A=E5=8A=A8=E4=BC=9A=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=A4=9A=E5=B1=95=E7=A4=BA=E5=89=8D=E4=B8=80=E4=B8=AA?= =?UTF-8?q?/=E5=90=8E=E4=B8=80=E4=B8=AAtag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../header/components/tagBar/index.vue | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/layout/components/header/components/tagBar/index.vue b/src/layout/components/header/components/tagBar/index.vue index c0a9a783..d4295bf9 100644 --- a/src/layout/components/header/components/tagBar/index.vue +++ b/src/layout/components/header/components/tagBar/index.vue @@ -131,19 +131,30 @@ const go = () => { const jump = (index: number) => { nextTick(() => { if (tagsRef.value[index]) { - const offsetLeft = tagsRef.value[index].offsetLeft; - const offsetWidth = tagsRef.value[index].offsetWidth; - const offsetRight = offsetWidth + offsetLeft; + currentTag.value = tags[index]; + if (index === 0) { + setScrollLeft(0); + return; + } + if (index === tagsRef.value.length - 1) { + setScrollLeft(tagsRef.value[tagsRef.value.length - 1].offsetLeft); + return; + } const parentWidth = scrollbarRef.value!.$el.clientWidth; const parentLeft = scrollLeft.value; const parentRight = parentWidth + scrollLeft.value; - if (offsetLeft < parentLeft) { + const lastLeft = tagsRef.value[index - 1].offsetLeft; + const offsetLeft = tagsRef.value[index].offsetLeft; + const offsetRight = offsetLeft + tagsRef.value[index].offsetWidth; + const nextLeft = tagsRef.value[index + 1].offsetLeft; + const nextRight = nextLeft + tagsRef.value[index + 1].offsetWidth; + if (parentWidth <= offsetRight - lastLeft || parentWidth <= nextRight - offsetLeft) { setScrollLeft(offsetLeft); + } else if (lastLeft < parentLeft) { + setScrollLeft(lastLeft); + } else if (nextRight > parentRight) { + setScrollLeft(nextRight - parentWidth); } - if (offsetRight > parentRight) { - setScrollLeft(offsetLeft + offsetWidth - parentWidth); - } - currentTag.value = tags[index]; } }); };