Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
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
wangpeng
dinky
Commits
c2795d67
Unverified
Commit
c2795d67
authored
Dec 09, 2022
by
czy868
Committed by
GitHub
Dec 09, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature-787][dlink-web] user can change password (#1414)
* -- 1209新增用户修改密码功能(前端) * -- 删除无用代码(前端) Co-authored-by:
caizhengyu
<
caizhengyu@qudian.com
>
parent
33a0c248
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
44 deletions
+72
-44
AvatarDropdown.tsx
dlink-web/src/components/RightContent/AvatarDropdown.tsx
+57
-29
PasswordForm.tsx
...henticationCenter/UserManager/components/PasswordForm.tsx
+15
-15
No files found.
dlink-web/src/components/RightContent/AvatarDropdown.tsx
View file @
c2795d67
...
...
@@ -18,7 +18,7 @@
*/
import
React
,
{
useCallback
,
useRef
}
from
'react'
;
import
React
,
{
useCallback
,
useRef
,
useState
}
from
'react'
;
import
{
LogoutOutlined
,
SafetyOutlined
,
...
...
@@ -26,14 +26,16 @@ import {
SettingOutlined
,
UserSwitchOutlined
}
from
'@ant-design/icons'
;
import
{
Avatar
,
Menu
,
Modal
,
Spin
}
from
'antd'
;
import
{
history
,
useModel
}
from
'umi'
;
import
{
stringify
}
from
'querystring'
;
import
{
Avatar
,
Menu
,
Modal
,
Spin
}
from
'antd'
;
import
{
handleOption
}
from
"@/components/Common/crud"
;
import
{
history
,
useModel
}
from
'umi'
;
import
{
stringify
}
from
'querystring'
;
import
HeaderDropdown
from
'../HeaderDropdown'
;
import
styles
from
'./index.less'
;
import
{
outLogin
}
from
'@/services/ant-design-pro/api'
;
import
{
ActionType
}
from
"@ant-design/pro-table"
;
import
{
l
}
from
"@/utils/intl"
;
import
{
outLogin
}
from
'@/services/ant-design-pro/api'
;
import
{
ActionType
}
from
"@ant-design/pro-table"
;
import
{
l
}
from
"@/utils/intl"
;
import
PasswordForm
from
"@/pages/AuthenticationCenter/UserManager/components/PasswordForm"
;
export
type
GlobalHeaderRightProps
=
{
menu
?:
boolean
;
...
...
@@ -44,8 +46,8 @@ export type GlobalHeaderRightProps = {
*/
const
loginOut
=
async
()
=>
{
await
outLogin
();
const
{
query
=
{},
pathname
}
=
history
.
location
;
const
{
redirect
}
=
query
;
const
{
query
=
{},
pathname
}
=
history
.
location
;
const
{
redirect
}
=
query
;
// Note: There may be security issues, please note
if
(
window
.
location
.
pathname
!==
'/user/login'
&&
!
redirect
)
{
history
.
replace
({
...
...
@@ -60,11 +62,14 @@ const loginOut = async () => {
const
requestUrl
=
'/api/tenant/switchTenant'
;
const
AvatarDropdown
:
React
.
FC
<
GlobalHeaderRightProps
>
=
({
menu
})
=>
{
const
{
initialState
,
setInitialState
}
=
useModel
(
'@@initialState'
);
const
url
=
'/api/user'
;
const
AvatarDropdown
:
React
.
FC
<
GlobalHeaderRightProps
>
=
({
menu
})
=>
{
const
{
initialState
,
setInitialState
}
=
useModel
(
'@@initialState'
);
const
actionRef
=
useRef
<
ActionType
>
();
const
[
formValues
,
setFormValues
]
=
useState
({});
const
[
passwordModalVisible
,
handlePasswordModalVisible
]
=
useState
<
boolean
>
(
false
);
const
onMenuClick
=
useCallback
(
(
event
:
{
key
:
React
.
Key
;
...
...
@@ -72,11 +77,16 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({menu}) => {
item
:
React
.
ReactInstance
;
domEvent
:
React
.
MouseEvent
<
HTMLElement
>
;
})
=>
{
const
{
key
}
=
event
;
const
{
key
}
=
event
;
if
(
key
===
'logout'
&&
initialState
)
{
setInitialState
({
...
initialState
,
currentUser
:
undefined
});
setInitialState
({
...
initialState
,
currentUser
:
undefined
});
loginOut
();
return
;
}
else
if
(
key
===
'changePassWord'
)
{
handlePasswordModalVisible
(
true
);
setFormValues
({
username
:
initialState
?.
currentUser
?.
username
})
}
else
{
}
// history.push(`/account/${key}`);
},
...
...
@@ -99,7 +109,7 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({menu}) => {
return
loading
;
}
const
{
currentUser
}
=
initialState
;
const
{
currentUser
}
=
initialState
;
if
(
!
currentUser
||
!
currentUser
.
username
)
{
return
loading
;
...
...
@@ -115,7 +125,7 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({menu}) => {
disabled=
{
item
.
id
===
currentUser
.
currentTenant
?.
id
}
key=
{
item
.
id
}
title=
{
item
.
tenantCode
}
icon=
{
<
SecurityScanOutlined
/>
}
icon=
{
<
SecurityScanOutlined
/>
}
onClick=
{
(
e
)
=>
{
// get choose tenant title
let
title
:
string
=
e
.
domEvent
.
target
.
textContent
;
...
...
@@ -123,7 +133,7 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({menu}) => {
let
tenantInfoId
=
e
.
key
;
Modal
.
confirm
({
title
:
l
(
'menu.account.checkTenant'
),
content
:
l
(
'menu.account.checkTenantConfirm'
,
''
,
{
tenantCode
:
title
}),
content
:
l
(
'menu.account.checkTenantConfirm'
,
''
,
{
tenantCode
:
title
}),
okText
:
l
(
'button.confirm'
),
cancelText
:
l
(
'button.cancel'
),
onOk
:
async
()
=>
{
...
...
@@ -152,7 +162,7 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({menu}) => {
<
Menu
.
SubMenu
key=
"chooseTenantList"
title=
{
l
(
'menu.account.checkTenant'
)
}
icon=
{
<
UserSwitchOutlined
/>
}
icon=
{
<
UserSwitchOutlined
/>
}
>
{
chooseTenantList
}
</
Menu
.
SubMenu
>
...
...
@@ -167,30 +177,48 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({menu}) => {
)
}
{
menu
&&
(
<
Menu
.
Item
key=
"personSettings"
disabled
>
<
SettingOutlined
/>
<
SettingOutlined
/>
{
l
(
'menu.account.settings'
)
}
</
Menu
.
Item
>
)
}
{
menu
&&
(
<
Menu
.
Item
key=
"changePassWord"
disabled
>
<
SafetyOutlined
/>
<
Menu
.
Item
key=
"changePassWord"
>
<
SafetyOutlined
/>
{
l
(
'menu.account.changePassword'
)
}
</
Menu
.
Item
>
)
}
{
menu
&&
<
Menu
.
Divider
/>
}
{
menu
&&
<
Menu
.
Divider
/>
}
<
Menu
.
Item
key=
"logout"
>
<
LogoutOutlined
/>
<
LogoutOutlined
/>
{
l
(
'menu.account.logout'
)
}
</
Menu
.
Item
>
</
Menu
>
);
return
(
<
HeaderDropdown
overlay=
{
menuHeaderDropdown
}
>
<
span
className=
{
`${styles.action} ${styles.account}`
}
>
<
Avatar
size=
"small"
className=
{
styles
.
avatar
}
src=
{
currentUser
.
avatar
}
alt=
"avatar"
/>
<
span
className=
{
`${styles.name} anticon`
}
>
{
currentUser
.
username
}
</
span
>
</
span
>
</
HeaderDropdown
>
<
div
>
<
HeaderDropdown
overlay=
{
menuHeaderDropdown
}
>
<
span
className=
{
`${styles.action} ${styles.account}`
}
>
<
Avatar
size=
"small"
className=
{
styles
.
avatar
}
src=
{
currentUser
.
avatar
}
alt=
"avatar"
/>
<
span
className=
{
`${styles.name} anticon`
}
>
{
currentUser
.
username
}
</
span
>
</
span
>
</
HeaderDropdown
>
{
formValues
&&
Object
.
keys
(
formValues
).
length
?
(
<
PasswordForm
onSubmit=
{
async
(
value
)
=>
{
const
success
=
await
handleOption
(
url
+
"/modifyPassword"
,
l
(
'button.changePassword'
),
value
);
if
(
success
)
{
handlePasswordModalVisible
(
false
);
setFormValues
({});
}
}
}
onCancel=
{
()
=>
{
handlePasswordModalVisible
(
false
);
}
}
modalVisible=
{
passwordModalVisible
}
values=
{
formValues
}
/>
)
:
null
}
</
div
>
);
};
...
...
dlink-web/src/pages/AuthenticationCenter/UserManager/components/PasswordForm.tsx
View file @
c2795d67
...
...
@@ -18,10 +18,10 @@
*/
import
React
,
{
useState
}
from
'react'
;
import
{
Button
,
Form
,
Input
,
Modal
}
from
'antd'
;
import
{
PasswordItem
}
from
"@/pages/AuthenticationCenter/data.d"
;
import
{
l
}
from
"@/utils/intl"
;
import
React
,
{
useState
}
from
'react'
;
import
{
Button
,
Form
,
Input
,
Modal
}
from
'antd'
;
import
{
PasswordItem
}
from
"@/pages/AuthenticationCenter/data.d"
;
import
{
l
}
from
"@/utils/intl"
;
export
type
PasswordFormProps
=
{
onCancel
:
(
flag
?:
boolean
)
=>
void
;
...
...
@@ -31,8 +31,8 @@ export type PasswordFormProps = {
};
const
formLayout
=
{
labelCol
:
{
span
:
7
},
wrapperCol
:
{
span
:
13
},
labelCol
:
{
span
:
7
},
wrapperCol
:
{
span
:
13
},
};
const
PasswordForm
:
React
.
FC
<
PasswordFormProps
>
=
(
props
)
=>
{
...
...
@@ -51,8 +51,8 @@ const PasswordForm: React.FC<PasswordFormProps> = (props) => {
const
submitForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
({
...
formVals
,
...
fieldsValue
});
handleSubmit
({
...
formVals
,
...
fieldsValue
});
setFormVals
({
...
formVals
,
...
fieldsValue
});
handleSubmit
({
...
formVals
,
...
fieldsValue
});
};
const
renderContent
=
()
=>
{
...
...
@@ -62,15 +62,15 @@ const PasswordForm: React.FC<PasswordFormProps> = (props) => {
name=
"password"
label=
{
l
(
'pages.user.UserOldPassword'
)
}
hasFeedback
rules=
{
[{
required
:
true
,
message
:
l
(
'pages.user.UserEnterOldPassword'
)
}]
}
>
<
Input
.
Password
placeholder=
{
l
(
'pages.user.UserEnterOldPassword'
)
}
/>
rules=
{
[{
required
:
true
,
message
:
l
(
'pages.user.UserEnterOldPassword'
)
}]
}
>
<
Input
.
Password
placeholder=
{
l
(
'pages.user.UserEnterOldPassword'
)
}
/>
</
Form
.
Item
>
<
Form
.
Item
name=
"newPassword"
label=
{
l
(
'pages.user.UserNewPassword'
)
}
hasFeedback
rules=
{
[{
required
:
true
,
message
:
l
(
'pages.user.UserEnterNewPassword'
)
}]
}
>
<
Input
.
Password
placeholder=
{
l
(
'pages.user.UserEnterNewPassword'
)
}
/>
rules=
{
[{
required
:
true
,
message
:
l
(
'pages.user.UserEnterNewPassword'
)
}]
}
>
<
Input
.
Password
placeholder=
{
l
(
'pages.user.UserEnterNewPassword'
)
}
/>
</
Form
.
Item
>
<
Form
.
Item
name=
"newPasswordCheck"
...
...
@@ -82,7 +82,7 @@ const PasswordForm: React.FC<PasswordFormProps> = (props) => {
required
:
true
,
message
:
l
(
'pages.user.UserNewPasswordNotMatch'
),
},
({
getFieldValue
})
=>
({
({
getFieldValue
})
=>
({
validator
(
_
,
value
)
{
if
(
!
value
||
getFieldValue
(
'newPassword'
)
===
value
)
{
return
Promise
.
resolve
();
...
...
@@ -91,7 +91,7 @@ const PasswordForm: React.FC<PasswordFormProps> = (props) => {
},
}),
]
}
>
<
Input
.
Password
placeholder=
{
l
(
'pages.user.UserEnterRepeatNewPassword'
)
}
/>
<
Input
.
Password
placeholder=
{
l
(
'pages.user.UserEnterRepeatNewPassword'
)
}
/>
</
Form
.
Item
>
</>
);
...
...
@@ -111,7 +111,7 @@ const PasswordForm: React.FC<PasswordFormProps> = (props) => {
return
(
<
Modal
width=
{
"40%"
}
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
destroyOnClose
title=
{
l
(
'button.changePassword'
)
}
visible=
{
modalVisible
}
...
...
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