accouts.component.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { Component, ChangeDetectorRef, OnInit, Input, Inject } from '@angular/core';
  17. import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
  18. import { Router, ActivatedRoute } from '@angular/router';
  19. import { I18NService } from '@core';
  20. import { ALAIN_I18N_TOKEN, SettingsService } from '@delon/theme';
  21. import { environment } from '@env/environment';
  22. import { NzMessageService } from 'ng-zorro-antd/message';
  23. import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
  24. import { Accounts } from '../../../entity/Accounts';
  25. import { AccountsService } from '../../../service/accounts.service';
  26. @Component({
  27. selector: 'app-accouts',
  28. templateUrl: './accouts.component.html',
  29. styleUrls: ['./accouts.component.less']
  30. })
  31. export class AccoutsComponent implements OnInit {
  32. @Input() appId?: String;
  33. form: {
  34. submitting: boolean;
  35. model: Accounts;
  36. } = {
  37. submitting: false,
  38. model: new Accounts()
  39. };
  40. redirect_uri: string = '';
  41. formGroup: FormGroup = new FormGroup({});
  42. confirmPasswordVisible = false;
  43. passwordVisible = false;
  44. constructor(
  45. fb: FormBuilder,
  46. private router: Router,
  47. private route: ActivatedRoute,
  48. private modalRef: NzModalRef,
  49. private accountsService: AccountsService,
  50. private msg: NzMessageService,
  51. @Inject(ALAIN_I18N_TOKEN) private i18n: I18NService,
  52. private cdr: ChangeDetectorRef
  53. ) { }
  54. ngOnInit(): void {
  55. if (this.appId) {
  56. this.accountsService.get(this.appId).subscribe(res => {
  57. console.log(res.data);
  58. this.form.model.init(res.data);
  59. this.cdr.detectChanges();
  60. });
  61. }
  62. }
  63. onClose(e: MouseEvent): void {
  64. e.preventDefault();
  65. this.modalRef.destroy({ refresh: false });
  66. }
  67. onSubmit(): void {
  68. this.form.submitting = true;
  69. this.form.model.trans();
  70. //if (this.formGroup.valid) {
  71. this.accountsService.update(this.form.model).subscribe(res => {
  72. if (res.code == 0) {
  73. this.form.model.init(res.data);
  74. this.msg.success(this.i18n.fanyi('mxk.alert.operate.success'));
  75. if (this.redirect_uri) {
  76. window.location.href = `${environment.api.baseUrl}${this.redirect_uri}`;
  77. }
  78. } else {
  79. this.msg.error(this.i18n.fanyi('mxk.alert.operate.error'));
  80. }
  81. });
  82. this.form.submitting = false;
  83. this.cdr.detectChanges();
  84. }
  85. }