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")} + />