Skip to content

Commit

Permalink
fix: 🐛 修复ta模块语法错误
Browse files Browse the repository at this point in the history
  • Loading branch information
G committed Jan 7, 2024
1 parent 59c5997 commit 6f08208
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions apps/admin/src/layout/tags/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const LayoutTags: FC = () => {

useEffect(() => {
const affixTags = initAffixTags(basicRoutes);
for (const tag of affixTags) {
affixTags.forEach((tag) => {
dispatch(addVisitedTags(tag));
}
});
}, []);

useEffect(() => {
Expand All @@ -73,9 +73,9 @@ const LayoutTags: FC = () => {
}, [activeTag]);

const initAffixTags = (routes: RouteObject[], basePath: string = '/') => {
let affixTags: RouteObject[] = [];
const affixTags: RouteObject[] = [];

for (const route of routes) {
const processRoute = (route: RouteObject) => {
if (route.meta?.affix) {
const fullPath = route.path!.startsWith('/') ? route.path : basePath + route.path;
affixTags.push({
Expand All @@ -84,9 +84,11 @@ const LayoutTags: FC = () => {
});
}
if (route.children && route.children.length) {
affixTags = affixTags.concat(initAffixTags(route.children, route.path));
route.children.forEach((child) => processRoute(child));
}
}
};

routes.forEach((route) => processRoute(route));

return affixTags;
};
Expand All @@ -98,15 +100,18 @@ const LayoutTags: FC = () => {
const mainBodyWidth = tagsMainBody.current?.offsetWidth!;
if (mainBodyWidth < mainWidth) {
leftOffset = 0;
} else if (tag?.offsetLeft! < -tagsBodyLeft) {
} else if ((tag?.offsetLeft ?? 0) < -tagsBodyLeft) {
// 标签在可视区域左侧 (The active tag on the left side of the layout_tags-main)
leftOffset = -tag?.offsetLeft! + mainBodyPadding;
} else if (tag?.offsetLeft! > -tagsBodyLeft && tag?.offsetLeft! + tag?.offsetWidth! < -tagsBodyLeft + mainWidth) {
leftOffset = (tag?.offsetLeft ?? 0) + mainBodyPadding;
} else if (
(tag?.offsetLeft ?? 0) > -tagsBodyLeft &&
(tag?.offsetLeft ?? 0) + (tag?.offsetWidth ?? 0) < -tagsBodyLeft + mainWidth
) {
// 标签在可视区域 (The active tag on the layout_tags-main)
leftOffset = Math.min(0, mainWidth - tag?.offsetWidth! - tag?.offsetLeft! - mainBodyPadding);
leftOffset = Math.min(0, mainWidth - (tag?.offsetWidth ?? 0) - (tag?.offsetLeft ?? 0) - mainBodyPadding);
} else {
// 标签在可视区域右侧 (The active tag on the right side of the layout_tags-main)
leftOffset = -(tag?.offsetLeft! - (mainWidth - mainBodyPadding - tag?.offsetWidth!));
leftOffset = -((tag?.offsetLeft ?? 0) - (mainWidth - mainBodyPadding - (tag?.offsetWidth ?? 0)));
}
setTagsBodyLeft(leftOffset);
};
Expand Down

0 comments on commit 6f08208

Please sign in to comment.