LivePage.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 id="videoplayer" 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="camNameModel" 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. video: {
  47. videoId: 110120119,
  48. title: '我的直播',
  49. description: '我的直播',
  50. view: 10,
  51. favorite: 10
  52. },
  53. user: {
  54. userId: 10001,
  55. screenName: '浩',
  56. avatarUrl: '',
  57. following: 1024,
  58. follower: 1024
  59. },
  60. calendarDate: new Date(),
  61. dateList: [],
  62. dateMap: new Map(),
  63. showRecordList: false,
  64. camList: [],
  65. camNameModel: null,
  66. camDetail: null,
  67. form: {},
  68. recordList: [],
  69. camRecord: null,
  70. showCalender: false
  71. }
  72. },
  73. watch: {
  74. $route() {
  75. this.$router.go()
  76. }
  77. },
  78. created() {
  79. const camId = this.$route.params.camId
  80. if (camId === undefined || camId === null) {
  81. return
  82. }
  83. getCamDetail(camId).then(resp => {
  84. if (resp.code === 0) {
  85. var camDetail = resp.data
  86. this.camDetail = camDetail
  87. this.camNameModel = camDetail.camName
  88. document.title = camDetail.camName + '实时录像'
  89. if (!camDetail.state) {
  90. const msg = camDetail.camName + '离线'
  91. console.log(msg)
  92. var container = document.getElementById('videoplayer')
  93. console.log(container)
  94. // container.innerHTML = msg
  95. } else {
  96. const pullUrl = camDetail.pullUrl
  97. this.initFlvPlayer(camId, null, pullUrl)
  98. }
  99. }
  100. })
  101. getCamList().then(resp => {
  102. if (resp.code === 0) {
  103. this.camList = resp.data
  104. }
  105. })
  106. },
  107. methods: {
  108. onSelect(value) {
  109. const path = '/my/cam/live/' + value
  110. if (this.$route.path === path) {
  111. this.$router.go(0)
  112. return
  113. }
  114. this.$router.push(path)
  115. },
  116. initFlvPlayer(videoId, coverUrl, videoUrl) {
  117. new DPlayer({
  118. container: document.getElementById('dplayer'),
  119. live: true,
  120. video: {
  121. url: videoUrl,
  122. type: 'customFlv',
  123. customType: {
  124. customFlv: function(video, player) {
  125. const flvPlayer = flvjs.createPlayer({
  126. type: 'flv',
  127. url: video.src
  128. })
  129. flvPlayer.attachMediaElement(video)
  130. flvPlayer.load()
  131. }
  132. }
  133. }
  134. })
  135. },
  136. goToCamRecord() {
  137. const path = '/my/cam/record/' + this.camDetail.camId
  138. if (this.$route.path === path) {
  139. this.$router.go(0)
  140. return
  141. }
  142. this.$router.push(path)
  143. }
  144. }
  145. }
  146. </script>
  147. <style scoped>
  148. /*处于手机屏幕时*/
  149. @media screen and (max-width: 768px) {
  150. .movie-list {
  151. padding-top: 8px;
  152. padding-left: 0.5%;
  153. padding-right: 0.5%;
  154. }
  155. }
  156. .movie-list {
  157. padding-top: 15px;
  158. padding-left: 5%;
  159. padding-right: 5%;
  160. }
  161. .clearfix:before,
  162. .clearfix:after {
  163. display: table;
  164. content: "";
  165. }
  166. .clearfix:after {
  167. clear: both;
  168. }
  169. .budge{
  170. width: 10px;
  171. height: 10px;
  172. border-radius: 5px;
  173. margin: 10px auto;
  174. }
  175. .blue{
  176. background-color: #409eff;
  177. }
  178. </style>