|
@@ -2,17 +2,18 @@
|
|
|
|
|
|
import "./module.css";
|
|
|
|
|
|
-import {ImageWithFallback} from "@/components/ImageWithFallback";
|
|
|
-import {Button} from "@/components/ui/button";
|
|
|
-import {Skeleton} from "@/components/ui/skeleton";
|
|
|
-import {Userinfo} from "@/components/Userinfo";
|
|
|
-import {ChevronRight, icons} from "lucide-react";
|
|
|
+import { Menu } from "@/app/api/v1/(model)/menu";
|
|
|
+import { ImageWithFallback } from "@/components/ImageWithFallback";
|
|
|
+import { Button } from "@/components/ui/button";
|
|
|
+import { Skeleton } from "@/components/ui/skeleton";
|
|
|
+import { Userinfo } from "@/components/Userinfo";
|
|
|
+import { ChevronRight, icons } from "lucide-react";
|
|
|
import Image from "next/image";
|
|
|
-import {useRouter} from "next/navigation";
|
|
|
-import {useEffect, useState} from "react";
|
|
|
-import {Company} from "../api/v1/(model)/company";
|
|
|
-import {Response} from "../api/v1/(response)/response";
|
|
|
-import {Menu} from "@/app/api/v1/(model)/menu";
|
|
|
+import { useRouter } from "next/navigation";
|
|
|
+import { useEffect, useState } from "react";
|
|
|
+import cookies from "react-cookies";
|
|
|
+import { Company } from "../api/v1/(model)/company";
|
|
|
+import { Response } from "../api/v1/(response)/response";
|
|
|
|
|
|
async function getMenus(menuId: number) {
|
|
|
const response = await fetch(`/api/v1/user/menu?parent_id=${menuId}`);
|
|
@@ -33,6 +34,8 @@ async function getMenus(menuId: number) {
|
|
|
* @author luoyangwei
|
|
|
*/
|
|
|
export default function LeftSlider() {
|
|
|
+ const route = useRouter()
|
|
|
+
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
const [parentMenus, setParentMenus] = useState<Menu[]>([]);
|
|
|
const [itemMenus, setItemMenus] = useState<Menu[]>([]);
|
|
@@ -55,6 +58,12 @@ export default function LeftSlider() {
|
|
|
}, []);
|
|
|
|
|
|
useEffect(() => {
|
|
|
+ const token = cookies.load('token');
|
|
|
+ console.log(token);
|
|
|
+ if (!token) {
|
|
|
+ route.push('/sign-in')
|
|
|
+ return;
|
|
|
+ }
|
|
|
getMenus(0)
|
|
|
.then(handleParentMenu)
|
|
|
.catch(console.error)
|
|
@@ -126,7 +135,7 @@ export default function LeftSlider() {
|
|
|
key={index}
|
|
|
onClick={() => handleParentMenuSelect(item.id)}
|
|
|
className={`${item.id === parentMenuId ? "bg-primary text-white hover:bg-primary/90" : "hover:bg-gray-100"} size-[var(--slider-menu-item-size)] rounded-lg flex-center-center text-gray-700 transition-all`}>
|
|
|
- <Icon name={item.menu_icon} size={24}/>
|
|
|
+ <Icon name={item.menu_icon} size={24} />
|
|
|
</button>
|
|
|
))}
|
|
|
</div>
|
|
@@ -135,7 +144,7 @@ export default function LeftSlider() {
|
|
|
<div className={"flex-1 border-r border-gray-100"}>
|
|
|
|
|
|
{/* 机构信息 */}
|
|
|
- <CompanyInfo/>
|
|
|
+ <CompanyInfo />
|
|
|
|
|
|
<div className={"flex flex-col gap-4 px-4"}>
|
|
|
{/*主菜单信息,通过 filter 获取*/}
|
|
@@ -186,21 +195,21 @@ function CompanyInfo() {
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
- {loading ? <Skeleton className="w-[90%] h-16 mx-4 my-6"/> :
|
|
|
+ {loading ? <Skeleton className="w-[90%] h-16 mx-4 my-6" /> :
|
|
|
<header className={"flex items-center justify-between border-b border-gray-100 py-7 px-4"}>
|
|
|
{company &&
|
|
|
<Userinfo
|
|
|
avatar={
|
|
|
company.company_avatar ?
|
|
|
- <ImageWithFallback src={company.company_avatar}/>
|
|
|
+ <ImageWithFallback src={company.company_avatar} />
|
|
|
:
|
|
|
<div
|
|
|
className={"size-full bg-black rounded-lg flex-center-center text-white"}>{company.company_name.substring(0, 1)}</div>
|
|
|
}
|
|
|
name={company.company_name}
|
|
|
- subtitle="0 设备在线"/>
|
|
|
+ subtitle="0 设备在线" />
|
|
|
}
|
|
|
- <Button variant={"outline"} size={"icon"}><ChevronRight/></Button>
|
|
|
+ <Button variant={"outline"} size={"icon"}><ChevronRight /></Button>
|
|
|
</header>}
|
|
|
</>
|
|
|
)
|
|
@@ -213,13 +222,13 @@ interface MenuItemProps {
|
|
|
}
|
|
|
|
|
|
// @ts-ignore
|
|
|
-const Icon = ({name, size}) => {
|
|
|
+const Icon = ({ name, size }) => {
|
|
|
// @ts-ignore
|
|
|
const LucideIcon = icons[name];
|
|
|
- return <LucideIcon size={size}/>;
|
|
|
+ return <LucideIcon size={size} />;
|
|
|
};
|
|
|
|
|
|
-function MenuItem({item, active, onChange}: MenuItemProps) {
|
|
|
+function MenuItem({ item, active, onChange }: MenuItemProps) {
|
|
|
const route = useRouter();
|
|
|
|
|
|
function handleMenuItemClick(item: Menu) {
|
|
@@ -231,10 +240,10 @@ function MenuItem({item, active, onChange}: MenuItemProps) {
|
|
|
|
|
|
return (
|
|
|
<button data-id={item.menu_href} onClick={() => handleMenuItemClick(item)}
|
|
|
- className={"w-full bg-slate-50 p-4 rounded-lg overflow-hidden flex items-center justify-between gap-4 text-left"}>
|
|
|
+ className={"w-full bg-slate-50 p-4 rounded-lg overflow-hidden flex items-center justify-between gap-4 text-left"}>
|
|
|
<div
|
|
|
className={`size-12 flex-center-center rounded-lg transition-all ${!active ? "bg-blue-50" : "bg-primary text-white"}`}>
|
|
|
- <Icon name={item.menu_icon} size={22}/>
|
|
|
+ <Icon name={item.menu_icon} size={22} />
|
|
|
</div>
|
|
|
<div className={"flex-1"}>
|
|
|
<h3 className={"text-lg font-medium"}>{item.menu_title}</h3>
|