From 8bd230ba0b69c7d2b9c85c11823c3cefaa06c30c Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Tue, 20 Jun 2023 15:42:52 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=9C=A8=E9=9F=B3=E4=B9=90=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E7=BB=93=E6=9D=9F=E6=97=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=E6=9A=82?= =?UTF-8?q?=E5=81=9C=E6=8C=89=E9=92=AE=E7=8A=B6=E6=80=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 32 ++++++++++++++++++-------------- src/MainPage.js | 2 +- src/PlayerBar.js | 11 +++++++++-- src/business/recorderSlice.js | 5 ++++- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/src/App.js b/src/App.js index 0ea7514..fc1b609 100644 --- a/src/App.js +++ b/src/App.js @@ -1,3 +1,4 @@ +import { useEffect } from 'react'; import { Routes, Route, Navigate, useNavigate } from 'react-router-dom' import { useDispatch } from 'react-redux' import { setAccessToken, setUserInfo, setSelectInfo } from "./business/userSlice.js" @@ -11,21 +12,24 @@ function App() { const navigate = useNavigate(); const [cookies, setCookie, removeCookie] = useCookies(['accessToken']); - if (cookies.accessToken) { - dispatch(setAccessToken(cookies.accessToken)); - yzs.get_user_info(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => { - dispatch(setUserInfo(info)); - yzs.user_select(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => { - dispatch(setSelectInfo(info)); + useEffect(() => { + if (cookies.accessToken) { + dispatch(setAccessToken(cookies.accessToken)); + yzs.get_user_info(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => { + dispatch(setUserInfo(info)); + yzs.user_select(yzs.uniqueDeviceIdentifier(), cookies.accessToken).then(info => { + dispatch(setSelectInfo(info)); + }); + }).catch(error => { + console.log(error) + if (error.returnCode === "uc_0106") { + removeCookie("accessToken"); + navigate("/login"); + } }); - }).catch(error => { - console.log(error) - if (error.returnCode === "uc_0106") { - removeCookie("accessToken"); - navigate("/login"); - } - }); - } + } + }, []); + return (