lanjianrong 5 yıl önce
ebeveyn
işleme
de048691fa

+ 4 - 1
src/components/RightContent/AvatarDropdown.tsx

@@ -6,6 +6,7 @@ import { history, useModel } from 'umi'
 import { stringify } from 'querystring'
 import HeaderDropdown from '../HeaderDropdown'
 import styles from './index.less'
+import { clearAuthCache } from '@/utils/auth'
 
 export type GlobalHeaderRightProps = {
   menu?: boolean
@@ -46,12 +47,14 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
           content: '是否确认退出系统?',
           onOk: () => {
             setInitialState({ ...initialState, currentUser: undefined, roles: [], permData: {} })
+            // 清除AuthCache
+            clearAuthCache()
             loginOut()
             return
           }
         })
       }
-      history.push(`/account/${key}`)
+      // history.push(`/account/${key}`)
     },
     [initialState, setInitialState]
   )

+ 9 - 5
src/pages/user/login/index.jsx

@@ -6,6 +6,8 @@ import { useIntl, Link, history, FormattedMessage, SelectLang, useModel } from '
 
 import styles from './index.less'
 import { apiLogin } from '@/services/login'
+import { setAuthCache } from '@/utils/auth'
+import { TOKEN_KEY } from '@/utils/cache/cacheEnum'
 
 const LoginMessage = ({ content }) => (
   <Alert
@@ -47,8 +49,10 @@ const Login = () => {
     setSubmitting(true)
     try {
       // 登录
-      const msg = await apiLogin({ ...values })
-      if (msg.code === 0) {
+      const res = await apiLogin({ ...values })
+      if (res.code === 0) {
+        setAuthCache(TOKEN_KEY, res.data.token)
+
         const defaultLoginSuccessMessage = intl.formatMessage({
           id: 'pages.login.success',
           defaultMessage: '登录成功!'
@@ -59,7 +63,7 @@ const Login = () => {
         return goto()
       }
       // 如果失败去设置用户错误信息
-      setUserLoginState(msg)
+      setUserLoginState(res.msg)
     } catch (error) {
       const defaultLoginFailureMessage = intl.formatMessage({
         id: 'pages.login.failure',
@@ -80,9 +84,9 @@ const Login = () => {
       <div className={styles.content}>
         <div className={styles.top}>
           <div className={styles.header}>
-            <Link to="/">
+            <Link to="/" className="flex justify-center">
               <img alt="logo" className={styles.logo} src="/logo.svg" />
-              <span className={styles.title}>Ant Design</span>
+              <span className={styles.title}>CLD.V2</span>
             </Link>
           </div>
           <div className={styles.desc}>