shaogen1995 2 年之前
父節點
當前提交
6f9d00624c

+ 18 - 2
src/components/AuthButton/index.tsx

@@ -1,14 +1,30 @@
 import React, { ReactNode } from "react";
 import { Button } from "antd";
+import { getPowerInfo } from "@/utils/storage";
 
 type Props = {
   [x: string]: any;
   children?: ReactNode;
+  id: number;
 };
-function AuthButton({ children, ...rest }: Props) {
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+const buttonArr = [] as any;
+powerInfo.forEach((v: any) => {
+  v.children.forEach((v2: any) => {
+    if (v2.authority) buttonArr.push(v2);
+  });
+});
+
+// console.log('有权限的按钮集合',buttonArr);
+
+
+function AuthButton({ children, id, ...rest }: Props) {
   // console.log({ children, ...rest });
 
-  return <Button {...rest}>{children}</Button>;
+  return buttonArr.some((v: any) => v.id === id) || id === -1 ? (
+    <Button {...rest}>{children}</Button>
+  ) : null;
 }
 
 const MemoAuthButton = React.memo(AuthButton);

+ 39 - 28
src/pages/Home/index.tsx

@@ -1,4 +1,4 @@
-import { getTokenInfo } from "@/utils/storage";
+import { getPowerInfo, getTokenInfo } from "@/utils/storage";
 import { useCallback, useEffect, useMemo, useRef, useState } from "react";
 import styles from "./index.module.scss";
 import dayjs from "dayjs";
@@ -14,23 +14,42 @@ import { getHomeNumsAPI } from "@/store/action/login";
 
 echarts.use([TooltipComponent, GridComponent, BarChart, CanvasRenderer]);
 
+// 顶部右侧数据
+const tabList = [
+  { id: 1, done: false, path: "/object", name: "藏品登记" },
+  { id: 2, done: false, path: "/object/2", name: "藏品总账" },
+  { id: 3, done: false, path: "/object/3", name: "入库管理" },
+  { id: 4, done: false, path: "/object/4", name: "出库管理" },
+  { id: 5, done: false, path: "/object/6", name: "藏品注销" },
+];
+
+// 右下方的数据
+const tempDone = [
+  { id: 1, done: false, path: "/object", num: 0, name: "藏品登记" },
+  { id: 2, done: false, path: "/object/3", num: 0, name: "入库管理" },
+  { id: 3, done: false, path: "/object/4", num: 0, name: "出库管理" },
+  { id: 4, done: false, path: "/object/5", num: 0, name: "藏品修改" },
+  { id: 5, done: false, path: "/object/6", num: 0, name: "藏品注销" },
+];
+
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+
+powerInfo.forEach((v: any) => {
+  if (v.id === 100) tabList[0].done = tempDone[0].done = true;
+  if (v.id === 200) tabList[1].done = true;
+  if (v.id === 300) tabList[2].done = tempDone[1].done = true;
+  if (v.id === 400) tabList[3].done = tempDone[2].done = true;
+  if (v.id === 500) tempDone[3].done = true;
+  if (v.id === 600) tabList[4].done = tempDone[4].done = true;
+});
+
 export default function Home() {
   // 实时时间
   const [nowTime, setNowTime] = useState(
     dayjs(Date.now()).format("YYYY年MM月DD HH:mm")
   );
 
-  // 头部右侧
-  const tabList = useMemo(() => {
-    return [
-      { id: 1, path: "/object", name: "藏品登记" },
-      { id: 2, path: "/object/2", name: "藏品总账" },
-      { id: 3, path: "/object/3", name: "入库管理" },
-      { id: 4, path: "/object/4", name: "出库管理" },
-      { id: 5, path: "/object/6", name: "藏品注销" },
-    ];
-  }, []);
-
   // 点击头部右侧和下面右侧
   const toPageFu = useCallback((path: string, flag: boolean) => {
     if (flag) return message.warning("没有该模块权限!");
@@ -149,16 +168,6 @@ export default function Home() {
     option && myChart.setOption(option);
   }, []);
 
-  const tempDone = useMemo(() => {
-    return [
-      { id: 1, path: "/object", num: 0, name: "藏品登记" },
-      { id: 2, path: "/object/3", num: 0, name: "入库管理" },
-      { id: 3, path: "/object/4", num: 0, name: "出库管理" },
-      { id: 4, path: "/object/5", num: 0, name: "藏品修改" },
-      { id: 5, path: "/object/6", num: 0, name: "藏品注销" },
-    ];
-  }, []);
-
   // 代办提醒
   const [doneList, setDoneList] = useState(tempDone);
 
@@ -173,7 +182,7 @@ export default function Home() {
       else if (v.groupKey === "cancel") data[4].num = v.count;
     });
     setDoneList(data);
-  }, [tempDone]);
+  }, []);
 
   useEffect(() => {
     echartsFu();
@@ -198,8 +207,8 @@ export default function Home() {
           <div className="titleR">
             {tabList.map((v, i) => (
               <div
-                onClick={() => toPageFu(v.path, i === 1)}
-                className={classNames("row", i === 1 ? "noAuth" : "")}
+                onClick={() => toPageFu(v.path, !v.done)}
+                className={classNames("row", !v.done ? "noAuth" : "")}
                 key={v.id}
               >
                 <div className={`bac${v.id}`}></div>
@@ -213,7 +222,9 @@ export default function Home() {
           <div className="flooBoxL">
             <div className="flooTit">
               <div>藏馆统计</div>
-              <Button>查看更多</Button>
+              <Button onClick={() => history.push("/stores/2")}>
+                查看更多
+              </Button>
             </div>
             {/* 图表 */}
             <div className="chartBox">
@@ -228,11 +239,11 @@ export default function Home() {
             <div className="doneBox">
               {doneList.map((v, i) => (
                 <div
-                  onClick={() => toPageFu(v.path, i === 1)}
+                  onClick={() => toPageFu(v.path, !v.done)}
                   className={classNames(
                     "doneRow",
                     i >= 4 ? "noneRow" : "",
-                    i === 1 ? "noAuth" : ""
+                    !v.done ? "noAuth" : ""
                   )}
                   key={v.id}
                 >

+ 31 - 3
src/pages/Layout/index.tsx

@@ -1,4 +1,9 @@
-import { getTokenInfo, removeTokenInfo } from "@/utils/storage";
+import {
+  getPowerInfo,
+  getTokenInfo,
+  removePowerInfo,
+  removeTokenInfo,
+} from "@/utils/storage";
 import styles from "./index.module.scss";
 import classNames from "classnames";
 import { useEffect, useMemo, useRef, useState } from "react";
@@ -15,21 +20,24 @@ import { useDispatch } from "react-redux";
 
 const NotFound = React.lazy(() => import("../../components/NotFound"));
 
-const tabList = [
+const tabListTemp = [
   {
     id: 1,
+    done: true,
     Com: React.lazy(() => import("../Home")),
     path: "/",
     name: "首页",
   },
   {
     id: 2,
+    done: false,
     Com: React.lazy(() => import("../Object")),
     path: "/object",
     name: "馆藏管理",
   },
   {
     id: 3,
+    done: true,
     Com: React.lazy(() => import("../Stores")),
     path: "/stores",
     name: "库房管理",
@@ -37,13 +45,31 @@ const tabList = [
 ];
 const temp = getTokenInfo().user.isAdmin;
 if (temp === 1)
-  tabList.push({
+  tabListTemp.push({
     id: 4,
+    done: true,
     Com: React.lazy(() => import("../System")),
     path: "/system",
     name: "系统管理",
   });
 
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+powerInfo.forEach((v: any) => {
+  if (
+    v.id === 100 ||
+    v.id === 200 ||
+    v.id === 300 ||
+    v.id === 400 ||
+    v.id === 500 ||
+    v.id === 600
+  ) {
+    tabListTemp[1].done = true;
+  }
+});
+
+const tabList = tabListTemp.filter((v) => v.done);
+
 function Layout() {
   const location = useLocation();
   const [path, setPath] = useState("");
@@ -95,7 +121,9 @@ function Layout() {
   // 点击退出登录
   const loginExit = () => {
     removeTokenInfo();
+    removePowerInfo();
     history.push("/login");
+    
   };
 
   const dispatch = useDispatch();

+ 7 - 2
src/pages/Login/index.tsx

@@ -5,8 +5,8 @@ import { UserOutlined, LockOutlined } from "@ant-design/icons";
 import { useState } from "react";
 import { Base64 } from "js-base64";
 import encodeStr from "@/utils/pass";
-import { userLoginAPI } from "@/store/action/login";
-import { setTokenInfo } from "@/utils/storage";
+import { getPowerInfoAPI, userLoginAPI } from "@/store/action/login";
+import { setPowerInfo, setTokenInfo } from "@/utils/storage";
 import history from "@/utils/history";
 
 export default function Login() {
@@ -29,8 +29,13 @@ export default function Login() {
     const res: any = await userLoginAPI(obj);
     if (res.code === 0) {
       message.success("登录成功");
+      // 用户信息存到本地
       setTokenInfo(res.data);
       history.push("/");
+      const res2: any = await getPowerInfoAPI();
+      const tempArr = res2.data.filter((v: any) => v.authority);
+      // 权限信息存到本地
+      setPowerInfo(tempArr);
     }
   };
 

+ 163 - 106
src/pages/Object/index.tsx

@@ -1,11 +1,12 @@
 import styles from "./index.module.scss";
 import LeftBar from "@/components/LeftBar";
-import React, { useEffect, useMemo } from "react";
+import React from "react";
 import SpinLoding from "@/components/SpinLoding";
 import { Route, Switch } from "react-router-dom";
 import AuthRoute from "@/components/AuthRoute";
 import NotFound from "@/components/NotFound";
 import history from "@/utils/history";
+import { getPowerInfo } from "@/utils/storage";
 
 const LookObject1 = React.lazy(
   () => import("../ObjectSon/Object1/LookObject1")
@@ -27,114 +28,170 @@ const LookObject6 = React.lazy(
   () => import("../ObjectSon/Object6/LookObject6")
 );
 
-export default function Object() {
-  const data = useMemo(() => {
-    return [
-      {
-        id: 1,
-        name: "藏品登记",
-        Com: React.lazy(() => import("../ObjectSon/Object1")),
-        path: "/object",
-      },
-      {
-        id: 2,
-        name: "藏品总账",
-        Com: React.lazy(() => import("../ObjectSon/Object2")),
-        path: "/object/2",
-      },
-      {
-        id: 3,
-        name: "入库管理",
-        Com: React.lazy(() => import("../ObjectSon/Object3")),
-        path: "/object/3",
-      },
-      {
-        id: 4,
-        name: "出库管理",
-        Com: React.lazy(() => import("../ObjectSon/Object4")),
-        path: "/object/4",
-      },
-      {
-        id: 5,
-        name: "藏品修改",
-        Com: React.lazy(() => import("../ObjectSon/Object5")),
-        path: "/object/5",
-      },
-      {
-        id: 6,
-        name: "藏品注销",
-        Com: React.lazy(() => import("../ObjectSon/Object6")),
-        path: "/object/6",
-      },
-    ];
-  }, []);
+const dataTemp = [
+  {
+    id: 1,
+    name: "藏品登记",
+    done: false,
+    Com: React.lazy(() => import("../ObjectSon/Object1")),
+    path: "/object",
+  },
+  {
+    id: 2,
+    done: false,
+    name: "藏品总账",
+    Com: React.lazy(() => import("../ObjectSon/Object2")),
+    path: "/object/2",
+  },
+  {
+    id: 3,
+    done: false,
+    name: "入库管理",
+    Com: React.lazy(() => import("../ObjectSon/Object3")),
+    path: "/object/3",
+  },
+  {
+    id: 4,
+    done: false,
+    name: "出库管理",
+    Com: React.lazy(() => import("../ObjectSon/Object4")),
+    path: "/object/4",
+  },
+  {
+    id: 5,
+    done: false,
+    name: "藏品修改",
+    Com: React.lazy(() => import("../ObjectSon/Object5")),
+    path: "/object/5",
+  },
+  {
+    id: 6,
+    done: false,
+    name: "藏品注销",
+    Com: React.lazy(() => import("../ObjectSon/Object6")),
+    path: "/object/6",
+  },
+];
+
+const dataInTemp = [
+  {
+    id: 1001,
+    done: false,
+    name: "藏品登记新增",
+    Com: React.lazy(() => import("../ObjectSon/Object1/AddObject1")),
+    path: "/object/1/add",
+  },
+  {
+    id: 1002,
+    done: false,
+    name: "藏品登记审核",
+    Com: React.lazy(() => import("../ObjectSon/Object1/AuditObject1")),
+    path: "/object/1/audit",
+  },
+  {
+    id: 3001,
+    done: false,
+    name: "入库管理新增",
+    Com: React.lazy(() => import("../ObjectSon/Object3/AddObject3")),
+    path: "/object/3/add",
+  },
+  {
+    id: 3002,
+    done: false,
+    name: "入库管理审核",
+    Com: React.lazy(() => import("../ObjectSon/Object3/AuditObject3")),
+    path: "/object/3/audit",
+  },
+  {
+    id: 4001,
+    done: false,
+    name: "出库管理新增",
+    Com: React.lazy(() => import("../ObjectSon/Object4/AddObject4")),
+    path: "/object/4/add",
+  },
+  {
+    id: 4002,
+    done: false,
+    name: "出库管理审核",
+    Com: React.lazy(() => import("../ObjectSon/Object4/AuditObject4")),
+    path: "/object/4/audit",
+  },
+  {
+    id: 5001,
+    done: false,
+    name: "出库管理审核",
+    Com: React.lazy(() => import("../ObjectSon/Object5/AuditObject5")),
+    path: "/object/5/audit",
+  },
+  {
+    id: 6001,
+    done: false,
+    name: "藏品注销新增",
+    Com: React.lazy(() => import("../ObjectSon/Object6/AddObject6")),
+    path: "/object/6/add",
+  },
+  {
+    id: 6002,
+    done: false,
+    name: "藏品注销审核",
+    Com: React.lazy(() => import("../ObjectSon/Object6/AuditObject6")),
+    path: "/object/6/audit",
+  },
+];
+
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+
+console.log('ppppppppppp',powerInfo);
 
-  const dataIn = useMemo(() => {
-    return [
-      {
-        id: 1001,
-        name: "藏品登记新增",
-        Com: React.lazy(() => import("../ObjectSon/Object1/AddObject1")),
-        path: "/object/1/add",
-      },
-      {
-        id: 1002,
-        name: "藏品登记审核",
-        Com: React.lazy(() => import("../ObjectSon/Object1/AuditObject1")),
-        path: "/object/1/audit",
-      },
-      {
-        id: 3001,
-        name: "入库管理新增",
-        Com: React.lazy(() => import("../ObjectSon/Object3/AddObject3")),
-        path: "/object/3/add",
-      },
-      {
-        id: 3002,
-        name: "入库管理审核",
-        Com: React.lazy(() => import("../ObjectSon/Object3/AuditObject3")),
-        path: "/object/3/audit",
-      },
-      {
-        id: 4001,
-        name: "出库管理新增",
-        Com: React.lazy(() => import("../ObjectSon/Object4/AddObject4")),
-        path: "/object/4/add",
-      },
-      {
-        id: 4002,
-        name: "出库管理审核",
-        Com: React.lazy(() => import("../ObjectSon/Object4/AuditObject4")),
-        path: "/object/4/audit",
-      },
-      {
-        id: 5001,
-        name: "出库管理审核",
-        Com: React.lazy(() => import("../ObjectSon/Object5/AuditObject5")),
-        path: "/object/5/audit",
-      },
-      {
-        id: 6001,
-        name: "藏品注销新增",
-        Com: React.lazy(() => import("../ObjectSon/Object6/AddObject6")),
-        path: "/object/6/add",
-      },
-      {
-        id: 6002,
-        name: "藏品注销审核",
-        Com: React.lazy(() => import("../ObjectSon/Object6/AuditObject6")),
-        path: "/object/6/audit",
-      },
-    ];
-  }, []);
 
-  // 没有藏品登记页面的权限 跳到有权限的页面
-  useEffect(() => {
-    if (data[0].id !== 1) {
-      history.replace(data[0].path);
-    }
-  }, [data]);
+powerInfo.forEach((v: any) => {
+  if (v.id === 100) {
+    dataTemp[0].done = true;
+    v.children.forEach((v2: any) => {
+      if (v2.id === 102 && v2.authority) dataInTemp[0].done = true;
+      if (v2.id === 105 && v2.authority) dataInTemp[1].done = true;
+    });
+  }
+  if (v.id === 200) dataTemp[1].done = true;
+  if (v.id === 300) {
+    dataTemp[2].done = true;
+    v.children.forEach((v2: any) => {
+      if (v2.id === 302 && v2.authority) dataInTemp[2].done = true;
+      if (v2.id === 305 && v2.authority) dataInTemp[3].done = true;
+    });
+  }
+  if (v.id === 400) {
+    dataTemp[3].done = true;
+    v.children.forEach((v2: any) => {
+      if (v2.id === 402 && v2.authority) dataInTemp[4].done = true;
+      if (v2.id === 405 && v2.authority) dataInTemp[5].done = true;
+    });
+  }
+  if (v.id === 500) {
+    v.children.forEach((v2: any) => {
+      if (v2.id === 505 && v2.authority) dataInTemp[6].done = true;
+    });
+    dataTemp[4].done = true;
+  }
+  if (v.id === 600) {
+    dataTemp[5].done = true;
+    v.children.forEach((v2: any) => {
+      if (v2.id === 602 && v2.authority) dataInTemp[7].done = true;
+      if (v2.id === 605 && v2.authority) dataInTemp[8].done = true;
+    });
+  }
+});
+const data = dataTemp.filter((v) => v.done);
 
+const dataIn = dataInTemp.filter((v) => v.done);
+
+// 没有藏品登记页面的权限 跳到有权限的页面
+if (data[0].id !== 1) {
+  history.replace(data[0].path);
+}
+
+export default function Object() {
   return (
     <div className={styles.Object}>
       <div className="leftBar">

+ 1 - 0
src/pages/ObjectSon/Object1/LookObject1/index.tsx

@@ -104,6 +104,7 @@ function LookObject1() {
         <div className="backBtn">
           {info.status === 2 ? (
             <AuthButton
+              id={102}
               type="primary"
               onClick={() =>
                 history.push(

+ 4 - 3
src/pages/ObjectSon/Object1/index.tsx

@@ -204,13 +204,14 @@ export default function Object1() {
             </Button>
 
             {item.status === 0 || item.status === 2 ? (
-              <AuthButton type="text" danger onClick={() => addObject(item.id)}>
+              <AuthButton id={102} type="text" danger onClick={() => addObject(item.id)}>
                 编辑
               </AuthButton>
             ) : null}
 
             {item.status === 1 ? (
               <AuthButton
+                id={105}
                 onClick={() =>
                   history.push(
                     `/object/1/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
@@ -230,7 +231,7 @@ export default function Object1() {
                 cancelText="取消"
                 onConfirm={() => delOne(item.id)}
               >
-                <AuthButton type="text" danger>
+                <AuthButton id={103} type="text" danger>
                   删除
                 </AuthButton>
               </Popconfirm>
@@ -303,7 +304,7 @@ export default function Object1() {
               <RangePicker onChange={timeChange} />
             </div>
             <div className="row">
-              <AuthButton type="primary" onClick={() => addObject()}>
+              <AuthButton id={102} type="primary" onClick={() => addObject()}>
                 新增
               </AuthButton>
             </div>

+ 5 - 2
src/pages/ObjectSon/Object2/LookObject2/index.tsx

@@ -22,6 +22,7 @@ import classNames from "classnames";
 import { editObj2StoresAPI, getObj2InfoInAPI } from "@/store/action/object2";
 import { storageStatusObj } from "@/utils/dataChange";
 import { getStores1ListAPI } from "@/store/action/stores1";
+
 function LookObject2() {
   const dispatch = useDispatch();
   // 获取地址栏参数
@@ -259,6 +260,7 @@ function LookObject2() {
               </div>
               <div>
                 <AuthButton
+                  id={202}
                   disabled={info.tempEdit !== 0}
                   size="small"
                   type="primary"
@@ -270,6 +272,7 @@ function LookObject2() {
                 {info.storageStatus !== "0" && info.storageStatus !== "temp" ? (
                   <>
                     <AuthButton
+                      id={205}
                       disabled={info.tempMove !== 0}
                       size="small"
                       type="primary"
@@ -280,9 +283,9 @@ function LookObject2() {
                     &emsp;
                   </>
                 ) : null}
-                <AuthButton size="small" onClick={() => titCutFu("3")}>
+                <Button size="small" onClick={() => titCutFu("3")}>
                   操作记录
-                </AuthButton>
+                </Button>
               </div>
             </div>
             <div className="topInfoBoxRTxt">

+ 19 - 1
src/pages/ObjectSon/Object2/LookObject2/table.tsx

@@ -2,6 +2,7 @@ import AuthButton from "@/components/AuthButton";
 import { RootState } from "@/store";
 import { getObj2LogListAPI } from "@/store/action/object2";
 import { logTypeObj, logTypeOpenObj } from "@/utils/dataChange";
+import { getPowerInfo } from "@/utils/storage";
 import { Table } from "antd";
 import React, {
   useCallback,
@@ -15,6 +16,10 @@ import { useDispatch, useSelector } from "react-redux";
 type Props = {
   id: number;
 };
+
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+
 function LookObject2Log({ id }: Props) {
   const dispatch = useDispatch();
 
@@ -69,15 +74,28 @@ function LookObject2Log({ id }: Props) {
       {
         title: "操作",
         render: (item: any) => {
+          let falg = false;
+          powerInfo.forEach((v: any) => {
+            if (
+              (item.type === "in" && v.id === 300) ||
+              (item.type === "out" && v.id === 400) ||
+              (item.type === "move" && v.id === 800) ||
+              (item.type === "edit" && v.id === 500)
+            )
+              falg = true;
+          });
           // 暂时不处理权限问题,后面在完善
-          return (
+          return falg ? (
             <AuthButton
+              id={-1}
               type="text"
               danger
               onClick={() => openURL(logTypeOpenObj[item.type] + item.id)}
             >
               查看
             </AuthButton>
+          ) : (
+            "-"
           );
         },
       },

+ 1 - 0
src/pages/ObjectSon/Object3/LookObject3/index.tsx

@@ -169,6 +169,7 @@ function LookObject3() {
         <div className="backBtn">
           {info.status === 2 ? (
             <AuthButton
+              id={302}
               type="primary"
               onClick={() =>
                 history.push(

+ 9 - 3
src/pages/ObjectSon/Object3/index.tsx

@@ -187,13 +187,19 @@ export default function Object3() {
             </Button>
 
             {item.status === 0 || item.status === 2 ? (
-              <AuthButton type="text" danger onClick={() => addObject(item.id)}>
+              <AuthButton
+                id={302}
+                type="text"
+                danger
+                onClick={() => addObject(item.id)}
+              >
                 编辑
               </AuthButton>
             ) : null}
 
             {item.status === 1 ? (
               <AuthButton
+                id={305}
                 onClick={() =>
                   history.push(
                     `/object/3/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
@@ -213,7 +219,7 @@ export default function Object3() {
                 cancelText="取消"
                 onConfirm={() => delOne(item.id)}
               >
-                <AuthButton type="text" danger>
+                <AuthButton id={303} type="text" danger>
                   删除
                 </AuthButton>
               </Popconfirm>
@@ -267,7 +273,7 @@ export default function Object3() {
               <RangePicker onChange={timeChange} />
             </div>
             <div className="row">
-              <AuthButton type="primary" onClick={() => addObject()}>
+              <AuthButton id={302} type="primary" onClick={() => addObject()}>
                 申请入库
               </AuthButton>
             </div>

+ 2 - 1
src/pages/ObjectSon/Object4/LookObject4/index.tsx

@@ -206,7 +206,7 @@ function LookObject4() {
                 cancelText="取消"
                 onConfirm={returnGoodsFu}
               >
-                <AuthButton disabled={tableSelectList.length === 0}>
+                <AuthButton id={406} disabled={tableSelectList.length === 0}>
                   归还
                 </AuthButton>
               </Popconfirm>
@@ -231,6 +231,7 @@ function LookObject4() {
         <div className="backBtn">
           {info.status === 2 ? (
             <AuthButton
+              id={402}
               type="primary"
               onClick={() =>
                 history.push(

+ 9 - 3
src/pages/ObjectSon/Object4/index.tsx

@@ -187,13 +187,19 @@ export default function Object4() {
             </Button>
 
             {item.status === 0 || item.status === 2 ? (
-              <AuthButton type="text" danger onClick={() => addObject(item.id)}>
+              <AuthButton
+                id={402}
+                type="text"
+                danger
+                onClick={() => addObject(item.id)}
+              >
                 编辑
               </AuthButton>
             ) : null}
 
             {item.status === 1 ? (
               <AuthButton
+                id={405}
                 onClick={() =>
                   history.push(
                     `/object/4/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
@@ -213,7 +219,7 @@ export default function Object4() {
                 cancelText="取消"
                 onConfirm={() => delOne(item.id)}
               >
-                <AuthButton type="text" danger>
+                <AuthButton id={403} type="text" danger>
                   删除
                 </AuthButton>
               </Popconfirm>
@@ -267,7 +273,7 @@ export default function Object4() {
               <RangePicker onChange={timeChange} />
             </div>
             <div className="row">
-              <AuthButton type="primary" onClick={() => addObject()}>
+              <AuthButton id={402} type="primary" onClick={() => addObject()}>
                 申请出库
               </AuthButton>
             </div>

+ 2 - 1
src/pages/ObjectSon/Object5/index.tsx

@@ -190,6 +190,7 @@ export default function Object5() {
 
             {item.status === 1 ? (
               <AuthButton
+                id={505}
                 onClick={() =>
                   history.push(
                     `/object/5/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
@@ -209,7 +210,7 @@ export default function Object5() {
                 cancelText="取消"
                 onConfirm={() => delOne(item.id)}
               >
-                <AuthButton type="text" danger>
+                <AuthButton id={503} type="text" danger>
                   删除
                 </AuthButton>
               </Popconfirm>

+ 1 - 0
src/pages/ObjectSon/Object6/LookObject6/index.tsx

@@ -165,6 +165,7 @@ function LookObject6() {
         <div className="backBtn">
           {info.status === 2 ? (
             <AuthButton
+              id={602}
               type="primary"
               onClick={() =>
                 history.push(

+ 9 - 3
src/pages/ObjectSon/Object6/index.tsx

@@ -187,13 +187,19 @@ export default function Object6() {
             </Button>
 
             {item.status === 0 || item.status === 2 ? (
-              <AuthButton type="text" danger onClick={() => addObject(item.id)}>
+              <AuthButton
+                id={602}
+                type="text"
+                danger
+                onClick={() => addObject(item.id)}
+              >
                 编辑
               </AuthButton>
             ) : null}
 
             {item.status === 1 ? (
               <AuthButton
+                id={605}
                 onClick={() =>
                   history.push(
                     `/object/6/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
@@ -213,7 +219,7 @@ export default function Object6() {
                 cancelText="取消"
                 onConfirm={() => delOne(item.id)}
               >
-                <AuthButton type="text" danger>
+                <AuthButton id={603} type="text" danger>
                   删除
                 </AuthButton>
               </Popconfirm>
@@ -267,7 +273,7 @@ export default function Object6() {
               <RangePicker onChange={timeChange} />
             </div>
             <div className="row">
-              <AuthButton type="primary" onClick={() => addObject()}>
+              <AuthButton id={602} type="primary" onClick={() => addObject()}>
                 申请注销
               </AuthButton>
             </div>

+ 53 - 41
src/pages/Stores/index.tsx

@@ -3,8 +3,8 @@ import LeftBar from "@/components/LeftBar";
 import NotFound from "@/components/NotFound";
 import SpinLoding from "@/components/SpinLoding";
 import history from "@/utils/history";
-import React, { useEffect } from "react";
-import { useMemo } from "react";
+import { getPowerInfo } from "@/utils/storage";
+import React from "react";
 import { Route, Switch } from "react-router-dom";
 import styles from "./index.module.scss";
 
@@ -12,48 +12,60 @@ const LookStores3 = React.lazy(
   () => import("../StoresSon/Stores3/LookStores3")
 );
 
-export default function Stores() {
-  const data = useMemo(() => {
-    return [
-      {
-        id: 1,
-        name: "库房设置",
-        Com: React.lazy(() => import("../StoresSon/Stores1")),
-        path: "/stores",
-      },
-      {
-        id: 2,
-        name: "统计报表",
-        Com: React.lazy(() => import("../StoresSon/Stores2")),
-        path: "/stores/2",
-      },
-      {
-        id: 3,
-        name: "藏品移库",
-        Com: React.lazy(() => import("../StoresSon/Stores3")),
-        path: "/stores/3",
-      },
-    ];
-  }, []);
+const dataTemp = [
+  {
+    id: 1,
+    done: false,
+    name: "库房设置",
+    Com: React.lazy(() => import("../StoresSon/Stores1")),
+    path: "/stores",
+  },
+  {
+    id: 2,
+    done: true,
+    name: "统计报表",
+    Com: React.lazy(() => import("../StoresSon/Stores2")),
+    path: "/stores/2",
+  },
+  {
+    id: 3,
+    done: false,
+    name: "藏品移库",
+    Com: React.lazy(() => import("../StoresSon/Stores3")),
+    path: "/stores/3",
+  },
+];
+
+const dataInTemp = [
+  {
+    id: 1001,
+    done: false,
+    name: "藏品移库审核",
+    Com: React.lazy(() => import("../StoresSon/Stores3/AuditStores3")),
+    path: "/stores/3/audit",
+  },
+];
 
-  const dataIn = useMemo(() => {
-    return [
-      {
-        id: 1001,
-        name: "藏品移库审核",
-        Com: React.lazy(() => import("../StoresSon/Stores3/AuditStores3")),
-        path: "/stores/3/audit",
-      },
-    ];
-  }, []);
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+powerInfo.forEach((v: any) => {
+  if (v.id === 700) dataTemp[0].done = true;
+  if (v.id === 800) {
+    v.children.forEach((v2: any) => {
+      if (v2.id === 805 && v2.authority) dataInTemp[0].done = true;
+    });
+    dataTemp[2].done = true;
+  }
+});
 
-  // 没有库房设置页面的权限 跳到有权限的页面
-  useEffect(() => {
-    if (data[0].id !== 1) {
-      history.replace(data[0].path);
-    }
-  }, [data]);
+const data = dataTemp.filter((v) => v.done);
+const dataIn = dataInTemp.filter((v) => v.done);
+// 没有库房设置页面的权限 跳到有权限的页面
+if (data[0].id !== 1) {
+  history.replace(data[0].path);
+}
 
+export default function Stores() {
   return (
     <div className={styles.Stores}>
       <div className="leftBar">

+ 63 - 26
src/pages/StoresSon/Stores1/index.tsx

@@ -26,6 +26,21 @@ import {
 } from "@/store/action/stores1";
 import { useDispatch, useSelector } from "react-redux";
 import { RootState } from "@/store";
+import AuthButton from "@/components/AuthButton";
+import { getPowerInfo } from "@/utils/storage";
+
+// 根据权限来判断
+const powerInfo = getPowerInfo();
+const powerInfoTemp = powerInfo.filter((v: any) => v.id === 700)[0];
+let powerInfoRes = [false, false];
+if (powerInfoTemp) {
+  powerInfoTemp.children.forEach((v: any) => {
+    if (v.id === 702 && v.authority) powerInfoRes[0] = true;
+    if (v.id === 703 && v.authority) powerInfoRes[1] = true;
+  });
+}
+
+
 function Stores1() {
   const dispatch = useDispatch();
 
@@ -153,18 +168,23 @@ function Stores1() {
         title: "操作",
         render: (item: any) => (
           <div className="storesRTitInco">
-            <EditOutlined
-              title="编辑货架"
-              onClick={() => addFu("3", item.id)}
-            />
-            &emsp;
+            {powerInfoRes[0] ? (
+              <>
+                <EditOutlined
+                  title="编辑货架"
+                  onClick={() => addFu("3", item.id)}
+                />
+                &emsp;
+              </>
+            ) : null}
+
             <Popconfirm
               title="确定删除吗?"
               okText="确定"
               cancelText="取消"
               onConfirm={() => delOne(item.id)}
             >
-              <DeleteOutlined title="删除货架" />
+              {powerInfoRes[1] ? <DeleteOutlined title="删除货架" /> : null}
             </Popconfirm>
           </div>
         ),
@@ -183,9 +203,9 @@ function Stores1() {
         {/* 左边的库区 */}
         <div className="storesL">
           <div className="storesLTit">
-            <Button type="primary" onClick={() => addFu("1")}>
+            <AuthButton id={702} type="primary" onClick={() => addFu("1")}>
               新建库区
-            </Button>
+            </AuthButton>
             &emsp;
             <Popconfirm
               title="确定删除吗?"
@@ -193,7 +213,7 @@ function Stores1() {
               cancelText="取消"
               onConfirm={() => delOne(infoList1[acind1].id)}
             >
-              <Button>删除</Button>
+              <AuthButton id={703}>删除</AuthButton>
             </Popconfirm>
           </div>
           <div className="storesLBox">
@@ -219,15 +239,22 @@ function Stores1() {
                       {v.name}
                     </div>
                     <div className="inco2">
-                      <PlusOutlined
-                        title="新增库房"
-                        onClick={() => addFu("2")}
-                      />
-                      &emsp;
-                      <EditOutlined
-                        title="编辑库区"
-                        onClick={() => addFu("1", v.id)}
-                      />
+                      {powerInfoRes[0] ? (
+                        <>
+                          <PlusOutlined
+                            title="新增库房"
+                            onClick={() => addFu("2")}
+                          />
+                          &emsp;
+                        </>
+                      ) : null}
+
+                      {powerInfoRes[1] ? (
+                        <EditOutlined
+                          title="编辑库区"
+                          onClick={() => addFu("1", v.id)}
+                        />
+                      ) : null}
                     </div>
                   </div>
                   {infoList2 && infoList2.length && i === acind1 ? (
@@ -266,20 +293,30 @@ function Stores1() {
                   仓库编号:{infoList2[acind2].num}
                 </div>
                 <div className="storesRTitInco">
-                  <PlusOutlined title="新增货架" onClick={() => addFu("3")} />
-                  &emsp;
-                  <EditOutlined
-                    title="编辑库房"
-                    onClick={() => addFu("2", infoList2[acind2].id)}
-                  />
-                  &emsp;
+                  {powerInfoRes[0] ? (
+                    <>
+                      <PlusOutlined
+                        title="新增货架"
+                        onClick={() => addFu("3")}
+                      />
+                      &emsp;
+                      <EditOutlined
+                        title="编辑库房"
+                        onClick={() => addFu("2", infoList2[acind2].id)}
+                      />
+                      &emsp;
+                    </>
+                  ) : null}
+
                   <Popconfirm
                     title="确定删除吗?"
                     okText="确定"
                     cancelText="取消"
                     onConfirm={() => delOne(infoList2[acind2].id)}
                   >
-                    <DeleteOutlined title="删除库房" />
+                    {powerInfoRes[1] ? (
+                      <DeleteOutlined title="删除库房" />
+                    ) : null}
                   </Popconfirm>
                 </div>
               </>

+ 2 - 1
src/pages/StoresSon/Stores3/index.tsx

@@ -190,6 +190,7 @@ export default function Stores3() {
 
             {item.status === 1 ? (
               <AuthButton
+                id={805}
                 onClick={() =>
                   history.push(
                     `/stores/3/audit?k=${pageNumRef.current}&d=${statusRef.current}&id=${item.id}`
@@ -209,7 +210,7 @@ export default function Stores3() {
                 cancelText="取消"
                 onConfirm={() => delOne(item.id)}
               >
-                <AuthButton type="text" danger>
+                <AuthButton id={803} type="text" danger>
                   删除
                 </AuthButton>
               </Popconfirm>

+ 20 - 2
src/pages/SystemSon/System1/index.tsx

@@ -4,6 +4,7 @@ import {
   delUserAPI,
   getUserListAPI,
   userEditStatusAPI,
+  userResetPassAPI,
 } from "@/store/action/system";
 import { Button, Input, message, Popconfirm, Switch, Table } from "antd";
 import React, {
@@ -64,6 +65,12 @@ function System1() {
     [dispatch, tableSelect]
   );
 
+  // 点击重置按钮
+  const resetPassFu = useCallback(async (id: number) => {
+    const res: any = await userResetPassAPI(id);
+    if (res.code === 0) message.success("重置成功!");
+  }, []);
+
   // ---------关于表格
 
   // 切换表格中的启用停用状态
@@ -100,7 +107,7 @@ function System1() {
       },
       {
         title: "角色",
-        dataIndex: "creatorName",
+        dataIndex: "roleName",
       },
       {
         title: "真实姓名",
@@ -126,6 +133,7 @@ function System1() {
 
       {
         title: "操作",
+        width: 240,
         render: (item: any) => (
           <>
             {item.isAdmin === 1 ? (
@@ -145,13 +153,23 @@ function System1() {
                     删除
                   </Button>
                 </Popconfirm>
+                <Popconfirm
+                  title="确定重置吗?"
+                  okText="确定"
+                  cancelText="取消"
+                  onConfirm={() => resetPassFu(item.id)}
+                >
+                  <Button type="text" danger>
+                    重置密码
+                  </Button>
+                </Popconfirm>
               </>
             )}
           </>
         ),
       },
     ];
-  }, [delOne, isEnabledClickFu]);
+  }, [delOne, isEnabledClickFu, resetPassFu]);
 
   // 关于弹窗
   const [open, setOpen] = useState(false);

+ 7 - 0
src/store/action/login.ts

@@ -39,3 +39,10 @@ export const getSelectAllAPI = () => {
 export const getHomeNumsAPI = () => {
   return http.get("cms/report/remind");
 };
+
+/**
+ * 获取用户权限
+ */
+export const getPowerInfoAPI = () => {
+  return http.get("sys/resource/getTreePermissions");
+};

+ 8 - 1
src/store/action/system.ts

@@ -110,8 +110,15 @@ export const delUserAPI = (ids: number) => {
 };
 
 /**
+ * 通过id重置用户密码
+ */
+export const userResetPassAPI = (id: number) => {
+  return http.get(`sys/user/resetPass/${id}`);
+};
+
+/**
  * 用户的启用和停用
  */
 export const userEditStatusAPI = (id: any, isDisable: any) => {
   return http.get(`sys/user/editStatus/${id}/${isDisable}`);
-};
+};

+ 1 - 1
src/utils/dataChange.ts

@@ -52,7 +52,7 @@ export const logTypeObj = {
 export const logTypeOpenObj = {
   in: "#/object/3/look?k=1&d=null&id=", //入库管理的查看
   out: "#/object/4/look?k=1&d=null&id=", //出库管理的查看
-  move: "",//藏品移库的查看
+  move: "#/stores/3/look?k=1&d=null&id=",//藏品移库的查看
   edit: "#/object/5/look?k=1&d=null&id=",//藏品修改的查看
 } as any;
 

+ 32 - 0
src/utils/storage.ts

@@ -1,5 +1,8 @@
 // ------------------------------------token的本地存储------------------------------------
 
+import { message } from "antd";
+import history from "./history";
+
 // 用户信息的本地缓存键名(包括token)
 const USER_KEY = "LSDFGC_USER_INFO";
 
@@ -32,4 +35,33 @@ export const hasToken = (): boolean => {
   return Boolean(getTokenInfo().token);
 };
 
+// ------------------------------------权限的本地存储------------------------------------
+
+// 用户信息的本地缓存键名(包括token)
+const POWER_KEY = "LSDFGC_POWER_INFO";
+
+/**
+ * 存入权限信息
+ */
+export const setPowerInfo = (info: any) => {
+  localStorage.setItem(POWER_KEY, JSON.stringify(info));
+};
+
+/**
+ * 取权限信息
+ */
+export const getPowerInfo = (): any => {
+  const data = localStorage.getItem(POWER_KEY);
+  if (data) return JSON.parse(data);
+  else {
+    message.warning("权限信息丢失!");
+    history.push("/login");
+  }
+};
 
+/**
+ * 删除本地缓存中的权限信息
+ */
+export const removePowerInfo = (): void => {
+  localStorage.removeItem(POWER_KEY);
+};