page-add.component.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Component } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import * as Parse from "parse";
  4. @Component({
  5. selector: 'app-page-add',
  6. templateUrl: './page-add.component.html',
  7. styleUrls: ['./page-add.component.scss']
  8. })
  9. export class PageAddComponent {
  10. userAdd: any = {
  11. name: '',
  12. tag: '',
  13. desc: ''
  14. };
  15. selectedImage: string | ArrayBuffer | null = null;
  16. constructor(
  17. private router: Router
  18. ) {}
  19. async saveAdd() {
  20. const Contact = Parse.Object.extend('Contact');
  21. const newContact = new Contact();
  22. newContact.set('name', this.userAdd.name);
  23. newContact.set('tag', this.userAdd.tag);
  24. newContact.set('desc', this.userAdd.desc);
  25. newContact.set('img', this.userAdd.img);
  26. // 设置其他联系人信息...
  27. try {
  28. await newContact.save();
  29. console.log('New contact saved successfully');
  30. this.router.navigate(['/lesson/me/userFollow']); // 导航到联系人列表页面
  31. } catch (error) {
  32. console.error('Error while saving new contact', error);
  33. }
  34. }
  35. onFileSelected(event: Event) {
  36. const inputElement = event.target as HTMLInputElement;
  37. if (inputElement.files && inputElement.files[0]) {
  38. const file = inputElement.files[0];
  39. const reader = new FileReader();
  40. reader.onload = () => {
  41. this.selectedImage = reader.result;
  42. };
  43. reader.readAsDataURL(file);
  44. }
  45. }
  46. }