部门按钮替换为权限按钮

This commit is contained in:
禺狨
2023-03-08 15:29:03 +08:00
parent 0f2ffd306d
commit 7a14ff88b6
4 changed files with 75 additions and 13 deletions

View File

@@ -3,4 +3,5 @@ export * from "./header";
export * from "./left-menu";
export * from "./upload-image-button";
export * from "./tree-department";
export * from "./back-bar";
export * from "./back-bar";
export * from "./permission-button";

View File

@@ -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" && (
<Button
className={props.class}
type="link"
danger
icon={props.icon}
onClick={() => {
props.onClick();
}}
>
{props.text}
</Button>
)}
{through() && props.type !== "link" && (
<Button
className={props.class}
type={props.type}
icon={props.icon}
onClick={() => {
props.onClick();
}}
>
{props.text}
</Button>
)}
</>
);
};