modal-identity-verification.component_20241222160455.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { OnInit } from '@angular/core';
  2. import { Component } from '@angular/core';
  3. import { ModalController, IonInput, IonItem, IonLabel, IonButton, IonCard, IonCardHeader, IonCardTitle, IonCardSubtitle, IonCardContent, IonSelect, IonSelectOption } from '@ionic/angular/standalone';
  4. import { CloudUser } from 'src/lib/ncloud';
  5. import { FormsModule } from '@angular/forms'; // 导入 FormsModule
  6. @Component({
  7. selector: 'app-modal-identity-verification',
  8. templateUrl: './modal-identity-verification.component.html',
  9. styleUrls: ['./modal-identity-verification.component.scss'],
  10. standalone: true,
  11. imports: [
  12. IonCard,
  13. IonCardHeader,
  14. IonCardTitle,
  15. IonCardSubtitle,
  16. IonCardContent,
  17. IonButton,
  18. IonInput,
  19. IonItem,
  20. IonLabel,
  21. IonSelect,
  22. IonSelectOption,
  23. FormsModule,
  24. ],
  25. })
  26. export class ModalIdentityVerificationComponent implements OnInit {
  27. currentUser: CloudUser | undefined;
  28. userData: any = {
  29. school: '',
  30. identity: '',
  31. studentID: '',
  32. department: '',
  33. teacherID: ''
  34. };
  35. constructor(private modalCtrl: ModalController) {
  36. this.currentUser = new CloudUser();
  37. }
  38. ngOnInit() {}
  39. onIdentityChange() {
  40. // 根据身份选择进行处理
  41. if (this.userData.identity === 'student') {
  42. this.userData.teacherID = ''; // 清空教师ID字段
  43. } else if (this.userData.identity === 'teacher') {
  44. this.userData.studentID = ''; // 清空学号字段
  45. this.userData.department = ''; // 清空学院字段
  46. }
  47. }
  48. async save() {
  49. this.currentUser?.set(this.userData);
  50. await this.currentUser?.save();
  51. this.modalCtrl.dismiss(this.currentUser, "confirm");
  52. }
  53. cancel() {
  54. this.modalCtrl.dismiss(null, "cancel");
  55. }
  56. }
  57. export async function openIdentityVerificationModal(modalCtrl: ModalController): Promise<CloudUser | null> {
  58. const modal = await modalCtrl.create({
  59. component: ModalIdentityVerificationComponent,
  60. breakpoints: [0.7, 1.0],
  61. initialBreakpoint: 0.7
  62. });
  63. modal.present();
  64. const { data, role } = await modal.onWillDismiss();
  65. if (role === 'confirm') {
  66. return data;
  67. }
  68. return null;
  69. }