mirror of
https://github.com/PlayEdu/backend
synced 2025-12-23 07:19:32 +08:00
重构
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import React from "react";
|
||||
import styles from "./index.module.less";
|
||||
import { Button, Dropdown, MenuProps } from "antd";
|
||||
import { useSelector } from "../../store/hooks";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { LoginOutActionCreator } from "../../store/user/userActions";
|
||||
import avatar from "../../assets/images/commen/avatar.png";
|
||||
import { logoutAction } from "../../store/user/loginUserSlice";
|
||||
|
||||
export const Header: React.FC = () => {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const user = useSelector((state: any) => state.user);
|
||||
const user = useSelector((state: any) => state.loginUser.value.user);
|
||||
|
||||
const onClick: MenuProps["onClick"] = ({ key }) => {
|
||||
if (key === "login_out") {
|
||||
dispatch(LoginOutActionCreator());
|
||||
dispatch(logoutAction());
|
||||
navigate("/login");
|
||||
} else if (key === "change_password") {
|
||||
navigate("/change-password");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Button } from "antd";
|
||||
import { useSelector } from "../../store/hooks";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface PropInterface {
|
||||
type: "link" | "text" | "primary" | "default";
|
||||
@@ -12,16 +12,18 @@ interface PropInterface {
|
||||
}
|
||||
|
||||
export const PerButton = (props: PropInterface) => {
|
||||
const permisssions = useSelector((state: any) => state.permisssions);
|
||||
const through = () => {
|
||||
if (!permisssions) {
|
||||
const permissions = useSelector(
|
||||
(state: any) => state.loginUser.value.permissions
|
||||
);
|
||||
const isThrough = () => {
|
||||
if (!permissions) {
|
||||
return false;
|
||||
}
|
||||
return typeof permisssions[props.p] !== "undefined";
|
||||
return typeof permissions[props.p] !== "undefined";
|
||||
};
|
||||
return (
|
||||
<>
|
||||
{through() && props.type === "link" && (
|
||||
{isThrough() && props.type === "link" && (
|
||||
<Button
|
||||
className={props.class}
|
||||
type="link"
|
||||
@@ -35,7 +37,7 @@ export const PerButton = (props: PropInterface) => {
|
||||
{props.text}
|
||||
</Button>
|
||||
)}
|
||||
{through() && props.type !== "link" && (
|
||||
{isThrough() && props.type !== "link" && (
|
||||
<Button
|
||||
className={props.class}
|
||||
type={props.type}
|
||||
|
||||
Reference in New Issue
Block a user