MtaBusVideoPlayer.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div>
  3. <video-player
  4. :options="videoOptions"
  5. @sectionCompleted="sectionCompleted"
  6. class="video-player"
  7. ref="stVideoPlayer"
  8. v-if="videoOptions.display"
  9. >
  10. </video-player>
  11. </div>
  12. </template>
  13. <script>
  14. import VideoPlayer from '@/components/custom/VideoPlayer.vue';
  15. import * as kejian from '@/api/peixun/kejian';
  16. import * as commonUtils from '@/utils/common';
  17. export default {
  18. name: 'MtaBusVideoPlayer',
  19. components: {
  20. VideoPlayer,
  21. },
  22. data() {
  23. return {
  24. videoOptions: {
  25. type: null, // 共用逻辑:1:预览 2:c端播放
  26. autoplay: false, // 共用逻辑:自动播放
  27. controls: true, // 共用逻辑:是否使播放器可控 为true
  28. sources: [], // 共用逻辑:当前资源列表 默认支持一组相同资源的不同编码格式
  29. progressControlEnable: true, // 共用逻辑:进度条可操作 可用true/禁用false
  30. // theme: 'city', // 共用逻辑:主题枚举 'default', 'city', 'fantasy', 'forest', 'sea'
  31. height: '500px', // 共用逻辑
  32. playlist: [], // 共用逻辑
  33. display: false, // 共用逻辑,
  34. questionDoneShow: null, // 共用逻辑: [Boolbean] 拖拽后是否显示已完成的题
  35. drugControl: null, // 共用逻辑: [String] none 不控制 forwardOnly 只能拖至已看过的
  36. hasPlaylist: false, // 共用逻辑: 视频右侧条,现在默认不要
  37. playIndex: 0, // 不共用逻辑 可删除
  38. shitiList: null, // 不共用逻辑 被插入的试题list
  39. },
  40. };
  41. },
  42. props: {
  43. options: {
  44. type: Object,
  45. default() {
  46. return {};
  47. },
  48. },
  49. },
  50. methods: {
  51. fileChange(event) {
  52. },
  53. videoOptionsInit() {
  54. this.videoOptions.questionDoneShow = true; // 预览和使用默认都是拖拽后显示已完成的题
  55. this.videoOptions.type = this.options.type;
  56. // 共用逻辑: none 不控制 forwardOnly 只能拖至已看过的
  57. if (this.videoOptions.type === 1) { // 预览
  58. this.videoOptions.drugControl = 'none';
  59. } else { // c端播放
  60. if (this.videoOptions.shitiList && this.videoOptions.shitiList.length > 0) { // 有题
  61. this.videoOptions.drugControl = 'forwardOnly';
  62. } else { // 没有题 已后台状态为准
  63. if (this.options.progressFlag === 0) {
  64. this.videoOptions.drugControl = 'none';
  65. } else if (this.options.progressFlag === 1) {
  66. this.videoOptions.drugControl = 'forwardOnly';
  67. } else {
  68. this.videoOptions.drugControl = 'none';
  69. }
  70. }
  71. }
  72. },
  73. videoPlayerShow() {
  74. kejian.getKejian({
  75. kjId: this.options.kjId,
  76. }).then(res => {
  77. if (res.code === 0) {
  78. let videoItem = {
  79. name: res.data.name,
  80. duration: res.data.duration, // 该视频播放时长
  81. sources: [
  82. {
  83. src: res.data.newUrl,
  84. type: 'video/mp4',
  85. },
  86. ],
  87. thumbnail: [
  88. {
  89. srcset: res.data.cover,
  90. type: 'image/jpeg',
  91. style: 'width:180px;',
  92. // media: '(min-width: 367px;)'
  93. },
  94. ],
  95. // poster: 'http://media.w3.org/2010/05/sintel/poster.png',
  96. };
  97. // console.log(res.data);
  98. this.videoOptions.shitiList = res.data.shitiList;
  99. this.videoOptionsInit();
  100. this.videoOptions.display = true;
  101. this.$nextTick(() => {
  102. if (this.videoOptions.hasPlaylist) {
  103. this.videoOptions.playlist.push(videoItem);
  104. } else {
  105. this.videoOptions.sources = videoItem.sources;
  106. }
  107. });
  108. }
  109. });
  110. },
  111. hidDialog() {
  112. this.$refs.stVideoPlayer.hidDialog();
  113. },
  114. sectionCompleted(payload) {
  115. commonUtils.updateSectionProgress();
  116. },
  117. },
  118. mounted() {
  119. this.videoPlayerShow();
  120. },
  121. watch: {
  122. options: {
  123. handler(value, oValue) {
  124. // console.log(value);
  125. this.videoPlayerShow();
  126. },
  127. deep: true,
  128. },
  129. },
  130. };
  131. </script>
  132. <style lang="scss">
  133. .el-button {
  134. font-size: 14px;
  135. }
  136. .fl {
  137. display: block;
  138. float: left;
  139. }
  140. .ml-30 {
  141. margin-left: 30px;
  142. }
  143. .answer-dialog,.success-answer-dialog {
  144. text-align: center;
  145. line-height: 40px;
  146. position: absolute;
  147. z-index: 9999;
  148. left: 46%;
  149. top: 10%;
  150. background-color: #fef0f0;
  151. border-color: #fde2e2;
  152. color: #F56C6C;
  153. padding: 0 20px;
  154. i{
  155. font-size: 19px;
  156. display: inline-block;
  157. vertical-align: middle;
  158. }
  159. >div{
  160. display: inline-block;
  161. font-size: 14px;
  162. vertical-align: middle;
  163. }
  164. }
  165. //成功弹窗
  166. .success-answer-dialog{
  167. background-color: #f0f9eb;
  168. border-color: #e1f3d8;
  169. color: #67C23A;
  170. }
  171. </style>