mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-17 11:14:19 +00:00
修复仓库冲突
This commit is contained in:
@@ -1,81 +1,71 @@
|
||||
"use client"
|
||||
"use client";
|
||||
|
||||
import styles from "./HomeSidebar.module.css"
|
||||
import styles from "./HomeSidebar.module.css";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SidebarChild, SidebarChildVO } from "@/app/home/components/home-sidebar/HomeSidebarChild";
|
||||
import { useRouter, usePathname, useSearchParams } from "next/navigation";
|
||||
import {
|
||||
SidebarChild,
|
||||
SidebarChildVO
|
||||
} from "@/app/home/components/home-sidebar/HomeSidebarChild";
|
||||
import { useRouter, usePathname } from "next/navigation";
|
||||
import { sidebarConfigList } from "@/app/home/components/home-sidebar/sidbarConfigList";
|
||||
|
||||
// TODO 侧边导航栏要加动画
|
||||
export default function HomeSidebar({
|
||||
onSelectedChange
|
||||
onSelectedChangeAction
|
||||
}: {
|
||||
onSelectedChange: (sidebarChild: SidebarChildVO) => void
|
||||
onSelectedChangeAction: (sidebarChild: SidebarChildVO) => void;
|
||||
}) {
|
||||
// 路由相关
|
||||
const router = useRouter()
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
// 路由被动变化时处理
|
||||
useEffect(() => {
|
||||
handleRouteChange(pathname)
|
||||
}, [pathname, searchParams]);
|
||||
// 路由相关
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
// 路由被动变化时处理
|
||||
useEffect(() => {
|
||||
handleRouteChange(pathname);
|
||||
}, [pathname]);
|
||||
|
||||
const [selectedChild, setSelectedChild] = useState<SidebarChildVO>(sidebarConfigList[0])
|
||||
const [selectedChild, setSelectedChild] = useState<SidebarChildVO>(
|
||||
sidebarConfigList[0]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('HomeSidebar挂载完成');
|
||||
initSelect()
|
||||
return () => console.log('HomeSidebar卸载');
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
console.log("HomeSidebar挂载完成");
|
||||
initSelect();
|
||||
return () => console.log("HomeSidebar卸载");
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
function handleChildClick(child: SidebarChildVO) {
|
||||
setSelectedChild(child);
|
||||
handleRoute(child);
|
||||
onSelectedChangeAction(child);
|
||||
}
|
||||
|
||||
function initSelect() {
|
||||
handleChildClick(sidebarConfigList[0]);
|
||||
}
|
||||
|
||||
function handleChildClick(child: SidebarChildVO) {
|
||||
setSelectedChild(child)
|
||||
handleRoute(child)
|
||||
onSelectedChange(child)
|
||||
}
|
||||
|
||||
function initSelect() {
|
||||
// 根据当前URL路径选择相应的菜单项,而不是总是使用第一个菜单项
|
||||
const currentPath = pathname;
|
||||
const matchedChild = sidebarConfigList.find(child => child.route === currentPath);
|
||||
|
||||
if (matchedChild) {
|
||||
// 如果找到匹配的菜单项,则选择它
|
||||
setSelectedChild(matchedChild);
|
||||
onSelectedChange(matchedChild);
|
||||
} else {
|
||||
// 如果没有匹配项,则回退到默认选择第一个菜单项
|
||||
handleChildClick(sidebarConfigList[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function handleRoute(child: SidebarChildVO) {
|
||||
console.log(child)
|
||||
router.push(`${child.route}`)
|
||||
}
|
||||
|
||||
function handleRouteChange(pathname: string) {
|
||||
// TODO 这段逻辑并不好,未来router封装好后改掉
|
||||
// 判断在home下,并且路由更改的是自己的路由子组件则更新UI
|
||||
const routeList = pathname.split('/')
|
||||
if (
|
||||
routeList[1] === "home" &&
|
||||
sidebarConfigList.find(childConfig =>
|
||||
childConfig.route === pathname
|
||||
)
|
||||
) {
|
||||
console.log("find success")
|
||||
const routeSelectChild = sidebarConfigList.find(childConfig =>
|
||||
childConfig.route === pathname
|
||||
)
|
||||
if (routeSelectChild) {
|
||||
setSelectedChild(routeSelectChild)
|
||||
}
|
||||
}
|
||||
function handleRoute(child: SidebarChildVO) {
|
||||
console.log(child);
|
||||
router.push(`${child.route}`);
|
||||
}
|
||||
|
||||
function handleRouteChange(pathname: string) {
|
||||
// TODO 这段逻辑并不好,未来router封装好后改掉
|
||||
// 判断在home下,并且路由更改的是自己的路由子组件则更新UI
|
||||
const routeList = pathname.split("/");
|
||||
if (
|
||||
routeList[1] === "home" &&
|
||||
sidebarConfigList.find((childConfig) => childConfig.route === pathname)
|
||||
) {
|
||||
console.log("find success");
|
||||
const routeSelectChild = sidebarConfigList.find(
|
||||
(childConfig) => childConfig.route === pathname
|
||||
);
|
||||
if (routeSelectChild) {
|
||||
setSelectedChild(routeSelectChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user