From b64f32080537840cfd772d14dfc1df1ccddc4330 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 01 七月 2023 18:10:33 +0800
Subject: [PATCH] 优化发流逻辑

---
 web_src/src/components/dialog/recordDownload.vue |   39 +++++++++++++++++++++++++++------------
 1 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/web_src/src/components/dialog/recordDownload.vue b/web_src/src/components/dialog/recordDownload.vue
index 4677487..7a94540 100644
--- a/web_src/src/components/dialog/recordDownload.vue
+++ b/web_src/src/components/dialog/recordDownload.vue
@@ -7,6 +7,7 @@
       </el-col>
       <el-col :span="6" >
         <el-button icon="el-icon-download" v-if="percentage < 100" size="mini" title="鐐瑰嚮涓嬭浇鍙皢浠ョ紦瀛橀儴鍒嗕笅杞藉埌鏈湴" @click="download()">鍋滄缂撳瓨骞朵笅杞�</el-button>
+        <el-button icon="el-icon-download" v-if="downloadFile" size="mini" title="鐐瑰嚮涓嬭浇" @click="downloadFileClientEvent()">鐐瑰嚮涓嬭浇</el-button>
       </el-col>
     </el-row>
   </el-dialog>
@@ -21,7 +22,7 @@
 export default {
     name: 'recordDownload',
     created() {
-
+      window.addEventListener('beforeunload', this.stopDownloadRecord)
 
     },
     data() {
@@ -39,7 +40,8 @@
           taskId: null,
           getProgressRun: false,
           getProgressForFileRun: false,
-          timer: null
+          timer: null,
+          downloadFile: null,
 
         };
     },
@@ -71,7 +73,7 @@
         getProgress: function (callback){
           this.$axios({
             method: 'get',
-            url: `./api/gb_record/download/progress/${this.deviceId}/${this.channelId}/${this.stream}`
+            url: `/api/gb_record/download/progress/${this.deviceId}/${this.channelId}/${this.stream}`
           }).then((res)=> {
             console.log(res)
               if (res.data.code === 0) {
@@ -96,7 +98,10 @@
           });
         },
         close: function (){
-          this.stopDownloadRecord();
+          if (this.streamInfo.progress < 1) {
+            this.stopDownloadRecord();
+          }
+
           if (this.timer !== null) {
             window.clearTimeout(this.timer);
             this.timer = null;
@@ -124,7 +129,7 @@
         stopDownloadRecord: function (callback) {
           this.$axios({
             method: 'get',
-            url: './api/gb_record/download/stop/' + this.deviceId + "/" + this.channelId+ "/" + this.stream
+            url: '/api/gb_record/download/stop/' + this.deviceId + "/" + this.channelId+ "/" + this.stream
           }).then((res)=> {
             if (callback) callback(res)
           });
@@ -132,7 +137,7 @@
         getFileDownload: function (){
           this.$axios({
             method: 'get',
-            url:`./record_proxy/${this.mediaServerId}/api/record/file/download/task/add`,
+            url:`/record_proxy/${this.mediaServerId}/api/record/file/download/task/add`,
             params: {
               app: this.app,
               stream: this.stream,
@@ -158,13 +163,13 @@
           }
           setTimeout( ()=>{
             if (!this.showDialog) return;
-            this.getProgressForFile(this.getProgressForFileTimer())
+            this.getProgressForFile(this.getProgressForFileTimer)
           }, 1000)
         },
         getProgressForFile: function (callback){
           this.$axios({
             method: 'get',
-            url:`./record_proxy/${this.mediaServerId}/api/record/file/download/task/list`,
+            url:`/record_proxy/${this.mediaServerId}/api/record/file/download/task/list`,
             params: {
               app: this.app,
               stream: this.stream,
@@ -176,13 +181,17 @@
             if (res.data.code === 0) {
               if (res.data.data.length === 0){
                 this.percentage = 0
+                // 寰�寰�鍦ㄥ娆¤姹傚悗锛堝疄楠屼簲鍒嗛挓鐨勮棰戞槸涓夋璇锋眰锛夛紝鎵嶄細杩斿洖鏁版嵁锛岀涓�娆¤姹傞�氬父鏄繑鍥炵┖鏁扮粍
+                if (callback)callback()
                 return
               }
-                this.percentage = parseFloat(res.data.data.percentage)*100
+              // res.data.data搴旀槸鏁扮粍绫诲瀷
+                this.percentage = parseFloat(res.data.data[0].percentage)*100
                  if (res.data.data[0].percentage === '1') {
                    this.getProgressForFileRun = false;
-                   window.open(res.data.data[0].downloadFile)
-                   this.close();
+                   this.downloadFile = res.data.data[0].downloadFile
+                   this.title = "鏂囦欢澶勭悊瀹屾垚锛岀偣鍑绘寜鎵笅杞�"
+                   // window.open(res.data.data[0].downloadFile)
                  }else {
                    if (callback)callback()
                  }
@@ -190,7 +199,13 @@
           }).catch(function (error) {
             console.log(error);
           });
-        }
+        },
+      downloadFileClientEvent: function (){
+        window.open(this.downloadFile )
+      }
+    },
+    destroyed() {
+      window.removeEventListener('beforeunload', this.stopDownloadRecord)
     }
 };
 </script>

--
Gitblit v1.8.0