|
@@ -1,10 +1,4 @@
|
|
|
-import React, {
|
|
|
- useCallback,
|
|
|
- useEffect,
|
|
|
- useMemo,
|
|
|
- useRef,
|
|
|
- useState,
|
|
|
-} from "react";
|
|
|
+import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
|
import { CaretUpOutlined, CaretDownOutlined } from "@ant-design/icons";
|
|
|
import styles from "./index.module.scss";
|
|
|
import SpinLoding from "@/components/SpinLoding";
|
|
@@ -24,31 +18,10 @@ import NotFound from "@/components/NotFound";
|
|
|
import { RouterType, RouterTypeRow } from "@/types";
|
|
|
import tabLeftArr from "./data";
|
|
|
import MyPopconfirm from "@/components/MyPopconfirm";
|
|
|
+import { UserListType } from "../Z1user/Z1auth";
|
|
|
+import { Z1_APIgetAuthByUserId } from "@/store/action/Z1user";
|
|
|
|
|
|
function Layout() {
|
|
|
- // 左侧菜单 和 路由 信息
|
|
|
- const [list, setList] = useState([] as RouterType);
|
|
|
-
|
|
|
- // useEffect(()=>{
|
|
|
- // console.log(123,list);
|
|
|
-
|
|
|
- // },[list])
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- const arr = [...tabLeftArr];
|
|
|
-
|
|
|
- // 超级管理员才有 用户管理 和 系统日志
|
|
|
- const flag = getTokenInfo().user.isAdmin === 1;
|
|
|
- arr[1].son[0].done = flag;
|
|
|
- arr[1].son[1].done = flag;
|
|
|
- setList(arr);
|
|
|
- }, []);
|
|
|
-
|
|
|
- // 点击跳转
|
|
|
- const pathCutFu = useCallback((path: string) => {
|
|
|
- history.push(path);
|
|
|
- }, []);
|
|
|
-
|
|
|
// 当前路径选中的左侧菜单
|
|
|
const location = useLocation();
|
|
|
const [path, setPath] = useState("");
|
|
@@ -61,6 +34,70 @@ function Layout() {
|
|
|
setPath(pathTemp);
|
|
|
}, [location]);
|
|
|
|
|
|
+ // 获取用户权限信息
|
|
|
+ const getUserAuthFu = useCallback(async () => {
|
|
|
+ const userInfo = getTokenInfo().user;
|
|
|
+
|
|
|
+ const res = await Z1_APIgetAuthByUserId(userInfo.id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ const tempList: UserListType[] = res.data || [];
|
|
|
+ const isOkIdArr = tempList.filter((c) => c.authority).map((v) => v.id);
|
|
|
+ // 是管理员
|
|
|
+ if (userInfo.isAdmin === 1) {
|
|
|
+ isOkIdArr.push(2100);
|
|
|
+ isOkIdArr.push(2200);
|
|
|
+ }
|
|
|
+
|
|
|
+ const tempArr: RouterTypeRow = [];
|
|
|
+
|
|
|
+ tabLeftArr.forEach((v1) => {
|
|
|
+ if (v1.son && v1.son[0]) {
|
|
|
+ v1.son.forEach((v2) => {
|
|
|
+ if (isOkIdArr.includes(v2.id)) {
|
|
|
+ tempArr.push(v2);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ setRouterCom(tempArr);
|
|
|
+
|
|
|
+ // 如果当前页面没有权限了,跳转有权限的第一个页面
|
|
|
+ const urlAll = window.location.hash;
|
|
|
+ const isNowPath = urlAll.replace("#", "");
|
|
|
+ const pathArr = tempArr.map((v) => v.path);
|
|
|
+ if (!pathArr.includes(isNowPath)) {
|
|
|
+ history.push(pathArr[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ const resList = tabLeftArr.map((v) => ({
|
|
|
+ ...v,
|
|
|
+ son: v.son.filter((c) => isOkIdArr.includes(c.id)),
|
|
|
+ }));
|
|
|
+
|
|
|
+ setList(resList);
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ getUserAuthFu();
|
|
|
+ }, [getUserAuthFu]);
|
|
|
+
|
|
|
+ // 左侧菜单 信息
|
|
|
+ const [list, setList] = useState([] as RouterType);
|
|
|
+
|
|
|
+ // 路由信息(过滤之后的)
|
|
|
+ const [RouterCom, setRouterCom] = useState<RouterTypeRow>([]);
|
|
|
+
|
|
|
+ // useEffect(() => {
|
|
|
+ // console.log(123, list);
|
|
|
+ // }, [list]);
|
|
|
+
|
|
|
+ // 点击跳转
|
|
|
+ const pathCutFu = useCallback((path: string) => {
|
|
|
+ history.push(path);
|
|
|
+ }, []);
|
|
|
+
|
|
|
// 修改密码相关
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
@@ -94,25 +131,6 @@ function Layout() {
|
|
|
history.push("/login");
|
|
|
};
|
|
|
|
|
|
- // 路由信息(过滤之后的)
|
|
|
- const RouterCom = useMemo(() => {
|
|
|
- const arr: RouterTypeRow = [];
|
|
|
- list.forEach((v) => {
|
|
|
- if (v.son && v.son[0]) {
|
|
|
- v.son.forEach((v2) => {
|
|
|
- if (v2.done) arr.push(v2);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- return arr;
|
|
|
- }, [list]);
|
|
|
-
|
|
|
- // 第一个页面不是 项目 管理 的时候 动态 跳转
|
|
|
- useEffect(() => {
|
|
|
- if (RouterCom && RouterCom[0] && RouterCom[0].id !== "1.1")
|
|
|
- history.replace(RouterCom[0].path);
|
|
|
- }, [RouterCom]);
|
|
|
-
|
|
|
return (
|
|
|
<div className={styles.Layout}>
|
|
|
{/* 左边 */}
|
|
@@ -126,24 +144,22 @@ function Layout() {
|
|
|
<div
|
|
|
className={classNames("layoutLRowBox")}
|
|
|
key={v.id}
|
|
|
- hidden={v.son.every((c) => !c.done)}
|
|
|
+ hidden={!v.son.length}
|
|
|
>
|
|
|
{/* 这个项目没有一级目录 */}
|
|
|
{/* <div className="layoutLRowBoxTxt">{v.name}</div> */}
|
|
|
- {v.son
|
|
|
- .filter((c2) => c2.done)
|
|
|
- .map((v2) => (
|
|
|
- <div
|
|
|
- key={v2.id}
|
|
|
- className={classNames(
|
|
|
- "layoutLRowBoxRow",
|
|
|
- path === v2.path ? "active" : ""
|
|
|
- )}
|
|
|
- onClick={() => pathCutFu(v2.path)}
|
|
|
- >
|
|
|
- {v2.name}
|
|
|
- </div>
|
|
|
- ))}
|
|
|
+ {v.son.map((v2) => (
|
|
|
+ <div
|
|
|
+ key={v2.id}
|
|
|
+ className={classNames(
|
|
|
+ "layoutLRowBoxRow",
|
|
|
+ path === v2.path ? "active" : ""
|
|
|
+ )}
|
|
|
+ onClick={() => pathCutFu(v2.path)}
|
|
|
+ >
|
|
|
+ {v2.name}
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
</div>
|
|
|
))}
|
|
|
</div>
|