LivePage.vue 4.5 KB

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