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

新增用户名显示

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