Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈智峰
jinfa-platform
Commits
2614883d
Commit
2614883d
authored
Sep 21, 2020
by
XieZhiXiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成会员角色切换相关
parent
1e8221b6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
RightContent.tsx
src/layouts/components/RightContent.tsx
+2
-0
Roles.tsx
src/layouts/components/Roles.tsx
+76
-0
No files found.
src/layouts/components/RightContent.tsx
View file @
2614883d
...
...
@@ -6,6 +6,7 @@ import React from 'react';
import
Avatar
from
'./AvatarDropdown'
;
import
SelectLang
from
'./SelectLang'
;
import
Location
from
'./Location'
;
import
Roles
from
'./Roles'
;
import
styles
from
'../styles/RightContent.less'
;
// export type SiderTheme = 'light' | 'dark';
...
...
@@ -25,6 +26,7 @@ const GlobalHeaderRight: React.SFC<{}> = (props) => {
return
(
<
div
className=
{
className
}
>
<
Roles
/>
<
Location
/>
<
SelectLang
/>
<
Tooltip
title=
"消息"
>
...
...
src/layouts/components/Roles.tsx
0 → 100644
View file @
2614883d
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
Dropdown
,
Space
,
Menu
,
message
}
from
'antd'
;
import
{
getAuth
,
setAuth
,
setRouters
}
from
'@/utils/auth'
;
import
{
PublicApi
}
from
'@/services/api'
;
interface
MemberRole
{
memberRoleId
:
number
;
memberRoleName
:
string
;
};
const
Roles
:
React
.
FC
=
()
=>
{
const
[
curRole
,
setCurRole
]
=
useState
<
MemberRole
>
(
null
);
const
[
roles
,
setRoles
]
=
useState
<
MemberRole
[]
>
([]);
useEffect
(()
=>
{
const
userInfo
=
getAuth
();
setRoles
(
userInfo
.
roles
||
[]);
if
(
userInfo
.
roles
&&
userInfo
.
roles
.
length
)
{
const
current
=
userInfo
.
roles
.
find
(
item
=>
item
.
memberRoleId
===
userInfo
.
memberRoleId
);
setCurRole
(
current
);
}
},
[]);
const
handleSelect
=
(
item
:
MemberRole
)
=>
{
const
{
memberRoleId
}
=
item
;
if
(
memberRoleId
===
curRole
.
memberRoleId
)
{
return
;
}
const
msg
=
message
.
loading
({
content
:
'正在切换角色...'
,
duration
:
0
,
});
PublicApi
.
postMemberLoginSwitchrole
({
memberRoleId
,
}).
then
(
res
=>
{
if
(
res
.
code
!==
1000
)
{
return
;
}
msg
();
setAuth
(
res
.
data
);
setRouters
(
res
.
data
.
urls
);
setTimeout
(()
=>
{
window
.
location
.
replace
(
'/memberCenter/home'
);
},
800
);
});
};
const
menuHeaderDropdown
=
(
<
Menu
selectedKeys=
{
curRole
?
[
`${curRole.memberRoleId}`
]
:
[]
}
>
{
roles
.
map
(
item
=>
(
<
Menu
.
Item
key=
{
item
.
memberRoleId
}
onClick=
{
()
=>
handleSelect
(
item
)
}
>
<
Space
>
<
span
>
{
item
.
memberRoleName
}
</
span
>
</
Space
>
</
Menu
.
Item
>
))
}
</
Menu
>
);
return
(
<
Dropdown
overlay=
{
menuHeaderDropdown
}
placement=
"bottomRight"
>
<
span
style=
{
{
cursor
:
'pointer'
,
padding
:
'0 15px'
}
}
>
{
curRole
?.
memberRoleName
}
</
span
>
</
Dropdown
>
)
};
export
default
Roles
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment