index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div
  3. :class="[
  4. 'video-wrapper',
  5. isMobile ? 'mobile' : '',
  6. isCssFullScreenRef ? 'fullScreen' : '',
  7. ]"
  8. :style="{ minHeight: props.height }"
  9. >
  10. <div id="mse"></div>
  11. <Transition name="fade">
  12. <div v-show="questionShowRef && question" class="question">
  13. 问题:{{ question }}
  14. </div>
  15. </Transition>
  16. <Transition name="fade">
  17. <div
  18. v-show="questionShowRef"
  19. :class="['option-btn-box']"
  20. :style="{ flexWrap: props.options.length >= 4 ? 'wrap' : 'nowrap' }"
  21. >
  22. <div
  23. class="option-btn-item"
  24. v-for="(option, index) in props.options"
  25. :key="index"
  26. >
  27. <div class="option-btn" @click="() => emits('onClickOption', option)">
  28. {{ option.optionType }}:{{ option.optionName }}
  29. </div>
  30. </div>
  31. </div>
  32. </Transition>
  33. </div>
  34. </template>
  35. <script>
  36. export default {
  37. name: "VideoLineGraph",
  38. };
  39. </script>
  40. <script setup>
  41. import { watch } from "vue";
  42. import useInitPlayer from "./hooks/useInitPlayer";
  43. const emits = defineEmits("onClickOption", "onFullscreenChange", 'reload');
  44. const props = defineProps({
  45. // 问题
  46. question: {
  47. type: String,
  48. default: "",
  49. },
  50. // 选项
  51. options: {
  52. type: Array,
  53. default: () => [],
  54. },
  55. // 视频地址
  56. videoUrl: {
  57. type: String,
  58. default: "",
  59. },
  60. // 视频容器宽度
  61. width: {
  62. type: String,
  63. default: "100%",
  64. },
  65. // 视频容器高度
  66. height: {
  67. type: String,
  68. default: "80vh",
  69. },
  70. // 是否自动播放
  71. autoplay: {
  72. type: Boolean,
  73. default: true,
  74. },
  75. // 是否静音自动播放。由于浏览器策略访问权重低的页面是不可以自动播放视频的,但是可以静音自动播放。这种情况下可以使用这个
  76. autoplayMuted: {
  77. type: Boolean,
  78. default: false,
  79. },
  80. // 视频封面图片
  81. poster: {
  82. type: String,
  83. default: "",
  84. },
  85. // 是否需要对外发送信息
  86. ifSendMsg: {
  87. type: Boolean,
  88. default: false,
  89. },
  90. // 外部调用者传递的数据, ifSendMsg 为 false时,说明没有外部调用,此参数就无意义
  91. pipData: {
  92. type: Object,
  93. default: () => ({}),
  94. },
  95. });
  96. const { xgplayer, isMobile, isCssFullScreenRef, questionShowRef, playNext } =
  97. useInitPlayer(props, emits);
  98. watch(
  99. () => props.videoUrl,
  100. (value) => {
  101. if (!xgplayer.value || !props.videoUrl) return;
  102. playNext(value, props.poster);
  103. // 切换poster海报, playNext里面有时候会失败,这里重新赋值一下
  104. const posterDom = document.querySelector(".xgplayer-poster");
  105. posterDom.style.backgroundImage = `url("${props.poster}")`;
  106. }
  107. );
  108. </script>
  109. <style lang="scss">
  110. .xgplayer .xgplayer-replay {
  111. left: unset;
  112. right: 0;
  113. top: -20px;
  114. flex-direction: row;
  115. width: 110px;
  116. transform: translate(-20%, 0%);
  117. }
  118. .xgplayer.xgplayer-rotate-fullscreen {
  119. width: 100vh !important;
  120. }
  121. </style>
  122. <style lang="scss" scoped>
  123. .fade-enter-active {
  124. transition: opacity 0.8s ease;
  125. }
  126. .fade-enter-from {
  127. opacity: 0;
  128. }
  129. .video-wrapper {
  130. width: 100%;
  131. background: #999;
  132. position: relative;
  133. .question {
  134. width: 100%;
  135. position: absolute;
  136. padding: 8px 16px;
  137. top: 20%;
  138. left: 0;
  139. transform: translateY(-50%);
  140. background-color: rgba($color: #000000, $alpha: 0.6);
  141. color: #fff;
  142. font-size: 14px;
  143. font-weight: 600;
  144. z-index: 9999;
  145. }
  146. .option-btn-box {
  147. width: 100%;
  148. position: absolute;
  149. bottom: 60px;
  150. left: 0;
  151. display: flex;
  152. z-index: 9999;
  153. .option-btn-item {
  154. width: 50%;
  155. padding: 2px;
  156. .option-btn {
  157. border: 1px solid #000;
  158. background-color: rgba($color: #ffffff, $alpha: 0.6);
  159. color: #000;
  160. font-size: 8px;
  161. width: 100%;
  162. height: 28px;
  163. display: flex;
  164. align-items: center;
  165. justify-content: flex-start;
  166. padding: 0 2px;
  167. user-select: none;
  168. cursor: pointer;
  169. }
  170. }
  171. }
  172. &.fullScreen .option-btn-box,
  173. &.fullScreen .question {
  174. position: fixed;
  175. }
  176. &.mobile.fullScreen .question {
  177. position: fixed;
  178. left: 0;
  179. top: 0;
  180. width: 100vh;
  181. transform: rotate(90deg) translate(0, -85vw);
  182. transform-origin: 0 0;
  183. }
  184. &.mobile.fullScreen .option-btn-box {
  185. left: 0;
  186. bottom: 0;
  187. position: fixed;
  188. transform: rotate(90deg) translate(-100%, -60px);
  189. transform-origin: 0 100%;
  190. width: 100vh;
  191. }
  192. }
  193. </style>