throw-drift-bottle.component_20241224173612.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { IonHeader, IonButton, IonList, IonListHeader, IonItem, IonContent, IonIcon, IonLabel, IonCardHeader, IonCardContent, IonTitle, IonCard, IonToolbar, IonInput, IonSearchbar, IonSegment, IonSegmentButton, IonSelect, IonSelectOption } from '@ionic/angular/standalone';
  4. import { CommonModule } from '@angular/common';
  5. import { FormsModule } from '@angular/forms'; // 导入 FormsModule
  6. import { HttpClient } from '@angular/common/http';
  7. import { CloudObject } from 'src/lib/ncloud';
  8. import { IonCardTitle } from '@ionic/angular/standalone';
  9. @Component({
  10. selector: 'app-throw-drift-bottle',
  11. templateUrl: './throw-drift-bottle.component.html',
  12. styleUrls: ['./throw-drift-bottle.component.scss'],
  13. standalone: true,
  14. imports: [
  15. IonHeader, IonToolbar, IonTitle, IonContent, IonSegment, IonSegmentButton, IonSelect, IonSelectOption,
  16. FormsModule, IonList, IonListHeader, IonItem,
  17. IonLabel, IonIcon, IonButton, IonCardContent,
  18. IonInput, IonSearchbar, IonCard, IonCardHeader,
  19. CommonModule,IonCardTitle
  20. ]
  21. })
  22. export class ModalThrowDriftBottleComponent implements OnInit {
  23. driftbottleData: { content: string } = { content: '' }; // 漂流瓶内容
  24. constructor(private router: Router, private http: HttpClient) { }
  25. ngOnInit() {}
  26. throwdriftbottle() {
  27. console.log('投掷漂流瓶:');
  28. console.log(`内容: ${this.driftbottleData.content}`);
  29. // 这里可以添加逻辑将漂流瓶内容发布到后端或其他处理
  30. const driftbottleData = {
  31. content: this.driftbottleData.content,
  32. };
  33. let driftbottle = new CloudObject("Driftbottle");
  34. driftbottle.set(driftbottleData);
  35. driftbottle.save().then(data => {
  36. console.log('漂流瓶已成功投掷', data);
  37. }).catch(err => {
  38. console.error('投掷漂流瓶时出错');
  39. });
  40. }
  41. }