Commit 91f4a3e7 authored by 前端-许佳敏's avatar 前端-许佳敏

新增用户名显示

parent 252fcdf1
...@@ -54,11 +54,7 @@ export function render(oldRender:Function) { ...@@ -54,11 +54,7 @@ export function render(oldRender:Function) {
PublicApi.getMemberManageLoginReget().then(res => { PublicApi.getMemberManageLoginReget().then(res => {
const { data, code } = res const { data, code } = res
if (code === 1000) { if (code === 1000) {
setAuth({ setAuth(data)
memberId: data.memberId,
userId: data.userId,
token: data.token
})
setRouters(data.urls) setRouters(data.urls)
} else { } else {
removeAuth() removeAuth()
......
...@@ -3,7 +3,7 @@ import { Link, history } from 'umi' ...@@ -3,7 +3,7 @@ import { Link, history } from 'umi'
import { Menu, Dropdown } from 'antd' import { Menu, Dropdown } from 'antd'
import { CaretDownOutlined } from '@ant-design/icons' import { CaretDownOutlined } from '@ant-design/icons'
import styles from './index.less' import styles from './index.less'
import { removeAuth } from '@/utils/auth' import { removeAuth, getAuth } from '@/utils/auth'
const RightContent: React.FC<{}> = (props) => { const RightContent: React.FC<{}> = (props) => {
...@@ -22,15 +22,16 @@ const RightContent: React.FC<{}> = (props) => { ...@@ -22,15 +22,16 @@ const RightContent: React.FC<{}> = (props) => {
</Menu> </Menu>
); );
const userInfo = getAuth()
console.log(userInfo)
return <div className={styles.lxLayoutRight}> return <div className={styles.lxLayoutRight}>
<Link to="/home" className={styles.lxLink}>返回首页</Link> <Link to="/home" className={styles.lxLink}>返回首页</Link>
<Dropdown overlay={menu}> <Dropdown overlay={menu}>
<div className={styles.avatarWrap}> <div className={styles.avatarWrap}>
<div className={styles.avatar}></div> <div className={styles.avatar}></div>
<div className="ant-dropdown-link" onClick={e => e.preventDefault()}> <div className="ant-dropdown-link" onClick={e => e.preventDefault()}>
<span>Admin</span> <span>{userInfo?.name || '未知用户'}</span>
<CaretDownOutlined /> <CaretDownOutlined />
</div> </div>
</div> </div>
......
...@@ -81,11 +81,7 @@ class Index extends Component<{}, IndexState> { ...@@ -81,11 +81,7 @@ class Index extends Component<{}, IndexState> {
console.log('Received values of form: ', values); console.log('Received values of form: ', values);
PublicApi.postMemberManageLogin(values).then(res => { PublicApi.postMemberManageLogin(values).then(res => {
const { data } = res const { data } = res
setAuth({ setAuth(data)
memberId: data.memberId,
userId: data.userId,
token: data.token
})
setRouters(data.urls) setRouters(data.urls)
window.location.href = '/home' window.location.href = '/home'
}).catch(error => { }).catch(error => {
......
import { isDev } from '@/constants' import { isDev } from '@/constants'
import { PublicApi } from '@/services/api'
import { GetMemberManageLoginRegetResponse } from '@/services'
export interface AuthInfo { export interface AuthInfo {
userId: number, userId: number,
memberId: number, memberId: number,
token: string token: string,
name: string,
account: string,
} }
export const setAuth = (info: AuthInfo) => { export const setAuth = (info: GetMemberManageLoginRegetResponse) => {
window.localStorage.setItem('auth', JSON.stringify(info)) window.localStorage.setItem('auth', JSON.stringify(info))
} }
......
...@@ -56,10 +56,12 @@ const baseRequest = extend({ ...@@ -56,10 +56,12 @@ const baseRequest = extend({
// 请求拦截器 // 请求拦截器
baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit): { url: string, options: RequestOptionsInit } => { baseRequest.interceptors.request.use((url: string, options: RequestOptionsInit): { url: string, options: RequestOptionsInit } => {
// 判断是否有权限 // 判断是否有权限
const loginAfterHeaders = getAuth() const { userId, memberId, token } = getAuth()
const headers = { const headers = {
...options.headers, ...options.headers,
...loginAfterHeaders userId,
memberId,
token
} }
return { return {
// 前缀如果已经带上api, 跳过自动补前缀 // 前缀如果已经带上api, 跳过自动补前缀
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment