|
@@ -1,5 +1,5 @@
|
|
|
import { Component, OnInit, OnDestroy, Renderer2, ElementRef, ViewChild } from '@angular/core';
|
|
|
-import { Router } from '@angular/router';
|
|
|
+import { ActivatedRoute, Router } from '@angular/router';
|
|
|
import { IonicModule } from '@ionic/angular';
|
|
|
import { openThrowDriftBottleModal } from '../throw-drift-bottle/throw-drift-bottle.component';
|
|
|
import { ModalController } from '@ionic/angular/standalone';
|
|
@@ -28,24 +28,39 @@ export class DriftBottleComponent implements OnInit, OnDestroy {
|
|
|
constructor(
|
|
|
private router: Router,
|
|
|
private modalCtrl: ModalController,
|
|
|
+ private route:ActivatedRoute,
|
|
|
private http: HttpClient,
|
|
|
private renderer: Renderer2,
|
|
|
private userService: UserService // 注入用户服务
|
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
|
- if (this.audioElement && this.audioElement.nativeElement) {
|
|
|
- const audio = this.audioElement.nativeElement;
|
|
|
- audio.loop = true;
|
|
|
- audio.play().catch(error => {
|
|
|
- console.error('Failed to play audio:', error);
|
|
|
- });
|
|
|
- } else {
|
|
|
- console.warn('Audio element not found');
|
|
|
- }
|
|
|
+
|
|
|
+ this.route.params.subscribe(data=>{
|
|
|
+ if (this.audioElement && this.audioElement.nativeElement) {
|
|
|
+ const audio = this.audioElement.nativeElement;
|
|
|
+ audio.loop = true;
|
|
|
+ audio.play().catch((error:any) => {
|
|
|
+ console.error('Failed to play audio:', error);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.warn('Audio element not found');
|
|
|
+ }
|
|
|
+
|
|
|
+ let listenLeaveInt = setInterval(() => {
|
|
|
+ let isLeave = location.pathname?.indexOf("drift-bottle")==-1
|
|
|
+ if(isLeave){
|
|
|
+ this.stop()
|
|
|
+ clearInterval(listenLeaveInt);
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
+ this.stop()
|
|
|
+ }
|
|
|
+ stop(){
|
|
|
if (this.audioElement && this.audioElement.nativeElement) {
|
|
|
const audio = this.audioElement.nativeElement;
|
|
|
audio.pause();
|
|
@@ -63,7 +78,7 @@ export class DriftBottleComponent implements OnInit, OnDestroy {
|
|
|
//点击捞一个时,随机打捞一个状态为漂流中的漂流瓶,将其状态(status)改为被打捞,打捞时间(catchtime)改为当前时间,打捞者(catcher)改为该用户的username
|
|
|
//如果打捞成功,则在页面中间显示“打捞成功!快去看看吧!”,如果数据库中没有状态为drifting的漂流瓶,则打捞失败,在页面中间显示“没捞着哭哭~”
|
|
|
catchDriftBottle() {
|
|
|
- const query = new CloudQuery("DriftBottle");
|
|
|
+ const query = new CloudQuery("Driftbottle");
|
|
|
query.equalTo("status", "drifting");
|
|
|
|
|
|
query.find().then((driftingBottles: any[]) => {
|