modal-identity-verification.component_20241222155740.ts 2.0 KB

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