2
0

PlaybackDownloadDlg.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div :class="['modal', { fade: fade }]" data-keyboard="true" data-backdrop="static" tabindex="-1">
  3. <div class="modal-dialog modal-md">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  7. <span aria-hidden="true">&times;</span>
  8. </button>
  9. <h4 class="modal-title text-primary text-center"><span>{{title}}</span></h4>
  10. </div>
  11. <div class="modal-body">
  12. <el-progress :text-inside="true" :stroke-width="18" :percentage="progress"></el-progress>
  13. </div>
  14. <div class="modal-footer">
  15. <button type="button" class="btn btn-primary" @click.prevent="scale(1)">x1</button>
  16. <button type="button" class="btn btn-primary" @click.prevent="scale(2)">x2</button>
  17. <button type="button" class="btn btn-primary" @click.prevent="scale(4)">x4</button>
  18. <button type="button" class="btn btn-default" @click.prevent="hide" :disabled="disabled">{{btnText}}</button>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. bShow: false,
  29. timer: 0,
  30. title: "",
  31. streamID: "",
  32. progress: 0,
  33. fileUrl: ""
  34. };
  35. },
  36. props: {
  37. fade: {
  38. type: Boolean,
  39. default: false
  40. },
  41. disabled: {
  42. type: Boolean,
  43. default: false
  44. }
  45. },
  46. computed: {
  47. btnText() {
  48. return this.fileUrl ? "下载" : "关闭";
  49. }
  50. },
  51. mounted() {
  52. $(this.$el)
  53. .find(".modal-content")
  54. .draggable({
  55. handle: ".modal-header",
  56. cancel: ".modal-title span",
  57. addClasses: false,
  58. containment: "document",
  59. delay: 100,
  60. opacity: 0.5
  61. });
  62. $(this.$el).on("shown.bs.modal", () => {
  63. this.bShow = true;
  64. this.$emit("show");
  65. if(this.streamID) {
  66. this.timer = setInterval(() => {
  67. $.ajax({
  68. type: "GET",
  69. url: "/api/v1/playback/streaminfo",
  70. data: {
  71. streamid: this.streamID
  72. },
  73. global: false
  74. }).then(ret => {
  75. this.progress = Math.ceil(ret.Progress * 100)
  76. this.fileUrl = ret.PlaybackFileURL;
  77. }).fail(() => {
  78. this.progress = 100;
  79. })
  80. }, 3000);
  81. }
  82. }).on("hidden.bs.modal", () => {
  83. this.bShow = false;
  84. this.$emit("hide");
  85. if(this.timer) {
  86. clearInterval(this.timer);
  87. this.timer = 0;
  88. }
  89. if(this.streamID) {
  90. $.get("/api/v1/playback/stop", {
  91. streamid: this.streamID
  92. }).then(() => {
  93. }).always(() => {
  94. if(this.fileUrl) {
  95. window.open(this.fileUrl, "_blank");
  96. this.fileUrl = "";
  97. }
  98. this.streamID = "";
  99. })
  100. }
  101. })
  102. },
  103. beforeDestroy() {
  104. if (this.timer) {
  105. clearInterval(this.timer);
  106. this.timer = 0;
  107. }
  108. },
  109. methods: {
  110. show() {
  111. $(this.$el).modal("show");
  112. },
  113. hide() {
  114. $(this.$el).modal("hide");
  115. },
  116. doSubmit() {
  117. this.$emit("submit");
  118. },
  119. download(title, streamID) {
  120. this.title = title;
  121. this.streamID = streamID;
  122. this.fileUrl = "";
  123. this.progress = 0;
  124. $(this.$el).modal("show");
  125. },
  126. scale(speed) {
  127. $.get("/api/v1/playback/control", {
  128. streamid: this.streamID,
  129. command: "scale",
  130. scale: speed
  131. })
  132. }
  133. }
  134. };
  135. </script>
  136. <style lang="less" scoped>
  137. .modal-title {
  138. overflow: hidden;
  139. white-space: nowrap;
  140. text-overflow: ellipsis;
  141. }
  142. </style>