From 7a14ff88b61edb27760a9b8e449dad1704638554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Wed, 8 Mar 2023 15:29:03 +0800 Subject: [PATCH] =?UTF-8?q?=E9=83=A8=E9=97=A8=E6=8C=89=E9=92=AE=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BA=E6=9D=83=E9=99=90=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compenents/index.ts | 3 +- .../permission-button/index.module.less | 0 src/compenents/permission-button/index.tsx | 50 +++++++++++++++++++ src/pages/department/index.tsx | 35 ++++++++----- 4 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 src/compenents/permission-button/index.module.less create mode 100644 src/compenents/permission-button/index.tsx diff --git a/src/compenents/index.ts b/src/compenents/index.ts index 6cda3f4..dfb835a 100644 --- a/src/compenents/index.ts +++ b/src/compenents/index.ts @@ -3,4 +3,5 @@ export * from "./header"; export * from "./left-menu"; export * from "./upload-image-button"; export * from "./tree-department"; -export * from "./back-bar"; \ No newline at end of file +export * from "./back-bar"; +export * from "./permission-button"; \ No newline at end of file diff --git a/src/compenents/permission-button/index.module.less b/src/compenents/permission-button/index.module.less new file mode 100644 index 0000000..e69de29 diff --git a/src/compenents/permission-button/index.tsx b/src/compenents/permission-button/index.tsx new file mode 100644 index 0000000..a293876 --- /dev/null +++ b/src/compenents/permission-button/index.tsx @@ -0,0 +1,50 @@ +import { Button } from "antd"; +import { useSelector } from "../../store/hooks"; + +interface PropInterface { + type: "link" | "text" | "primary" | "default"; + text: string; + p: string; + class: string; + icon: any; + onClick: () => void; +} + +export const PerButton = (props: PropInterface) => { + const permisssions = useSelector((state: any) => state.permisssions); + const through = () => { + if (!permisssions) { + return false; + } + return typeof permisssions[props.p] !== "undefined"; + }; + return ( + <> + {through() && props.type === "link" && ( + + )} + {through() && props.type !== "link" && ( + + )} + + ); +}; diff --git a/src/pages/department/index.tsx b/src/pages/department/index.tsx index 478caa0..569f3bd 100644 --- a/src/pages/department/index.tsx +++ b/src/pages/department/index.tsx @@ -6,6 +6,7 @@ import { PlusOutlined, ReloadOutlined } from "@ant-design/icons"; import { department } from "../../api/index"; import { dateFormat } from "../../utils/index"; import { Link, useNavigate } from "react-router-dom"; +import { PerButton } from "../../compenents"; interface Option { id: string | number; @@ -57,14 +58,14 @@ export const DepartmentPage: React.FC = () => { width: 160, render: (_, record) => ( - + /> { okText="确定" cancelText="取消" > - + null} + /> ), @@ -143,9 +149,14 @@ export const DepartmentPage: React.FC = () => {
- + } + p="department-store" + onClick={() => console.log("ok")} + />