index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div
  3. style="width: 100%; height: 100%"
  4. class="bs-design-wrap"
  5. >
  6. <video-player
  7. ref="videoPlayer1"
  8. :options="videoOptions"
  9. class="vjs-custom-skin videoPlayer"
  10. :playsinline="true"
  11. />
  12. </div>
  13. </template>
  14. <script>
  15. import { videoPlayer } from 'vue-video-player'
  16. import 'video.js/dist/video-js.css'
  17. import 'videojs-contrib-hls'
  18. import { refreshComponentMixin } from 'data-room-ui/js/mixins/refreshComponent'
  19. export default {
  20. name: 'Video',
  21. components: { videoPlayer },
  22. mixins: [refreshComponentMixin],
  23. props: {
  24. // 卡片的属性
  25. config: {
  26. type: Object,
  27. default: () => ({})
  28. }
  29. },
  30. computed: {},
  31. beforeDestroy () {
  32. this.$refs.videoPlayer1.dispose()
  33. },
  34. data () {
  35. return {
  36. // TODO 这里介绍各个参数的意义
  37. videoOptions: {
  38. live: true,
  39. // 浏览器准备好时开始回放
  40. autoplay: false,
  41. // true:默认视频播放无声音,需要手动开启声音
  42. muted: false,
  43. // 播放速度
  44. playbackRates: [0.5, 1.0, 1.5, 2.0],
  45. // 语言
  46. language: 'zh-CN',
  47. // 当true时,播放器将按比例缩放以适应其容器
  48. fluid: true,
  49. // 无法播放时提示信息
  50. notSupportedMessage: '该视频无法正常播放',
  51. // 纵横比或屏幕高宽比
  52. aspectRatio: '16:9',
  53. controlBar: {
  54. timeDivider: true,
  55. durationDisplay: true,
  56. remainingTimeDisplay: true,
  57. // 全屏按钮
  58. fullscreenToggle: true
  59. },
  60. // 播放器宽度,测试无效
  61. // width: 100,
  62. // 视频封面图
  63. poster: this.config.customize.posterUrl,
  64. sources: [
  65. {
  66. // 流配置,数组形式,会根据兼容顺序自动切换
  67. type: this.config.customize.videoType,
  68. src: this.config.customize.videoUrl
  69. }
  70. ]
  71. },
  72. dataForm: {
  73. script: ''
  74. }
  75. }
  76. },
  77. watch: {},
  78. mounted () {},
  79. methods: {
  80. // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错
  81. changeStyle (config) {
  82. this.videoOptions.sources.type = config.customize.videoType
  83. this.videoOptions.sources.type = config.customize.videoUrl
  84. this.videoOptions.poster = config.customize.posterUrl
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .bs-design-wrap {
  91. position: relative;
  92. width: 100%;
  93. height: 100%;
  94. background-color: transparent;
  95. border-radius: 4px;
  96. box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.1);
  97. box-sizing: border-box;
  98. .videoPlayer {
  99. width: 100%;
  100. height: 100%;
  101. display: flex;
  102. align-items: center;
  103. }
  104. }
  105. /*滚动条样式*/
  106. ::v-deep ::-webkit-scrollbar {
  107. width: 4px;
  108. border-radius: 4px;
  109. height: 4px;
  110. }
  111. ::v-deep ::-webkit-scrollbar-thumb {
  112. background: #dddddd !important;
  113. border-radius: 10px;
  114. }
  115. ::v-deep .video-js .vjs-big-play-button {
  116. z-index: 100;
  117. left: 50%;
  118. top: 50%;
  119. transform: translate(-50%, -50%);
  120. font-size: 4em;
  121. }
  122. </style>