From 89b6307e2dc2133fc77ffe2d64b2f48a05157cd2 Mon Sep 17 00:00:00 2001 From: none Date: Thu, 23 Mar 2023 17:29:43 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 21 ------- src/compenents/header/index.tsx | 10 ++-- src/compenents/permission-button/index.tsx | 16 ++--- src/main.tsx | 2 +- src/pages/department/index.tsx | 12 ++-- src/pages/init/index.tsx | 19 +++++- src/pages/login/index.tsx | 10 +--- .../resource/resource-category/index.tsx | 12 ++-- src/routes/index.tsx | 28 ++++++++- src/store/hooks.ts | 7 --- src/store/index.ts | 12 ++++ src/store/store.ts | 7 --- src/store/system/systemConfigSlice.ts | 34 +++++++++++ src/store/user/loginUserSlice.ts | 42 +++++++++++++ src/store/user/userActions.ts | 59 ------------------- src/store/user/userReducer.ts | 33 ----------- 16 files changed, 163 insertions(+), 161 deletions(-) delete mode 100644 src/store/hooks.ts create mode 100644 src/store/index.ts delete mode 100644 src/store/store.ts create mode 100644 src/store/system/systemConfigSlice.ts create mode 100644 src/store/user/loginUserSlice.ts delete mode 100644 src/store/user/userActions.ts delete mode 100644 src/store/user/userReducer.ts diff --git a/src/App.tsx b/src/App.tsx index 91f8a9c..af397d5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,32 +2,11 @@ import { Suspense } from "react"; import styles from "./App.module.less"; import { useRoutes } from "react-router-dom"; import routes from "./routes"; -import { getToken } from "./utils/index"; -import { login } from "./api/index"; -import { useDispatch } from "react-redux"; -import { - IsLoginActionCreator, - SetUserActionCreator, - SetPermisssionsActionCreator, -} from "./store/user/userActions"; import LoadingPage from "./pages/loading"; function App() { const Views = () => useRoutes(routes); - const dispatch = useDispatch(); - const getUser = () => { - login.getUser().then((res: any) => { - const data = res.data; - dispatch(IsLoginActionCreator()); - dispatch(SetUserActionCreator(data.user)); - dispatch(SetPermisssionsActionCreator(data.permissions)); - }); - }; - if (getToken()) { - getUser(); - } - return ( }>
diff --git a/src/compenents/header/index.tsx b/src/compenents/header/index.tsx index d9b864f..8953bd2 100644 --- a/src/compenents/header/index.tsx +++ b/src/compenents/header/index.tsx @@ -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"); diff --git a/src/compenents/permission-button/index.tsx b/src/compenents/permission-button/index.tsx index 8abc1bf..97d73a1 100644 --- a/src/compenents/permission-button/index.tsx +++ b/src/compenents/permission-button/index.tsx @@ -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" && ( )} - {through() && props.type !== "link" && ( + {isThrough() && props.type !== "link" && (