From aebbaadfacd50a0d4750b470e8efacf89f9fedfc Mon Sep 17 00:00:00 2001 From: wenhua <1084668738@qq.com> Date: Mon, 11 Dec 2023 15:26:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Login.tsx | 9 +++++++++ src/components/Authenticationbtn.tsx | 6 ++++-- src/view/home/index.tsx | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Login.tsx b/src/Login.tsx index 0ea9bab..34410fa 100644 --- a/src/Login.tsx +++ b/src/Login.tsx @@ -4,6 +4,8 @@ import './assets/styles/login.scss' import { getCaptchaApi, loginApi } from "./api/login"; import { useNavigate } from "react-router-dom"; import { setToken } from "./utils/auth"; +import { useDispatch } from "react-redux"; +import { addAuthInfo, getAuthInfo } from "./stores/auth"; type Login = { uuid?: string, @@ -16,8 +18,14 @@ export default function Login() { const [messageApi, contextHolder] = message.useMessage() const [uuid, setUuid] = useState('') const [captcha, setCaptcha] = useState('') + const dispatch = useDispatch() const navigate = useNavigate() + const requestAuthInfo = async () => { + const { payload } = await dispatch(getAuthInfo() as any) + dispatch(addAuthInfo(payload)) + } + const getCaptcha = async () => { try { const { code, data } = await getCaptchaApi() @@ -37,6 +45,7 @@ export default function Login() { if (code === 1000) { setToken(data) messageApi.success(msg) + requestAuthInfo() navigate('/') return } diff --git a/src/components/Authenticationbtn.tsx b/src/components/Authenticationbtn.tsx index 37e3228..c8ae6e9 100644 --- a/src/components/Authenticationbtn.tsx +++ b/src/components/Authenticationbtn.tsx @@ -1,4 +1,5 @@ import { useState } from "react"; +import { useSelector } from "react-redux"; /** * @author {温华} @@ -9,9 +10,10 @@ import { useState } from "react"; export default function Authenticationbtn({ permission, children }: any) { // 还需从缓存中获取用户权限数组 + const authInfo = useSelector((store: any) => store.auth) const [visible, setVisible] = useState(true) const allPermission: string = "*:*:*" - const authPermissions: Array = [] + const authPermissions: Array = authInfo.permissions if(permission && permission instanceof Array && permission.length > 0) { const permissiosFlag = permission const hasPermission = authPermissions.some((perm: string)=>{ @@ -20,6 +22,6 @@ export default function Authenticationbtn({ permission, children }: any) { setVisible(hasPermission) } - if(visible) return
{children}
+ if(visible) return children return null } \ No newline at end of file diff --git a/src/view/home/index.tsx b/src/view/home/index.tsx index 3099b57..d02c66a 100644 --- a/src/view/home/index.tsx +++ b/src/view/home/index.tsx @@ -1,5 +1,10 @@ +import Authenticationbtn from "@/components/Authenticationbtn"; +import { Button } from "antd"; + export default function Home() { return( -
home
+ + + ) } \ No newline at end of file