recordDownload.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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-dropdown size="mini" title="播放倍速" style="margin-left: 1px;" @command="gbScale">-->
  10. <!-- <el-button-group>-->
  11. <!-- <el-button size="mini" style="width: 100%">-->
  12. <!-- {{scale}}倍速 <i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
  13. <!-- </el-button>-->
  14. <!-- </el-button-group>-->
  15. <!-- <el-dropdown-menu slot="dropdown">-->
  16. <!-- <el-dropdown-item command="1">1倍速</el-dropdown-item>-->
  17. <!-- <el-dropdown-item command="2">2倍速</el-dropdown-item>-->
  18. <!-- <el-dropdown-item command="4">4倍速</el-dropdown-item>-->
  19. <!-- </el-dropdown-menu>-->
  20. <!-- </el-dropdown>-->
  21. <el-button icon="el-icon-download" v-if="percentage < 100" size="mini" title="点击下载可将以缓存部分下载到本地" @click="download()">停止缓存并下载</el-button>
  22. </el-col>
  23. </el-row>
  24. </el-dialog>
  25. </div>
  26. </template>
  27. <script>
  28. import moment from "moment";
  29. export default {
  30. name: 'recordDownload',
  31. created() {
  32. },
  33. data() {
  34. return {
  35. title: "四倍速下载中...",
  36. deviceId: "",
  37. channelId: "",
  38. app: "",
  39. stream: "",
  40. mediaServerId: "",
  41. showDialog: false,
  42. scale: 1,
  43. percentage: 0.00,
  44. streamInfo: null,
  45. taskId: null,
  46. getProgressRun: false,
  47. getProgressForFileRun: false,
  48. };
  49. },
  50. methods: {
  51. openDialog: function (deviceId, channelId, app, stream, mediaServerId) {
  52. this.deviceId = deviceId;
  53. this.channelId = channelId;
  54. this.app = app;
  55. this.stream = stream;
  56. this.mediaServerId = mediaServerId;
  57. this.showDialog = true;
  58. this.getProgressRun = true;
  59. this.percentage = 0.0;
  60. this.getProgressTimer()
  61. },
  62. getProgressTimer(){
  63. if (!this.getProgressRun) {
  64. return;
  65. }
  66. if (this.percentage == 100 ) {
  67. this.getFileDownload();
  68. return;
  69. }
  70. setTimeout( ()=>{
  71. if (!this.showDialog) return;
  72. this.getProgress(this.getProgressTimer())
  73. }, 5000)
  74. },
  75. getProgress: function (callback){
  76. this.$axios({
  77. method: 'get',
  78. url: `/api/gb_record/download/progress/${this.deviceId}/${this.channelId}/${this.stream}`
  79. }).then((res)=> {
  80. console.log(res)
  81. console.log(res.data.progress)
  82. this.streamInfo = res.data;
  83. if (parseFloat(res.data.progress) == 1) {
  84. this.percentage = 100;
  85. }else {
  86. this.percentage = (res.data.progress*100).toFixed(1);
  87. }
  88. if (callback)callback();
  89. }).catch((e) =>{
  90. });
  91. },
  92. close: function (){
  93. if (this.streamInfo.progress < 100) {
  94. this.stopDownloadRecord();
  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 && res.data.msg === "success") {
  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. this.percentage = parseFloat(res.data.data.percentage)*100
  170. if (res.data.data[0].percentage === '1') {
  171. this.getProgressForFileRun = false;
  172. window.open(res.data.data[0].downloadFile)
  173. this.close();
  174. }else {
  175. if (callback)callback()
  176. }
  177. }
  178. }).catch(function (error) {
  179. console.log(error);
  180. });
  181. }
  182. }
  183. };
  184. </script>
  185. <style>
  186. </style>