updatePasswordDialog.ets
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { promptAction } from '@kit.ArkUI'
import { updatePassword } from '../api/user'
@CustomDialog
export default struct updatePasswordDialog{
controller: CustomDialogController = new CustomDialogController({builder: ''})
@State oldPassword: string = ''
@State newPassword: string = ''
@State requirePassword: string = ''
build() {
Column(){
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('旧密码')
}.width(90)
TextInput({placeholder: '请输入旧密码', text: $$this.oldPassword})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Password)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('新密码')
}.width(90)
TextInput({placeholder: '请输入新密码', text: $$this.newPassword})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Password)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row(){
Row(){
Image($r('app.media.require')).width(20)
Text('确认密码')
}.width(90)
TextInput({placeholder: '请确认密码', text: $$this.requirePassword})
.backgroundColor('#fff').layoutWeight(1).type(InputType.Password)
}.border({width: {bottom: 1}, color: '#eee'}).padding({top: 10, bottom: 10})
Row({space: 10}){
Text('取消').layoutWeight(1).textAlign(TextAlign.Center).onClick(() => {
this.controller.close()
})
Text('确认').layoutWeight(1).fontColor('#1890ff').textAlign(TextAlign.Center)
.onClick(async () => {
if(this.oldPassword == '' && this.newPassword == '' && this.requirePassword == '') {
promptAction.showToast({
message: '请正确填写内容',
duration: 2000
})
} else if(this.newPassword == this.oldPassword) {
promptAction.showToast({
message: '新密码和旧密码不能相同',
duration: 2000
})
} else if(this.newPassword !== this.requirePassword) {
promptAction.showToast({
message: '两次密码输入不同',
duration: 2000
})
} else {
await updatePassword(this.oldPassword, this.newPassword)
promptAction.showToast({
message: '修改成功',
duration: 2000
})
this.controller.close()
}
})
}.width('100%').padding({top: 10, bottom: 10})
}.backgroundColor('#fff').width('100%')
.padding({top: 20,left: 13, right: 13})
}
}