LivePage.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <el-row class="movie-list">
  3. <el-col :md="16">
  4. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  5. <el-card class="box-card">
  6. <div slot="header" class="clearfix">
  7. <h3 v-if="camDetail != null" v-html="camDetail.camName" />
  8. </div>
  9. <div class="text item">
  10. <div id="dplayer" ref="dplayer" style="height: 480px;" />
  11. </div>
  12. </el-card>
  13. </el-row>
  14. </el-col>
  15. <el-col :md="8">
  16. <el-row>
  17. <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
  18. <el-card class="box-card">
  19. <div slot="header" class="clearfix">
  20. <el-select v-model="camId" placeholder="选择摄像头" @change="onSelect">
  21. <el-option
  22. v-for="item in camList"
  23. :key="item.value"
  24. :label="item.name"
  25. :value="item.value"
  26. />
  27. </el-select>
  28. <el-button style="float: right; padding: 3px 0" type="text" @click="goToCamRecord">历史录像</el-button>
  29. </div>
  30. </el-card>
  31. </el-row>
  32. </el-row>
  33. </el-col>
  34. </el-row>
  35. </template>
  36. <script>
  37. import flvjs from 'flv.js'
  38. import DPlayer from 'dplayer'
  39. import { getCamDetail, getCamList } from '@/api/cam'
  40. export default {
  41. name: 'LivePage',
  42. data() {
  43. return {
  44. flvjs,
  45. DPlayer,
  46. user: {
  47. userId: 10001,
  48. screenName: '浩',
  49. avatarUrl: '//pic1.zhimg.com/v2-c755e7ec5510b0638c2d1bead712544a_r.jpg',
  50. following: 1024,
  51. follower: 1024
  52. },
  53. camId: null,
  54. camList: [],
  55. camDetail: null
  56. }
  57. },
  58. watch: {
  59. $route() {
  60. this.$router.go()
  61. }
  62. },
  63. created() {
  64. const camId = this.$route.params.camId
  65. this.camId = camId
  66. getCamDetail(camId).then(resp => {
  67. if (resp.code === 0) {
  68. var camDetail = resp.data
  69. this.camDetail = camDetail
  70. document.title = camDetail.camName + '实时录像'
  71. var ele = document.querySelector('#dplayer')
  72. if (camDetail.state) {
  73. const flvUrl = camDetail.pullUrl
  74. this.initFlvPlayer(camId, flvUrl)
  75. } else {
  76. ele.innerHTML = '<h5>摄像头离线, 你可以查看本摄像头的' +
  77. '<a style="text-decoration-line: none; color: red" target="_blank" href="/cam/record/' + this.camId + '">历史录像</a>' +
  78. '</h5>'
  79. }
  80. }
  81. })
  82. getCamList().then(resp => {
  83. if (resp.code === 0) {
  84. this.camList = resp.data
  85. }
  86. })
  87. },
  88. methods: {
  89. onSelect(value) {
  90. const path = '/cam/live/' + value
  91. if (this.$route.path === path) {
  92. this.$router.go(0)
  93. return
  94. }
  95. this.$router.push(path)
  96. },
  97. initFlvPlayer(videoId, flvUrl) {
  98. new DPlayer({
  99. container: document.querySelector('#dplayer'),
  100. live: true,
  101. screenshot: true,
  102. autoplay: false,
  103. volume: 0.1,
  104. mutex: true,
  105. video: {
  106. url: flvUrl,
  107. type: 'customFlv',
  108. customType: {
  109. customFlv: function(video, player) {
  110. const flvPlayer = flvjs.createPlayer({
  111. type: 'flv',
  112. url: video.src
  113. })
  114. flvPlayer.attachMediaElement(video)
  115. flvPlayer.load()
  116. }
  117. }
  118. }
  119. })
  120. },
  121. goToCamRecord() {
  122. const path = '/cam/record/' + this.camId
  123. if (this.$route.path === path) {
  124. this.$router.go(0)
  125. return
  126. }
  127. this.$router.push(path)
  128. }
  129. }
  130. }
  131. </script>
  132. <style scoped>
  133. /*处于手机屏幕时*/
  134. @media screen and (max-width: 768px) {
  135. .movie-list {
  136. padding-top: 8px;
  137. padding-left: 0.5%;
  138. padding-right: 0.5%;
  139. }
  140. }
  141. .movie-list {
  142. padding-top: 15px;
  143. padding-left: 5%;
  144. padding-right: 5%;
  145. }
  146. .clearfix:before,
  147. .clearfix:after {
  148. display: table;
  149. content: "";
  150. }
  151. .clearfix:after {
  152. clear: both;
  153. }
  154. .budge{
  155. width: 10px;
  156. height: 10px;
  157. border-radius: 5px;
  158. margin: 10px auto;
  159. }
  160. .blue{
  161. background-color: #409eff;
  162. }
  163. </style>