perf: tag

This commit is contained in:
lrl 2021-11-20 16:41:30 +08:00
parent c3645fd760
commit 034f1577c2
2 changed files with 51 additions and 0 deletions

View File

@ -119,6 +119,8 @@
transition: transform 0.5s ease-in-out; transition: transform 0.5s ease-in-out;
.scroll-item { .scroll-item {
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
&:nth-child(1) { &:nth-child(1) {
margin-left: 5px; margin-left: 5px;
} }

View File

@ -54,6 +54,54 @@ const tabDom = templateRef<HTMLElement | null>("tabDom", null);
const containerDom = templateRef<HTMLElement | null>("containerDom", null); const containerDom = templateRef<HTMLElement | null>("containerDom", null);
const scrollbarDom = templateRef<HTMLElement | null>("scrollbarDom", null); const scrollbarDom = templateRef<HTMLElement | null>("scrollbarDom", null);
watch([route], () => {
const index = dynamicTagList.value.findIndex(item => {
return item.path === route.path;
});
moveToView(index);
});
const tabNavPadding = 10;
const moveToView = (index: number): void => {
if (!instance.refs["dynamic" + index]) {
return;
}
const tabItemEl = instance.refs["dynamic" + index];
const tabItemElOffsetLeft = (tabItemEl as HTMLElement).offsetLeft;
const tabItemOffsetWidth = (tabItemEl as HTMLElement).offsetWidth;
//
const scrollbarDomWidth = scrollbarDom.value
? scrollbarDom.value.offsetWidth
: 0;
//
const tabDomWidth = tabDom.value ? tabDom.value.offsetWidth : 0;
if (tabDomWidth < scrollbarDomWidth || tabItemElOffsetLeft === 0) {
translateX.value = 0;
} else if (tabItemElOffsetLeft < -translateX.value) {
//
translateX.value = -tabItemElOffsetLeft + tabNavPadding;
} else if (
tabItemElOffsetLeft > -translateX.value &&
tabItemElOffsetLeft + tabItemOffsetWidth <
-translateX.value + scrollbarDomWidth
) {
//
translateX.value = Math.min(
0,
scrollbarDomWidth -
tabItemOffsetWidth -
tabItemElOffsetLeft -
tabNavPadding
);
} else {
//
translateX.value = -(
tabItemElOffsetLeft -
(scrollbarDomWidth - tabNavPadding - tabItemOffsetWidth)
);
}
};
const handleScroll = (offset: number): void => { const handleScroll = (offset: number): void => {
const scrollbarDomWidth = scrollbarDom.value const scrollbarDomWidth = scrollbarDom.value
? scrollbarDom.value?.offsetWidth ? scrollbarDom.value?.offsetWidth
@ -341,6 +389,7 @@ function showMenuModel(currentPath: string, refresh = false) {
let routeLength = unref(relativeStorage.routesInStorage).length; let routeLength = unref(relativeStorage.routesInStorage).length;
// currentIndex1 // currentIndex1
let currentIndex = allRoute.findIndex(v => v.path === currentPath); let currentIndex = allRoute.findIndex(v => v.path === currentPath);
moveToView(currentIndex);
// currentIndexrouteLength-1 // currentIndexrouteLength-1
showMenus(true); showMenus(true);