diff --git a/src/stores/Auth.js b/src/stores/Auth.js deleted file mode 100644 index e1b2284..0000000 --- a/src/stores/Auth.js +++ /dev/null @@ -1,17 +0,0 @@ -const KEY_USER_ID = 'KEY_USER_ID' - -class Auth { - - // {"errcode":0,"errmsg":"ok","result":{"nick":"廖一军","unionId":"j7cuUCplZe1ZiiqjQNUUmFwiEiE","avatarUrl":"https://static-legacy.dingtalk.com/media/lALPBDDrhXr716HNAoDNAoA_640_640.png","openId":"iioljiPmZ4RPoOYpkFiSn7IKAiEiE","mobile":"18777396951","stateCode":"86","email":"lyj@hainatravel.com","opisn":"383"}} - userId = '383' - username = '廖一军' - avatarUrl = 'https://static-legacy.dingtalk.com/media/lALPBDDrhXr716HNAoDNAoA_640_640.png' - stateCode = '86' - email = 'lyj@hainatravel.com' - openId = 'iioljiPmZ4RPoOYpkFiSn7IKAiEiE' - accountList = ['LYJ', 'LYJAH', 'LYJGH'] - permissionList = ['view_chat', 'send_msg'] - -} - -export default Auth diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js new file mode 100644 index 0000000..fb3a903 --- /dev/null +++ b/src/stores/AuthStore.js @@ -0,0 +1,29 @@ +import { create } from 'zustand' +import { devtools } from 'zustand/middleware' +import { fetchJSON, postJSON } from '@/utils/request' + +const useAuthStore = create((set, get) => ({ + + loginUser: { + // userId: '354', + // username: '廖一军', + // avatarUrl: 'https://static-legacy.dingtalk.com/media/lALPBDDrhXr716HNAoDNAoA_640_640.png', + // mobile: '86-18777396951', + // email: 'lyj@hainatravel.com', + // openId: 'iioljiPmZ4RPoOYpkFiSn7IKAiEiE', + // accountList: ['LYJ', 'LYJAH', 'LYJGH'], + // permissionList: ['view_chat', 'send_msg'], + }, + + loadUser: () => { + return JSON.parse(window.sessionStorage.getItem('GLOBAL_SALES_LOGIN_USER')) + }, + + saveUser: () => { + const { loginUser } = get() + window.sessionStorage.setItem('GLOBAL_SALES_LOGIN_USER', JSON.stringify(loginUser)) + }, + +})) + +export default useAuthStore diff --git a/src/views/AuthApp.jsx b/src/views/AuthApp.jsx index ad59010..5646423 100644 --- a/src/views/AuthApp.jsx +++ b/src/views/AuthApp.jsx @@ -6,7 +6,8 @@ import ErrorBoundary from '@/components/ErrorBoundary' import zhLocale from 'antd/locale/zh_CN' import { useThemeContext } from '@/stores/ThemeContext' import { useAuthContext } from '@/stores/AuthContext' -import useConversationStore from '@/stores/ConversationStore'; +import useConversationStore from '@/stores/ConversationStore' +import useAuthStore from '@/stores/AuthStore' import 'dayjs/locale/zh-cn' import 'react-chat-elements/dist/main.css' @@ -17,20 +18,26 @@ import { isEmpty } from '@/utils/commons' const { Header, Footer, Content } = Layout const { Title } = Typography -// AuthApp function AuthApp() { const { colorPrimary, borderRadius } = useThemeContext() - const { loginUser, permissionList } = useAuthContext() + // 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) + // const shouldBeLogin = isEmpty(loginUser) && (href.indexOf('/p/') == -1) let defaultPath = 'follow' if (href !== '/') { const splitPath = href.split('/') defaultPath = href } + const { token: { colorBgContainer }, } = theme.useToken() @@ -44,7 +51,7 @@ function AuthApp() { return () => { disconnectWebsocket(); } - }, [loginUser, connectWebsocket, disconnectWebsocket, fetchInitialData]); + }, [loginUser.userId, connectWebsocket, disconnectWebsocket, fetchInitialData]); return (