|
| 1 | +import {Component, ViewChild} from '@angular/core'; |
| 2 | +import {SmartEditorComponent, SmartField} from '../lib/smart-editor/smart-editor.component'; |
| 3 | +import {Router} from '@angular/router'; |
| 4 | +import {NzNotificationService} from 'ng-zorro-antd/notification'; |
| 5 | +import {SmartRequestService} from '../lib/smart-request.service'; |
| 6 | +import {UserService} from '../user.service'; |
| 7 | +import {Md5} from 'ts-md5'; |
| 8 | +import {NzCardComponent} from 'ng-zorro-antd/card'; |
| 9 | +import {NzButtonComponent} from 'ng-zorro-antd/button'; |
| 10 | + |
| 11 | +@Component({ |
| 12 | + selector: 'app-password', |
| 13 | + standalone: true, |
| 14 | + imports: [ |
| 15 | + SmartEditorComponent, |
| 16 | + NzCardComponent, |
| 17 | + NzButtonComponent |
| 18 | + ], |
| 19 | + templateUrl: './password.html', |
| 20 | + styleUrl: './password.scss', |
| 21 | +}) |
| 22 | +export class PasswordComponent { |
| 23 | + |
| 24 | + fields: SmartField[] = [ |
| 25 | + {key: 'old', type: 'password', label: '旧密码', required: true}, |
| 26 | + {key: 'new', type: 'password', label: '新密码', required: true}, |
| 27 | + ] |
| 28 | + |
| 29 | + @ViewChild("editor", {static: true}) editor!: SmartEditorComponent; |
| 30 | + |
| 31 | + constructor(private router: Router, |
| 32 | + private ns: NzNotificationService, |
| 33 | + private request: SmartRequestService, |
| 34 | + private us: UserService, |
| 35 | + ) { |
| 36 | + } |
| 37 | + |
| 38 | + submit() { |
| 39 | + |
| 40 | + if (!this.editor.valid) { |
| 41 | + this.ns.error("错误", "无效密码") |
| 42 | + return |
| 43 | + } |
| 44 | + |
| 45 | + let obj = this.editor.value |
| 46 | + this.request.post("password", { |
| 47 | + old: Md5.hashStr(obj.old), |
| 48 | + new: Md5.hashStr(obj.new), |
| 49 | + }).subscribe(res => { |
| 50 | + console.log("password", res) |
| 51 | + if (res.error) { |
| 52 | + return |
| 53 | + } |
| 54 | + this.ns.success("提示", "修改成功,请重新登录") |
| 55 | + |
| 56 | + localStorage.removeItem("token") |
| 57 | + this.router.navigateByUrl('/login') |
| 58 | + }) |
| 59 | + } |
| 60 | +} |
0 commit comments