File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,13 @@ export const loginApi = (params: Login.ReqLoginForm) => {
15
15
// return http.post<Login.ResLogin>(PORT1 + `/login`, params, { headers: { noLoading: true } }); // 控制当前请求不显示 loading
16
16
} ;
17
17
18
+ /**
19
+ * 查询当前登录的用户信息
20
+ */
21
+ export const loginUserInfo = ( ) => {
22
+ return http . get ( PORT1 + `/user/info` , { } ) ;
23
+ } ;
24
+
18
25
export const logoutApi = ( ) => {
19
26
return http . get ( PORT1 + `/logout` , { } ) ;
20
27
} ;
Original file line number Diff line number Diff line change 1
1
import { connect } from "react-redux" ;
2
2
import { Layout } from "antd" ;
3
3
4
+ import { loginUserInfo } from "@/api/modules/login" ;
5
+ import { setToken , setUserInfo } from "@/redux/modules/global/action" ;
4
6
import AssemblySize from "./components/AssemblySize" ;
5
7
import AvatarIcon from "./components/AvatarIcon" ;
6
8
import BreadcrumbNav from "./components/BreadcrumbNav" ;
@@ -11,8 +13,23 @@ import Theme from "./components/Theme";
11
13
import "./index.less" ;
12
14
13
15
const LayoutHeader = ( props : any ) => {
14
- const { userInfo } = props || { } ;
16
+ let { userInfo } = props || { } ;
17
+ if ( ! userInfo ) {
18
+ let fetchUsrInfo = async ( ) => {
19
+ const { status, result } = await loginUserInfo ( ) ;
20
+ if ( status && status . code == 0 && result && result ?. userId > 0 ) {
21
+ // fixme 拿登录的用户名、用户头像来替换默认的用户名头像
22
+ setToken ( result ?. userId ) ;
23
+
24
+ setUserInfo ( result ) ;
25
+ userInfo = result ;
26
+ }
27
+ } ;
28
+ // 未拿到用户信息时,主动去拿一下
29
+ fetchUsrInfo ( ) ;
30
+ }
15
31
const { userName } = userInfo || { } ;
32
+ console . log ( "userInfo:" , userInfo , userName ) ;
16
33
17
34
const { Header } = Layout ;
18
35
You can’t perform that action at this time.
0 commit comments