recordDownload.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div id="recordDownload" >
  3. <el-dialog :title="title" v-if="showDialog" width="45rem" :append-to-body="true" :close-on-click-modal="false" :visible.sync="showDialog" :destroy-on-close="true" @close="close()" center>
  4. <el-row>
  5. <el-col :span="18" style="padding-top: 7px;">
  6. <el-progress :percentage="percentage"></el-progress>
  7. </el-col>
  8. <el-col :span="6" >
  9. <el-button icon="el-icon-download" v-if="percentage < 100" size="mini" title="点击下载可将以缓存部分下载到本地" @click="download()">停止缓存并下载</el-button>
  10. </el-col>
  11. </el-row>
  12. </el-dialog>
  13. </div>
  14. </template>
  15. <script>
  16. import moment from "moment";
  17. export default {
  18. name: 'recordDownload',
  19. created() {
  20. },
  21. data() {
  22. return {
  23. title: "四倍速下载中...",
  24. deviceId: "",
  25. channelId: "",
  26. app: "",
  27. stream: "",
  28. mediaServerId: "",
  29. showDialog: false,
  30. scale: 1,
  31. percentage: 0.00,
  32. streamInfo: null,
  33. taskId: null,
  34. getProgressRun: false,
  35. getProgressForFileRun: false,
  36. timer: null
  37. };
  38. },
  39. methods: {
  40. openDialog: function (deviceId, channelId, app, stream, mediaServerId) {
  41. this.deviceId = deviceId;
  42. this.channelId = channelId;
  43. this.app = app;
  44. this.stream = stream;
  45. this.mediaServerId = mediaServerId;
  46. this.showDialog = true;
  47. this.getProgressRun = true;
  48. this.percentage = 0.0;
  49. this.getProgressTimer()
  50. },
  51. getProgressTimer: function (){
  52. if (!this.getProgressRun) {
  53. return;
  54. }
  55. if (this.percentage == 100 ) {
  56. this.getFileDownload();
  57. return;
  58. }
  59. setTimeout( ()=>{
  60. if (!this.showDialog) return;
  61. this.getProgress(this.getProgressTimer())
  62. }, 5000)
  63. },
  64. getProgress: function (callback){
  65. this.$axios({
  66. method: 'get',
  67. url: `/api/gb_record/download/progress/${this.deviceId}/${this.channelId}/${this.stream}`
  68. }).then((res)=> {
  69. console.log(res)
  70. if (res.data.code === 0) {
  71. this.streamInfo = res.data.data;
  72. if (parseFloat(res.data.progress) == 1) {
  73. this.percentage = 100;
  74. }else {
  75. this.percentage = (parseFloat(res.data.data.progress)*100).toFixed(1);
  76. }
  77. if (callback)callback();
  78. }else {
  79. this.$message({
  80. showClose: true,
  81. message: res.data.msg,
  82. type: "error",
  83. });
  84. this.close();
  85. }
  86. }).catch((e) =>{
  87. console.log(e)
  88. });
  89. },
  90. close: function (){
  91. this.stopDownloadRecord();
  92. if (this.timer !== null) {
  93. window.clearTimeout(this.timer);
  94. this.timer = null;
  95. }
  96. this.showDialog=false;
  97. this.getProgressRun = false;
  98. this.getProgressForFileRun = false;
  99. },
  100. gbScale: function (scale){
  101. this.scale = scale;
  102. },
  103. download: function (){
  104. this.getProgressRun = false;
  105. if (this.streamInfo != null ) {
  106. if (this.streamInfo.progress < 1) {
  107. // 发送停止缓存
  108. this.stopDownloadRecord((res)=>{
  109. this.getFileDownload()
  110. })
  111. }else {
  112. this.getFileDownload()
  113. }
  114. }
  115. },
  116. stopDownloadRecord: function (callback) {
  117. this.$axios({
  118. method: 'get',
  119. url: '/api/gb_record/download/stop/' + this.deviceId + "/" + this.channelId+ "/" + this.stream
  120. }).then((res)=> {
  121. if (callback) callback(res)
  122. });
  123. },
  124. getFileDownload: function (){
  125. this.$axios({
  126. method: 'get',
  127. url:`/record_proxy/${this.mediaServerId}/api/record/file/download/task/add`,
  128. params: {
  129. app: this.app,
  130. stream: this.stream,
  131. startTime: null,
  132. endTime: null,
  133. }
  134. }).then((res) =>{
  135. if (res.data.code === 0 ) {
  136. // 查询进度
  137. this.title = "录像文件处理中..."
  138. this.taskId = res.data.data;
  139. this.percentage = 0.0;
  140. this.getProgressForFileRun = true;
  141. this.getProgressForFileTimer();
  142. }
  143. }).catch(function (error) {
  144. console.log(error);
  145. });
  146. },
  147. getProgressForFileTimer: function (){
  148. if (!this.getProgressForFileRun || this.percentage == 100) {
  149. return;
  150. }
  151. setTimeout( ()=>{
  152. if (!this.showDialog) return;
  153. this.getProgressForFile(this.getProgressForFileTimer())
  154. }, 1000)
  155. },
  156. getProgressForFile: function (callback){
  157. this.$axios({
  158. method: 'get',
  159. url:`/record_proxy/${this.mediaServerId}/api/record/file/download/task/list`,
  160. params: {
  161. app: this.app,
  162. stream: this.stream,
  163. taskId: this.taskId,
  164. isEnd: true,
  165. }
  166. }).then((res) => {
  167. console.log(res)
  168. if (res.data.code === 0) {
  169. if (res.data.data.length === 0){
  170. this.percentage = 0
  171. return
  172. }
  173. this.percentage = parseFloat(res.data.data.percentage)*100
  174. if (res.data.data[0].percentage === '1') {
  175. this.getProgressForFileRun = false;
  176. window.open(res.data.data[0].downloadFile)
  177. this.close();
  178. }else {
  179. if (callback)callback()
  180. }
  181. }
  182. }).catch(function (error) {
  183. console.log(error);
  184. });
  185. }
  186. }
  187. };
  188. </script>
  189. <style>
  190. </style>