123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { CommonModule } from '@angular/common'; // 导入 CommonModule
- import { IonHeader, IonButton, IonContent, IonIcon, IonItem, IonLabel, IonList,
- IonListHeader, IonCardHeader, IonCardTitle, IonCardContent, IonTitle, IonCard, IonToolbar, IonInput, IonSearchbar } from '@ionic/angular/standalone';
- import { CloudQuery, CloudObject, CloudUser } from 'src/lib/ncloud';
- import { UserService } from 'src/app/user.service'; // 假设这是你的用户服务
- @Component({
- selector: 'app-my-drift-bottle',
- templateUrl: './my-drift-bottle.component.html',
- styleUrls: ['./my-drift-bottle.component.scss'],
- standalone: true,
- imports: [
- CommonModule, // 添加 CommonModule
-
- IonHeader, IonToolbar, IonTitle, IonContent,
- IonList, IonListHeader, IonItem, IonCardTitle,
- IonLabel, IonIcon, IonButton, IonCardContent,
- IonInput, IonSearchbar, IonCard, IonCardHeader,
- ]
- })
- export class MyDriftBottleComponent implements OnInit {
- filteredDriftbottles2: any[] = [];
- Driftbottles: any[] = [];
- filteredDriftbottles: any[] = [];
- username: string = '';
- constructor(private router: Router, private userService: UserService) {}
- ngOnInit() {
- this.getDriftbottles(); // 获取所有漂流瓶并进行过滤
- }
- async getDriftbottles() {
- let query = new CloudQuery("Driftbottle");
- this.Driftbottles = await query.find();
- this.filterDriftbottles();
- this.filterDriftbottles2();
- }
- filterDriftbottles() {
- let user = new CloudUser();
- console.log(user);
- this.filteredDriftbottles = this.Driftbottles.filter(driftbottle => {
- console.log(driftbottle.get("username"), user.get("username"));
- return driftbottle.get("username") === user.get("username") || driftbottle.get("username") === 'all';
- });
- }
- filterDriftbottles2() {
- let user = new CloudUser();
- console.log(user);
- this.filteredDriftbottles2 = this.Driftbottles.filter(driftbottle => {
- console.log(driftbottle.get("catcher"), user.get("username"));
- return driftbottle.get("catcher") === user.get("username") || driftbottle.get("catcher") === 'all';
- });
- }
- goDriftbottle() {
- this.router.navigate(['tabs/drift-bottle']);
- }
- gothrowNewDriftbottle() {
- this.router.navigate(['tabs/drift-bottle']); // 假设这是投掷新漂流瓶的路由
- }
- async rethrowBottle(bottle: CloudObject) {
- try {
- bottle.set({
- status: "drifting",
- catcher: null,
- catchtime: null
- });
- await bottle.save();
- this.getDriftbottles(); // 刷新漂流瓶列表
- console.log('漂流瓶扔回成功');
- } catch (err) {
- console.error('扔回漂流瓶时出错:', err);
- }
- }
- }
|