Browse Source

新增评价

warrior 2 weeks ago
parent
commit
108b97f1bc
32 changed files with 315 additions and 75 deletions
  1. 3 0
      projects/live-app/src/app/app.routes.ts
  2. 38 5
      projects/live-app/src/app/components/appraise/appraise.component.html
  3. 23 1
      projects/live-app/src/app/components/appraise/appraise.component.scss
  4. 114 10
      projects/live-app/src/app/components/appraise/appraise.component.ts
  5. 1 1
      projects/live-app/src/app/components/gift-modal/gift-modal.component.ts
  6. 1 1
      projects/live-app/src/app/components/live/live.component.ts
  7. 1 1
      projects/live-app/src/app/components/upload/upload.component.ts
  8. 1 1
      projects/live-app/src/modules/account/notice-log/notice-log.component.ts
  9. 1 1
      projects/live-app/src/modules/account/recharge/recharge.component.ts
  10. 1 1
      projects/live-app/src/modules/goods/vip/vip.component.ts
  11. 1 1
      projects/live-app/src/modules/live/chat/chat.component.ts
  12. 6 5
      projects/live-app/src/modules/live/link-page/link-page.component.ts
  13. 1 1
      projects/live-app/src/modules/live/room-manage/room-manage.component.ts
  14. 1 1
      projects/live-app/src/modules/live/search/search.component.ts
  15. 38 0
      projects/live-app/src/modules/login/auth.guard.ts
  16. 1 1
      projects/live-app/src/modules/login/login.component.ts
  17. 1 1
      projects/live-app/src/modules/tabs/anthorhome/anthorhome.component.ts
  18. 2 1
      projects/live-app/src/modules/tabs/my/my.component.ts
  19. 1 1
      projects/live-app/src/modules/user/album/album.component.ts
  20. 1 1
      projects/live-app/src/modules/user/anchor/anchor.component.ts
  21. 1 1
      projects/live-app/src/modules/user/certification/certification.component.ts
  22. 5 1
      projects/live-app/src/modules/user/comment/comment.component.html
  23. 7 3
      projects/live-app/src/modules/user/comment/comment.component.scss
  24. 1 1
      projects/live-app/src/modules/user/feedback/feedback.component.ts
  25. 19 11
      projects/live-app/src/modules/user/profile/profile.component.html
  26. 7 3
      projects/live-app/src/modules/user/profile/profile.component.scss
  27. 1 1
      projects/live-app/src/modules/user/profile/profile.component.ts
  28. 1 1
      projects/live-app/src/modules/user/setting/setting.component.ts
  29. 1 1
      projects/live-app/src/modules/user/share/share.component.ts
  30. 8 2
      projects/live-app/src/services/auth.service.ts
  31. 26 14
      projects/live-app/src/services/live.service.ts
  32. 1 1
      projects/live-app/src/services/message.service.ts

+ 3 - 0
projects/live-app/src/app/app.routes.ts

@@ -7,10 +7,13 @@ import { UserRoutingModule } from '../modules/user/user.modules.routes';
 import { AccountRoutingModule } from '../modules/account/account.modules.routes';
 import { GoodsRoutingModule } from '../modules/goods/goods.modules.routes';
 import { LiveRoutingModule } from '../modules/live/live.modules.routes';
+import { LoginAuthGuard } from '../modules/login/auth.guard';
+
 export const routes: Routes = [
   { path: '', redirectTo:'tabs', pathMatch: "full",}, // 默认跳转到 ''
   {
     path: 'login',
+    canActivate: mapToCanActivate([LoginAuthGuard]),
     loadComponent:()=> import('../modules/login/login.component').then((mod) => mod.LoginComponent),
   },
   {

+ 38 - 5
projects/live-app/src/app/components/appraise/appraise.component.html

@@ -6,16 +6,49 @@
   [backdropDismiss]="false"
 >
   <ng-template>
+    <div class="modal-content">
+      <div class="title">评价</div>
+      <ion-segment
+        [scrollable]="true"
+        (ionChange)="segmentChanged($event)"
+        layout="icon-bottom"
+        value="negativeTags"
+        mode="md"
+      >
+        <ion-segment-button
+          value="negativeTags"
+          class="tabs"
+          content-id="negativeTags"
+        >
+          <ion-label>无感</ion-label>
+        </ion-segment-button>
+        <ion-segment-button
+          value="positiveTags"
+          class="tabs"
+          content-id="positiveTags"
+        >
+          <ion-label>喜欢</ion-label>
+        </ion-segment-button>
+      </ion-segment>
+      <div class="list">
+        @for (tag of list; track $index) {
+        <span 
+        (click)="onCheck(tag)"
+        [ngClass]="{
+          'action': checkTags.has(tag),
+        }">{{ tag }}</span>
+        } 
+      </div>
+    </div>
     <ion-toolbar>
       <ion-buttons slot="start">
-        <ion-button (click)="liveService.isOpenEvaluate = false">取消</ion-button>
+        <ion-button (click)="liveService.isOpenEvaluate = false"
+          >取消</ion-button
+        >
       </ion-buttons>
       <ion-buttons slot="end">
         <ion-button (click)="confirm()">确认</ion-button>
       </ion-buttons>
     </ion-toolbar>
-    <div class="wrapper">
-     
-    </div>
   </ng-template>
-</ion-modal>
+</ion-modal>

+ 23 - 1
projects/live-app/src/app/components/appraise/appraise.component.scss

@@ -1,7 +1,29 @@
 ion-modal {
-  --height: 50%;
+  --height: 280px;
   --width: 89.7436vw;
   --border-radius: 4.1026vw;
   --box-shadow: 0 2.5641vw 3.8462vw -0.7692vw rgb(0 0 0 / 0.1),
     0 1.0256vw 1.5385vw -1.0256vw rgb(0 0 0 / 0.1);
+}
+.title{
+  text-align: center;
+  font-size: 16px;
+  margin: 10px auto;
+  font-weight: bold;
+}
+.list{
+  display: flex;
+  flex-wrap: wrap;
+  padding: 4px;
+  span{
+    margin-right: 4px;
+    margin-bottom: 10px;
+    background-color: #d1d1d1; 
+    color: #fff;
+    padding: 2px 6px;
+    font-size: 14px;
+  }
+  .action{
+    background-color: #a065ee; 
+  }
 }

+ 114 - 10
projects/live-app/src/app/components/appraise/appraise.component.ts

@@ -1,26 +1,130 @@
 import { Component, OnInit } from '@angular/core';
 import { CommonModule } from '@angular/common';
-import { ionicStandaloneModules } from '../../../modules/ionic-standalone.modules';
+import {
+  ionicStandaloneModules,
+  LoadingController,
+  ToastController,
+} from '../../../modules/ionic-standalone.modules';
 import { LiveService } from '../../../services/live.service';
+import * as Parse from 'parse';
 
 @Component({
   selector: 'app-appraise',
   templateUrl: './appraise.component.html',
   styleUrls: ['./appraise.component.scss'],
   standalone: true,
-  imports: [
-    ...ionicStandaloneModules,
-    CommonModule,
-  ],
+  imports: [...ionicStandaloneModules, CommonModule],
 })
 export class AppraiseComponent implements OnInit {
+  active: string = 'negativeTags';
+  negativeTags: Array<string> = [
+    '没礼貌',
+    '不好看',
+    '不专业',
+    '态度差',
+    '声音难听',
+    '内容无聊',
+    '互动少',
+    '妆容差',
+    '发型乱',
+    '背景杂乱',
+    '动作僵硬',
+    '表情不自然',
+    '内容重复',
+    '没有创意',
+    '不幽默',
+  ];
+  positiveTags: Array<string> = [
+    '很礼貌',
+    '很好看',
+    '很专业',
+    '态度好',
+    '声音好听',
+    '内容有趣',
+    '互动多',
+    '妆容精致',
+    '发型时尚',
+    '背景整洁',
+    '动作自然',
+    '表情生动',
+    '内容新颖',
+    '有创意',
+    '很幽默',
+  ];
+  list: Array<string> = this.negativeTags;
+  checkTags = new Set();
   constructor(
-    public liveService: LiveService,
-  ) { }
+    private toastController: ToastController,
+    private loadingCtrl: LoadingController,
+    public liveService: LiveService
+  ) {}
 
-  ngOnInit() {
+  ngOnInit() {}
+  segmentChanged(e: any) {
+    let { value } = e.detail;
+    // this.active = value;
+    console.log(value);
+    this.list = this[value]
+    this.checkTags = new Set();
   }
-  confirm(){
-    
+  async onCheck(tag:string){
+    if(this.checkTags.has(tag)){
+      this.checkTags.delete(tag)
+    }else{
+      if(this.checkTags.size >= 3){
+        const toast = await this.toastController.create({
+          message: '不超过3项',
+          color: 'danger',
+          duration: 1000,
+        });
+        toast.present();
+        return;
+      }
+      this.checkTags.add(tag)
+    }
+  }
+  confirm() {
+    this.onComment()
+  }
+
+  async onComment() {
+    const loading = await this.loadingCtrl.create({
+      message: '加载中',
+    });
+    loading.present();
+    if(this.checkTags.size > 3 || this.checkTags.size == 0){
+      loading.dismiss();
+      const toast = await this.toastController.create({
+        message: this.checkTags.size == 0 ? '至少选择一项' : '不超过3项',
+        color: 'danger',
+        duration: 1000,
+      });
+      toast.present();
+      return;
+    }
+    let obj = Parse.Object.extend('DramaPostLog');
+    let postLog = new obj();
+    postLog.set('room', {
+      __type: 'Pointer',
+      className: 'Room',
+      objectId: this.liveService.room?.id,
+    });
+    postLog.set('company', {
+      __type: 'Pointer',
+      className: 'Company',
+      objectId: this.liveService?.company,
+    });
+    postLog.set('user', {
+      __type: 'Pointer',
+      className: '_User',
+      objectId: this.liveService.room?.get('user')?.id,
+    });
+    postLog.set('type', 'comment');
+    // postLog.set('credit', star)
+    postLog.set('tags',Array.from(this.checkTags))
+    await postLog.save();
+    loading.dismiss();
+    this.liveService.isOpenEvaluate = false;
+    this.checkTags = new Set();
   }
 }

+ 1 - 1
projects/live-app/src/app/components/gift-modal/gift-modal.component.ts

@@ -67,7 +67,7 @@ export class GiftModalComponent implements OnInit {
     public liveService: LiveService,
     private loadingCtrl: LoadingController,
     public accServ: AccountService,
-    public toastController: ToastController,
+    private toastController: ToastController,
     public msgSerrvice: MessageService
   ) {}
   async ngOnInit() {

+ 1 - 1
projects/live-app/src/app/components/live/live.component.ts

@@ -26,7 +26,7 @@ export class LiveComponent implements OnInit {
   changeScreen: boolean = false; //大小屏切换
   timer: any; //轮询获取频道token的定时
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     private loadingCtrl: LoadingController,
     private activateRoute: ActivatedRoute,
     private alertController: AlertController,

+ 1 - 1
projects/live-app/src/app/components/upload/upload.component.ts

@@ -66,7 +66,7 @@ export class UploadComponent implements OnInit {
   loading: any;
   currentPreviewImg:string = ''
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     public loadCtrl: LoadingController
   ) {
     Parse.Cloud.run('qiniu_uptoken', { company: this.company }).then((data) => {

+ 1 - 1
projects/live-app/src/modules/account/notice-log/notice-log.component.ts

@@ -25,7 +25,7 @@ export class NoticeLogComponent implements OnInit {
   user: Parse.Object = Parse.User.current()!;
 
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     private loadingCtrl: LoadingController,
     private router: Router,
     private msgSer: MessageService,

+ 1 - 1
projects/live-app/src/modules/account/recharge/recharge.component.ts

@@ -37,7 +37,7 @@ export class RechargeComponent implements OnInit {
   tradeNo: string = ''; //支付单号
   orderId?: string;
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     public loadingController: LoadingController,
     private router: Router
   ) {}

+ 1 - 1
projects/live-app/src/modules/goods/vip/vip.component.ts

@@ -44,7 +44,7 @@ export class VipComponent implements OnInit {
   loading: boolean = true;
   constructor(
     private modalController: ModalController,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private authSer: AuthService,
     private accServ: AccountService,
     private router: Router,

+ 1 - 1
projects/live-app/src/modules/live/chat/chat.component.ts

@@ -61,7 +61,7 @@ export class ChatComponent implements OnInit {
     private router: Router,
     private http: HttpClient,
     // public datePipe: DatePipe,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private alertController: AlertController,
     private loadingCtrl: LoadingController,
     private activateRoute: ActivatedRoute,

+ 6 - 5
projects/live-app/src/modules/live/link-page/link-page.component.ts

@@ -51,7 +51,7 @@ export class LinkPageComponent implements OnInit {
   loading: boolean = true;
   userVip: any;
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     private loadingCtrl: LoadingController,
     private alertController: AlertController,
     private activateRoute: ActivatedRoute,
@@ -209,11 +209,12 @@ export class LinkPageComponent implements OnInit {
           cssClass: 'secondary',
           handler: () => {
             console.log('Confirm Cancel: blah');
-            if (this.liveService.isAnchor) {
-              this.onExit();
+            this.onExit();
+            if (!this.liveService.isAnchor) {
+              this.liveService.isOpenEvaluate = true
               return;
             }
-            this.onComment();
+            // this.onComment();
           },
         },
       ],
@@ -291,7 +292,7 @@ export class LinkPageComponent implements OnInit {
   }
   onExit() {
     this.liveService.client.leave();
-    history.back();
+    // history.back();
   }
 
   ngOnDestroy(): void {

+ 1 - 1
projects/live-app/src/modules/live/room-manage/room-manage.component.ts

@@ -33,7 +33,7 @@ export class RoomManageComponent implements OnInit {
   profile?: Parse.Object
   initLoad:boolean = true;
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     private loadingCtrl: LoadingController,
     private liveService: LiveService,
     private alertController: AlertController,

+ 1 - 1
projects/live-app/src/modules/live/search/search.component.ts

@@ -26,7 +26,7 @@ export class SearchComponent implements OnInit {
   constructor(
     private aiServ: AiChatService,
     private router: Router,
-    public toastController: ToastController
+    private toastController: ToastController
   ) {}
 
   async presentToast(message: string) {

+ 38 - 0
projects/live-app/src/modules/login/auth.guard.ts

@@ -0,0 +1,38 @@
+import { Injectable } from '@angular/core';
+import {
+  CanActivate,
+  ActivatedRouteSnapshot,
+  RouterStateSnapshot,
+} from '@angular/router';
+import { Observable } from 'rxjs';
+import { Router } from '@angular/router';
+import Parse from 'parse';
+
+@Injectable({
+  providedIn: 'root',
+})
+export class LoginAuthGuard implements CanActivate {
+  LoginPage = 'tabs';
+
+  constructor(public router: Router) {}
+
+  canActivate(
+    next: ActivatedRouteSnapshot,
+    state: RouterStateSnapshot
+  ): Observable<boolean> | Promise<boolean> | boolean {
+    // 当前路由url
+    // let url: string = state.url;
+    return this.checkLogin();
+  }
+  checkLogin(): boolean {
+    // 如果已登录,直接跳转首页
+    let currentUser = Parse.User.current();
+    if (currentUser?.id) {
+      // 否则重定向到login页面
+      this.router.navigate([this.LoginPage]);
+      return false;
+    }
+    return true;
+  }
+}
+export { CanActivate };

+ 1 - 1
projects/live-app/src/modules/login/login.component.ts

@@ -35,7 +35,7 @@ export class LoginComponent implements OnInit {
   };
   currentUser: any;
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     public authServ: AuthService,
     // private router: Router,
     private activatedRoute: ActivatedRoute,

+ 1 - 1
projects/live-app/src/modules/tabs/anthorhome/anthorhome.component.ts

@@ -68,7 +68,7 @@ export class AnthorhomeComponent implements OnInit {
     private activateRoute: ActivatedRoute,
     private connectTask: ConnectTaskService,
     private router: Router,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private aiServ: AiChatService,
     private msgSer: MessageService,
     private datePipe: DatePipe

+ 2 - 1
projects/live-app/src/modules/tabs/my/my.component.ts

@@ -27,7 +27,7 @@ export class MyComponent implements OnInit {
     private modalController: ModalController,
     private alertController: AlertController,
     public authServ: AuthService,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private activateRoute: ActivatedRoute,
     private router: Router,
     public aiServ: AiChatService,
@@ -209,6 +209,7 @@ export class MyComponent implements OnInit {
       cssClass: 'my-custom-class',
       header: '',
       message: '你确定退出登录吗?',
+      backdropDismiss:false,
       buttons: [
         {
           text: '确定',

+ 1 - 1
projects/live-app/src/modules/user/album/album.component.ts

@@ -22,7 +22,7 @@ export class AlbumComponent implements OnInit {
   loading: boolean = false;
   constructor(
     public loadCtrl: LoadingController,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private authServ: AuthService
   ) {}
   ngOnInit() {

+ 1 - 1
projects/live-app/src/modules/user/anchor/anchor.component.ts

@@ -54,7 +54,7 @@ export class AnchorComponent implements OnInit {
   constructor(
     private modalController: ModalController,
     public loadingCtrl: LoadingController,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private authServ: AuthService,
     private alertController: AlertController,
     private router: Router,

+ 1 - 1
projects/live-app/src/modules/user/certification/certification.component.ts

@@ -52,7 +52,7 @@ export class CertificationComponent implements OnInit {
     public loadCtrl: LoadingController,
     private modalController: ModalController,
     private alertController: AlertController,
-    public toastController: ToastController
+    private toastController: ToastController
   ) {}
 
   ngOnInit() {

+ 5 - 1
projects/live-app/src/modules/user/comment/comment.component.html

@@ -18,7 +18,11 @@
           LV{{ item?.get("user").get("achievementCount") }}
         </div>
       </div>
-      <div class="li-score">{{ item?.get("comment") }}</div>
+      <div class="li-score">
+        @for(i of item?.get("tags"); track $index){
+        <span>{{ i }}</span>
+        }
+      </div>
     </div>
     }
   </div>

+ 7 - 3
projects/live-app/src/modules/user/comment/comment.component.scss

@@ -38,9 +38,13 @@
       }
       .li-score{
         font-size: 12px;
-        background-color: #c509ff;
-        padding: 2px 4px;
-        color: white;
+        span{
+          background-color: #c509ff;
+          padding: 2px 4px;
+          color: white;
+          margin-left: 2px;
+          border-radius: 4px;
+        }
       }
     }
   }

+ 1 - 1
projects/live-app/src/modules/user/feedback/feedback.component.ts

@@ -21,7 +21,7 @@ export class FeedbackComponent implements OnInit {
   company: string | null = '';
   constructor(
     private authServ: AuthService,
-    public toastController: ToastController
+    private toastController: ToastController
   ) {
     this.company = authServ.company;
   }

+ 19 - 11
projects/live-app/src/modules/user/profile/profile.component.html

@@ -154,11 +154,13 @@
       <div class="comment-room">
         <div class="title-text comment-title">
           <div class="coulum">
-            对ta的评价({{
-              commentObj.score ? commentObj.score + "分" : "暂无评价"
-            }})
+            对ta的评价
+            <!-- ({{ commentObj.score ? commentObj.score + "分" : "暂无评价"}}) -->
           </div>
-          <div class="coulum" (click)="tourl('/user/comment',{rid: this.room?.id})">
+          <div
+            class="coulum"
+            (click)="tourl('/user/comment', { rid: this.room?.id })"
+          >
             {{ commentObj.count }}条<ion-icon
               name="chevron-forward-outline"
             ></ion-icon>
@@ -187,18 +189,24 @@
                 LV{{ item?.get("user").get("achievementCount") }}
               </div>
             </div>
-            <div class="li-score">{{ item?.get("comment") }}</div>
+            <div class="li-score">
+              @for(i of item?.get("tags"); track $index){
+              <span>{{ i }}</span>
+              }
+            </div>
           </div>
           }
         </div>
       </div>
     </div>
     <div class="data-row">
-      <div class="title-text flex">ta的礼物墙
-        <div class="coulum" (click)="tourl('/user/income',{uid: profile?.get('user')?.id})">
-          <ion-icon
-            name="chevron-forward-outline"
-          ></ion-icon>
+      <div class="title-text flex">
+        ta的礼物墙
+        <div
+          class="coulum"
+          (click)="tourl('/user/income', { uid: profile?.get('user')?.id })"
+        >
+          <ion-icon name="chevron-forward-outline"></ion-icon>
         </div>
       </div>
       <div class="gift">
@@ -298,4 +306,4 @@
 @if(profile?.id){
 <app-call-modal #call [profile]="profile"></app-call-modal>
 }
-<app-appraise></app-appraise>
+<app-appraise></app-appraise>

+ 7 - 3
projects/live-app/src/modules/user/profile/profile.component.scss

@@ -252,9 +252,13 @@
             }
             .li-score{
               font-size: 12px;
-              background-color: #c509ff;
-              padding: 2px 4px;
-              color: white;
+              span{
+                background-color: #c509ff;
+                padding: 2px 4px;
+                color: white;
+                margin-left: 2px;
+                border-radius: 4px;
+              }
             }
           }
         }

+ 1 - 1
projects/live-app/src/modules/user/profile/profile.component.ts

@@ -192,7 +192,7 @@ export class ProfileComponent implements OnInit {
     let r = await query.first();
     if(r?.id){
       this.room = r;
-      this.commentObj.score = await this.aiChatServ.getCommentScore(r?.id);
+      // this.commentObj.score = await this.aiChatServ.getCommentScore(r?.id);
       let queryPost = new Parse.Query('DramaPostLog');
       queryPost.equalTo('room', r.id);
       queryPost.notEqualTo('isDeleted', true);

+ 1 - 1
projects/live-app/src/modules/user/setting/setting.component.ts

@@ -107,7 +107,7 @@ export class SettingComponent implements OnInit {
   constructor(
     private alertController: AlertController,
     public loadingCtrl: LoadingController,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private authServ: AuthService,
     private accServ: AccountService,
     // private router: Router

+ 1 - 1
projects/live-app/src/modules/user/share/share.component.ts

@@ -21,7 +21,7 @@ export class ShareComponent implements OnInit {
     'https://file-cloud.fmode.cn/Qje9D4bqol/20241220/qvj1bm054428527.png';
   codeUrl: string = '';
   constructor(
-    public toastController: ToastController,
+    private toastController: ToastController,
     private http: HttpClient
   ) {}
 

+ 8 - 2
projects/live-app/src/services/auth.service.ts

@@ -5,6 +5,8 @@ import { MessageService } from './message.service';
 import { ConnectTaskService } from './connectTask.service';
 import { HttpClient } from '@angular/common/http';
 import { catchError } from 'rxjs/operators';
+import { NavController } from '@ionic/angular';
+import { Location } from '@angular/common';
 @Injectable({
   providedIn: 'root',
 })
@@ -15,7 +17,9 @@ export class AuthService {
     private connectTask: ConnectTaskService,
     private router: Router,
     private msgSer: MessageService,
-    private http: HttpClient
+    private http: HttpClient,
+    private navCtrl: NavController,
+    private location: Location,
   ) {}
   authMobile(
     mobile: string,
@@ -117,7 +121,9 @@ export class AuthService {
       this.msgSer?.logOutRTM();
       this.msgSer?.reset();
       this.connectTask?.reset();
-      this.router.navigate(['login']);
+      // this.router.navigate(['login']);
+      this.navCtrl.navigateRoot('/login', { animated: false });
+      this.location.replaceState('/login');
     });
   }
 }

+ 26 - 14
projects/live-app/src/services/live.service.ts

@@ -1,4 +1,5 @@
 import { Injectable } from '@angular/core';
+import { Router } from '@angular/router';
 import { AlertController } from '@ionic/angular';
 import * as Parse from 'parse';
 import { AiChatService } from './aichart.service';
@@ -56,11 +57,12 @@ export class LiveService {
   countdown: number = 0; // 新增倒计时变量
   timer_countdown: any;
   liveLog?: Parse.Object; //直播记录
-  
-  isOpenEvaluate:boolean = false; //是否开启评价
+
+  isOpenEvaluate: boolean = false; //是否开启评价
 
   constructor(
     private http: HttpService,
+    private router: Router,
     private aiServ: AiChatService,
     private alertController: AlertController,
     private msgSer: MessageService
@@ -227,8 +229,9 @@ export class LiveService {
       await this.client.publish(Object.values(this.localTracks));
     } catch (err) {
       console.log('发布本地视频失败:', err);
-      history.back()
-      this.alertTips('发布本地视频失败', '提示');
+      // history.back()
+      this.alertTips('发布本地视频失败,请检查摄像头是否授权或正常', '提示');
+      this.client.leave();
     }
   }
   /* 订阅远程视频 */
@@ -280,9 +283,9 @@ export class LiveService {
         }
         //主播离开,停止计时计费
         // if (!this.isAnchor) {
-          this.client.leave();
+        this.client.leave();
         // }
-        history.back()
+        // history.back()
         this.alertTips('对方已离开直播间');
       }
     });
@@ -300,7 +303,11 @@ export class LiveService {
           if (!this.isAnchor) {
             //用户离开直播间,断开与主播状态连接频道
             this.msgSer.unsubscribeMessage(this.room?.get('user')?.id);
+            this.isOpenEvaluate = true;
           }
+          console.log(this.router.url);
+          if(this.router.url.indexOf('/live/link-room/') == 0)
+          curState == 'DISCONNECTED' && history.back();
         }
         console.log('live状态变更:', this.connection_state);
       }
@@ -339,7 +346,9 @@ export class LiveService {
   async afterJoin() {
     this.timer && clearTimeout(this.timer);
     this.timer_countdown && clearInterval(this.timer_countdown);
-    const targetUser = this.client.remoteUsers?.find((user: any) => user.uid !== 100001) //排出超管
+    const targetUser = this.client.remoteUsers?.find(
+      (user: any) => user.uid !== 100001
+    ); //排出超管
     console.log(targetUser);
     if (this.client.remoteUsers.length > 0 && targetUser) {
       if (this.isAnchor) {
@@ -368,7 +377,7 @@ export class LiveService {
       }, 1000);
     }
   }
-  async getLiveLog(tarUid:string) {
+  async getLiveLog(tarUid: string) {
     // let uid = this.client.remoteUsers[0].uid;
     this.timer && clearTimeout(this.timer);
     let query = new Parse.Query('LiveLog');
@@ -382,7 +391,7 @@ export class LiveService {
       this.liveLog?.set('isLive', true);
       await this.liveLog?.save();
       await this.get_duration();
-      this.getCallDuration()
+      this.getCallDuration();
       return;
     }
     this.timer = setTimeout(() => {
@@ -416,7 +425,7 @@ export class LiveService {
         // console.log(this.countdown);
       } else {
         clearInterval(this.timer_countdown);
-        history.back()
+        // history.back()
         this.alertTips('通话时间结束');
         this.client.leave(); // 结束通话
       }
@@ -444,12 +453,15 @@ export class LiveService {
     }, num ?? 10000);
   }
   /* 主播每10s获取一次对方可通话时长 */
-  getCallDuration(){
+  getCallDuration() {
     this.timer && clearTimeout(this.timer);
-    this.timer = setTimeout(async() => {
+    this.timer = setTimeout(async () => {
       await this.get_duration();
-      this.getCallDuration();
-    },10000);
+      let arr = ['CONNECTING', 'CONNECTED'];
+      if (arr.includes(this.connection_state as any)) {
+        this.getCallDuration();
+      }
+    }, 10000);
   }
   /* 监听音视频设备插拔 */
   monitorDevices() {

+ 1 - 1
projects/live-app/src/services/message.service.ts

@@ -47,7 +47,7 @@ export class MessageService {
   constructor(
     private alertController: AlertController,
     private router: Router,
-    public toastController: ToastController,
+    private toastController: ToastController,
     private http: HttpService,
     private aiServ: AiChatService
   ) {