From 9d90b5e5544f1ca8256ac754f3cade7cdf988c46 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Mon, 26 Feb 2024 11:48:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BB=E9=99=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=88=A4=E6=96=AD=EF=BC=8C=E6=B2=A1=E6=9C=89=E7=99=BB?= =?UTF-8?q?=E9=99=86=E8=B7=B3=E8=BD=AC=E9=92=89=E9=92=89=E4=BA=8C=E7=BB=B4?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/AuthStore.js | 17 ++++++++++++++++- src/views/AuthApp.jsx | 39 +++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js index fb3a903..73953b1 100644 --- a/src/stores/AuthStore.js +++ b/src/stores/AuthStore.js @@ -16,7 +16,22 @@ const useAuthStore = create((set, get) => ({ }, loadUser: () => { - return JSON.parse(window.sessionStorage.getItem('GLOBAL_SALES_LOGIN_USER')) + const sessionData = window.sessionStorage.getItem('GLOBAL_SALES_LOGIN_USER') + let userData = { + userId: 0, + username: '', + avatarUrl: '', + mobile: '', + email: '', + openId: '', + accountList: [], + permissionList: [], + } + if (sessionData !== null) { + userData = JSON.parse(sessionData) + } + + return userData }, saveUser: () => { diff --git a/src/views/AuthApp.jsx b/src/views/AuthApp.jsx index 5e0604e..c478404 100644 --- a/src/views/AuthApp.jsx +++ b/src/views/AuthApp.jsx @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { Outlet, Link, useHref, NavLink } from 'react-router-dom' +import { Outlet, Link, useHref, useNavigate, NavLink } from 'react-router-dom' import { Layout, Menu, ConfigProvider, theme, Empty, Row, Col, Avatar, Dropdown, Space, Typography, App as AntApp } from 'antd' import { DownOutlined } from '@ant-design/icons' import ErrorBoundary from '@/components/ErrorBoundary' @@ -19,38 +19,45 @@ const { Title } = Typography function AuthApp() { + const navigate = useNavigate() + const { colorPrimary, borderRadius } = useThemeContext() - // const { loginUser, permissionList } = useAuthContext() const { loadUser } = useAuthStore() const loginUser = loadUser() - console.info(loginUser) const href = useHref() - // 除了路由 /p...以外都需要登陆系统 - // const shouldBeLogin = isEmpty(loginUser) && (href.indexOf('/p/') == -1) - let defaultPath = 'follow' - if (href !== '/') { - const splitPath = href.split('/') - defaultPath = href - } + useEffect(() => { + // 除了路由 /p...以外都需要登陆系统 + if ((loginUser.userId === 0) && (href.indexOf('/p/') == -1)) { + navigate('/p/dingding/qrcode'); + } + }, [href]) - const { - token: { colorBgContainer }, - } = theme.useToken() + const userId = loginUser.userId - const { userId } = loginUser; useEffect(() => { if (userId) { useConversationStore.getState().connectWebsocket(userId); useConversationStore.getState().fetchInitialData(userId); } return () => { - useConversationStore.getState().disconnectWebsocket(); + //useConversationStore.getState().disconnectWebsocket(); } - }, [userId]); + }, [userId]) + + let defaultPath = 'follow' + + if (href !== '/') { + const splitPath = href.split('/') + defaultPath = href + } + + const { + token: { colorBgContainer }, + } = theme.useToken() return (