modal-identity-verification.component.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { OnInit } from '@angular/core';
  2. import { Component } from '@angular/core';
  3. import { ModalController, IonInput, IonItem, IonLabel, IonSegment, IonButton, IonCard, IonSegmentButton,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. IonSegment,
  18. IonSegmentButton,
  19. IonButton,
  20. IonInput,
  21. IonItem,
  22. IonLabel,
  23. IonSelect,
  24. IonSelectOption,
  25. FormsModule,
  26. ],
  27. })
  28. export class ModalIdentityVerificationComponent implements OnInit {
  29. currentUser: CloudUser | undefined;
  30. userData: any = {
  31. school: '',
  32. identity: '',
  33. studentID: '',
  34. department: '',
  35. teacherID: ''
  36. };
  37. constructor(private modalCtrl: ModalController) {
  38. this.currentUser = new CloudUser();
  39. }
  40. ngOnInit() {}
  41. onIdentityChange() {
  42. // 根据身份选择进行处理
  43. if (this.userData.identity === 'student') {
  44. this.userData.teacherID = ''; // 清空教师ID字段
  45. } else if (this.userData.identity === 'teacher') {
  46. this.userData.studentID = ''; // 清空学号字段
  47. this.userData.department = ''; // 清空学院字段
  48. }
  49. }
  50. async save() {
  51. this.currentUser?.set(this.userData);
  52. await this.currentUser?.save();
  53. this.modalCtrl.dismiss(this.currentUser, "confirm");
  54. }
  55. cancel() {
  56. this.modalCtrl.dismiss(null, "cancel");
  57. }
  58. }
  59. export async function openIdentityVerificationModal(modalCtrl: ModalController): Promise<CloudUser | null> {
  60. const modal = await modalCtrl.create({
  61. component: ModalIdentityVerificationComponent,
  62. breakpoints: [0.7, 1.0],
  63. initialBreakpoint: 0.7
  64. });
  65. modal.present();
  66. const { data, role } = await modal.onWillDismiss();
  67. if (role === 'confirm') {
  68. return data;
  69. }
  70. return null;
  71. }