index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div
  3. class="o-video"
  4. :class="{ offline: !online, mask: !isPlaying, controls }"
  5. >
  6. <template v-if="online">
  7. <video
  8. ref="video"
  9. class="o-video__player o-simple-video"
  10. :poster="poster"
  11. autoplay
  12. muted
  13. @play="onVideoPlay"
  14. @pause="onVideoPause"
  15. @waiting="onVideoWaiting"
  16. @playing="onVideoPlaying"
  17. @error="onVideoError"
  18. @ended="onVideoEnded"
  19. />
  20. <div class="o-video__mask">
  21. <div
  22. class="l-flex--row center o-video__btn u-pointer"
  23. @click.stop="onPlayOrPause"
  24. >
  25. <i :class="statusIconClass" />
  26. </div>
  27. </div>
  28. </template>
  29. <div
  30. v-else
  31. class="o-video__tag"
  32. />
  33. <div
  34. v-if="controls"
  35. class="l-flex--row c-footer"
  36. >
  37. <div class="l-flex__auto c-sibling-item u-ellipsis">{{ camera.name }}</div>
  38. <slot />
  39. <i
  40. v-if="online"
  41. class="c-sibling-item el-icon-full-screen has-active u-pointer"
  42. @click="onFullScreen"
  43. />
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { mapGetters } from 'vuex'
  49. import { GATEWAY_CAMERA } from '@/constant'
  50. import playerMixin from '../../player'
  51. export default {
  52. name: 'CameraPlayer',
  53. mixins: [playerMixin],
  54. props: {
  55. camera: {
  56. type: Object,
  57. required: true
  58. }
  59. },
  60. computed: {
  61. ...mapGetters(['token']),
  62. online () {
  63. return this.camera.onlineStatus === 1
  64. }
  65. },
  66. watch: {
  67. online (val) {
  68. if (val) {
  69. this.$nextTick(this.createPlayer)
  70. } else {
  71. this.destroyPlayer()
  72. }
  73. }
  74. },
  75. mounted () {
  76. this.online && this.createPlayer()
  77. },
  78. methods: {
  79. createPlayer () {
  80. this.playUrl(`${GATEWAY_CAMERA}/${this.camera.identifier}?authorization=${this.token}`)
  81. }
  82. }
  83. }
  84. </script>