You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
46 lines
1.5 KiB
import { Component } from '@angular/core'
|
|
import { SharedModule } from '../../shared/shared.module'
|
|
import { FormControl, FormGroup } from '@angular/forms'
|
|
import { FormValidators } from 'app/utils'
|
|
import { ApiService, LocalHttpInterceptorService } from 'app/services'
|
|
import { NzMessageService } from 'ng-zorro-antd/message'
|
|
|
|
@Component({
|
|
standalone: true,
|
|
imports: [SharedModule],
|
|
selector: 'app-profile-account',
|
|
templateUrl: './profile-account.component.html',
|
|
styleUrls: ['./profile-account.component.less'],
|
|
})
|
|
export class ProfileAccountComponent {
|
|
constructor(
|
|
private local: LocalHttpInterceptorService,
|
|
private api: ApiService,
|
|
private msg: NzMessageService,
|
|
) {}
|
|
|
|
formGroup = new FormGroup({
|
|
id: new FormControl(this.api.authInfo.id),
|
|
username: new FormControl({ value: this.api.authInfo.username, disabled: true }, [
|
|
FormValidators.required('请输入用户名'),
|
|
]),
|
|
password: new FormControl('', [FormValidators.required('请输入密码')]),
|
|
confirmPassword: new FormControl('', [FormValidators.required('请再次输入密码')]),
|
|
})
|
|
|
|
onSubmit() {
|
|
if (FormValidators.validateFormGroup(this.formGroup)) {
|
|
if (this.formGroup.value.confirmPassword !== this.formGroup.value.password) {
|
|
this.msg.error('两次输入密码不一致')
|
|
return
|
|
}
|
|
const v = this.formGroup.getRawValue()
|
|
this.api.changePassword(v).subscribe(() => {
|
|
this.msg.success('修改成功,请重新登录').onClose.subscribe(() => {
|
|
this.local.removeAccess()
|
|
window.location.href = '/login'
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|