shaogen1995 2 yıl önce
ebeveyn
işleme
4f4db79abb
1 değiştirilmiş dosya ile 53 ekleme ve 23 silme
  1. 53 23
      houtai/src/pages/Layout/index.tsx

+ 53 - 23
houtai/src/pages/Layout/index.tsx

@@ -61,7 +61,7 @@ function Layout() {
         incoAc: inco1Ac,
         son: [
           {
-            id: 100,
+            id: 110,
             name: "热度统计",
             path: "/",
             done: false,
@@ -74,42 +74,42 @@ function Layout() {
         incoAc: inco2Ac,
         son: [
           {
-            id: 200,
+            id: 220,
             name: "场景管理",
             path: "/scene",
             done: false,
             Com: React.lazy(() => import("../B1Scene")),
           },
           {
-            id: 300,
+            id: 230,
             name: "馆藏管理",
             path: "/goods",
             done: false,
             Com: React.lazy(() => import("../B2Goods")),
           },
           {
-            id: 400,
+            id: 240,
             name: "万物墙管理",
             path: "/wall",
             done: false,
             Com: React.lazy(() => import("../B3Wall")),
           },
           {
-            id: 500,
+            id: 250,
             name: "弹幕管理",
             path: "/barrage",
             done: false,
             Com: React.lazy(() => import("../B4Barrage")),
           },
           {
-            id: 600,
+            id: 260,
             name: "题库管理",
             path: "/topic",
             done: false,
             Com: React.lazy(() => import("../B5Topic")),
           },
           {
-            id: 700,
+            id: 270,
             name: "智能导览管理",
             path: "/smart",
             done: false,
@@ -156,28 +156,55 @@ function Layout() {
     }
   }, [listTemp]);
 
+  const authPageArr = useSelector(
+    (state: RootState) => state.loginStore.authPageArr
+  );
+
   // 权限的数据和页面判断
   useEffect(() => {
-    // authPageArr.forEach((v) => {
-    //   if (v.authority) {
-    //     listTemp.forEach((v2) => {
-    //       if (v.id === v2.id) v2.done = true;
-    //     });
-    //   }
-    // });
-    // const newList = listTemp.filter((v) => v.done);
-    // setList(listTemp.filter((v) => v.done));
-  }, [listTemp]);
+    authPageArr.forEach((v1) => {
+      v1.children?.forEach((v2) => {
+        if (v2.authority) {
+          listTemp.forEach((v3) => {
+            v3.son.forEach((v4) => {
+              if (v2.id === v4.id) v4.done = true;
+            });
+          });
+        }
+      });
+    });
+    const arr = listTemp.map((v1) => {
+      return {
+        ...v1,
+        son: v1.son.filter((v2) => v2.done),
+      };
+    });
+    setList(arr);
+  }, [authPageArr, listTemp]);
 
   const [list, setList] = useState(listTemp);
 
   // 进页面看看第一个页面有权限的是哪一个
-  // useEffect(() => {
-  //   const userInfo = getTokenInfo().user;
-  //   if (userInfo.isAdmin !== 1) {
-  //     if (list[0] && list[0].id !== 100) history.replace(list[0].path);
-  //   }
-  // }, [list]);
+
+  const timeRef = useRef(0);
+
+  useEffect(() => {
+    const userInfo = getTokenInfo().user;
+    if (userInfo.isAdmin !== 1) {
+      clearTimeout(timeRef.current);
+      timeRef.current = window.setTimeout(() => {
+        const newList: any = [];
+        list.forEach((v1) => {
+          v1.son.forEach((v2) => {
+            newList.push(v2);
+          });
+        });
+
+        if (newList[0] && newList[0].id !== 110)
+          history.replace(newList[0].path);
+      }, 100);
+    }
+  }, [list]);
 
   // 进页面获取所有下拉信息和权限信息
   useEffect(() => {
@@ -265,6 +292,9 @@ function Layout() {
           {list.map((v1) => (
             <div className="mainBoxL2RowBox" key={v1.title}>
               <div
+                style={{
+                  display: v1.son.every((v) => !v.done) ? "none" : "flex",
+                }}
                 className={classNames(
                   "mainBoxL2RowBoxTit",
                   row1ActiveFu(v1.title) ? "activeRow1" : ""