2
0

CloudRecordTimeBox.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="box box-primary records">
  3. <div class="box-header">
  4. <h4 class="text-primary text-center">云端录像({{ name }})-时间轴视图</h4>
  5. </div>
  6. <div class="box-body">
  7. <div class="form-inline">
  8. <div class="form-group">
  9. <button type="button" class="btn btn-primary btn-sm" @click.prevent="$router.go(-1)"> <i class="fa fa-chevron-left"></i> 返回 </button>
  10. </div>
  11. <div class="form-group pull-right">
  12. <div class="input-group input-group-sm">
  13. <CloudRecordDatePicker class="form-control" :day="day" @update:day="updateDay" ref="datePicker" :serial="serial" :code="code"></CloudRecordDatePicker>
  14. <div class="input-group-btn">
  15. <button type="button" class="btn btn-sm btn-default" @click.prevent="showCloudRecordDatePicker"> <i class="fa fa-calendar"></i> </button>
  16. <router-link :to="`/cloudrecord/listview/${this.serial}/${this.code}/${this.day}`" replace class="btn btn-default btn-sm">
  17. <i class="fa fa-hand-o-right"></i> 列表视图
  18. </router-link>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. <br>
  24. <div class="clearfix"></div>
  25. <LivePlayer :videoUrl="videoUrl" muted :currentTime="currentTime" @ended="onVideoEnd" @timeupdate="onVideoTimeUpdate" style="margin:0 auto; max-width:700px;" :loading.sync="loading" v-loading="loading" element-loading-text="加载中" element-loading-background="#000"></LivePlayer>
  26. <div class="text-center" v-if="isDemoUser(serverInfo, userInfo)">
  27. <br>
  28. 提示: 演示系统限制匿名登录播放时间, 若需测试长时间播放, 请<a target="_blank" href="//www.liveqing.com/docs/download/LiveGBS.html">下载使用</a>
  29. </div>
  30. <br>
  31. <br>
  32. <CloudRecordTimeRule :videos="videos" @timeChange="onTimeChange" ref="timeRule" v-loading="loadingRecords"></CloudRecordTimeRule>
  33. <br>
  34. </div>
  35. <div class="box-footer clearfix">
  36. <br>
  37. </div>
  38. </div>
  39. </template>
  40. <script>
  41. import moment from 'moment'
  42. import CloudRecordDatePicker from 'components/CloudRecordDatePicker.vue'
  43. import CloudRecordTimeRule from 'components/CloudRecordTimeRule.vue'
  44. import LivePlayer from '@liveqing/liveplayer'
  45. import {
  46. mapState
  47. } from "vuex";
  48. export default {
  49. props: {
  50. serial: '',
  51. code: '',
  52. day: ''
  53. },
  54. data() {
  55. return {
  56. videos: [],
  57. videoUrl: "",
  58. currentTime: 0,
  59. bActive: false,
  60. loading: false,
  61. loadingRecords: false,
  62. name: '',
  63. pathname: location.pathname == "/" ? "" : location.pathname.substring(0, location.pathname.length - 1)
  64. }
  65. },
  66. components: {
  67. CloudRecordDatePicker,
  68. LivePlayer,
  69. CloudRecordTimeRule
  70. },
  71. methods: {
  72. updateDay(day) {
  73. this.$router.replace(`/cloudrecord/timeview/${this.serial}/${this.code}/${day}`);
  74. },
  75. showCloudRecordDatePicker() {
  76. $(this.$refs['datePicker'].$el).focus();
  77. },
  78. updateVideos() {
  79. this.loadingRecords = true;
  80. $.get("/api/v1/cloudrecord/querydaily", {
  81. serial: this.serial,
  82. code: this.code,
  83. period: this.day
  84. }).then(data => {
  85. this.name = data.name || `${this.serial}:${this.code}`;
  86. this.videos = data.list;
  87. }).always(() => {
  88. this.loadingRecords = false;
  89. })
  90. },
  91. onTimeChange(video) {
  92. this.videoUrl = this.pathname + ((video || {}).hls || "");
  93. this.currentTime = (video || {}).currentTime || 0;
  94. },
  95. onVideoEnd() {
  96. var idx = this.videoUrls.indexOf(this.videoUrl);
  97. if (idx >= 0 && idx < this.videos.length - 1) {
  98. var nextVideo = this.videos[idx + 1];
  99. if (!nextVideo) return;
  100. var startTime = moment(nextVideo.startAt, 'YYYYMMDDHHmmss');
  101. var n = startTime.diff(startTime.clone().startOf('day'), 'minutes');
  102. this.$refs['timeRule'].clickMinute(n);
  103. }
  104. },
  105. onVideoTimeUpdate(currentTime) {
  106. var idx = this.videoUrls.indexOf(this.videoUrl);
  107. if (idx >= 0 && idx < this.videos.length) {
  108. var video = this.videos[idx];
  109. var startTime = moment(video.startAt, 'YYYYMMDDHHmmss');
  110. startTime.add(currentTime, 'seconds');
  111. var n = startTime.diff(startTime.clone().startOf('day'), 'minutes');
  112. this.$refs['timeRule'].clickMinute(n, false);
  113. }
  114. }
  115. },
  116. computed: {
  117. ...mapState(['userInfo', 'serverInfo']),
  118. videoUrls() {
  119. return this.videos.map((val, index, array) => {
  120. return (val || {}).hls;
  121. });
  122. }
  123. },
  124. mounted() {
  125. let mmt = moment();
  126. let n = mmt.diff(mmt.clone().startOf('day'), 'minutes');
  127. n -= 10;
  128. if (n < 0) n = 0;
  129. this.$refs.timeRule.clickMinute(n);
  130. if (!this.serial || !this.code) {
  131. this.$router.replace("/cloudrecord");
  132. return;
  133. }
  134. if (!this.day) {
  135. this.$router.replace(`/cloudrecord/timeview/${this.serial}/${this.code}/${moment().format('YYYYMMDD')}`);
  136. return;
  137. }
  138. this.updateVideos();
  139. },
  140. beforeRouteUpdate(to, from, next) {
  141. if (!to.params.serial || !to.params.code) {
  142. next({
  143. path: '/cloudrecord',
  144. replace: true
  145. })
  146. return;
  147. }
  148. if (!to.params.day) {
  149. next({
  150. path: `/cloudrecord/timeview/${to.params.serial}/${to.params.code}/${moment().format('YYYYMMDD')}`,
  151. replace: true
  152. })
  153. return;
  154. }
  155. next();
  156. this.$nextTick(() => {
  157. this.updateVideos();
  158. })
  159. }
  160. }
  161. </script>