album.component.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Component, OnInit } from '@angular/core';
  2. import {
  3. IonicModule,
  4. LoadingController,
  5. ToastController,
  6. } from '@ionic/angular';
  7. import * as Parse from 'parse';
  8. import { UploadComponent } from '../../../app/components/upload/upload.component';
  9. import { AuthService } from '../../../services/auth.service';
  10. @Component({
  11. selector: 'app-album',
  12. templateUrl: './album.component.html',
  13. styleUrls: ['./album.component.scss'],
  14. standalone: true,
  15. imports: [IonicModule, UploadComponent],
  16. })
  17. export class AlbumComponent implements OnInit {
  18. files: any = [];
  19. profile?: Parse.Object;
  20. loading:boolean = false
  21. constructor(
  22. public loadCtrl: LoadingController,
  23. public toastController: ToastController,
  24. private authServ: AuthService
  25. ) {}
  26. ngOnInit() {
  27. console.log(Parse.User.current()?.toPointer());
  28. this.getProfile();
  29. }
  30. async getProfile() {
  31. let query = new Parse.Query('Profile');
  32. query.equalTo('user', Parse.User.current()?.id);
  33. query.notEqualTo('isDeleted', true);
  34. query.select('attachment');
  35. let p = await query.first();
  36. this.profile = p;
  37. this.files = p?.get('attachment')?.map((item: String) => {
  38. return { url: item };
  39. });
  40. this.loading = true
  41. }
  42. async onSave(e: any) {
  43. console.log(e);
  44. let urls = e?.map((item: any) => item.url);
  45. if (!this.profile?.id) {
  46. let obj = Parse.Object.extend('Profile');
  47. this.profile = new obj();
  48. }
  49. this.profile?.set('user', Parse.User.current()?.toPointer());
  50. this.profile?.set('company', {
  51. __type: 'Pointer',
  52. className: 'Company',
  53. objectId: this.authServ.company,
  54. });
  55. this.profile?.set('attachment', urls);
  56. await this.profile?.save();
  57. const toast = await this.toastController.create({
  58. message: '保存成功',
  59. color: 'success',
  60. duration: 1000,
  61. });
  62. toast.present();
  63. }
  64. back() {
  65. history.back();
  66. }
  67. }