questionJiexiYingyu.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view>
  3. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  4. mask-background-color="rgba(255, 255, 255, 0.6);" class="ezy-popup-width-all">
  5. <view class="ezy-dajx-page" :style="{backgroundImage: 'url(' + courseBjFun() + ')'}">
  6. <view class="icon-title-navBar-box">
  7. <view @click="handleBack" class="nav-bar-icon"></view>
  8. <view class="nav-bar-title">单元测试</view>
  9. </view>
  10. <view class="shiti-frame-box">
  11. <view class="dajx-content-box">
  12. <!-- 思路分析 -->
  13. <view class="slfx-title"></view>
  14. <!-- <view class="slfx-content"> {{data.answer}}</view> -->
  15. <!-- <rich-text class="slfx-content" :nodes="data.answer"></rich-text> -->
  16. <textReplaceIconVue :question="data" :text="data.answer" :placeholders="data.placeholders"></textReplaceIconVue>
  17. <!-- 视频讲解 -->
  18. <view class="spjj-title" v-if="videoId"></view>
  19. <view class="ezy-video-box" v-if="videoId" >
  20. <!-- 这里放视频 ↓ -->
  21. <view class="ezy-video" ref="videoContent" id="wgy-player-test" :playAuth="playAuth"
  22. :change:playAuth="renderScript.receiveMsg" :videoId="videoId"
  23. :change:videoId="renderScript.videoIdFun" :hideFlag="hideFlag"
  24. :change:hideFlag="renderScript.hideFlagFun" :seekTime="seekTime"
  25. :change:seekTime="renderScript.seekTimeFun">
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </uni-popup>
  32. </view>
  33. </template>
  34. <script>
  35. import textReplaceIconVue from '@/components/question/yingyu/textReplaceIcon.vue'
  36. import {
  37. onLoad,
  38. onReady
  39. } from '@dcloudio/uni-app';
  40. import {
  41. getVideoAuth,
  42. } from "@/api/shipin.js"
  43. export default {
  44. components: {textReplaceIconVue},
  45. props: {
  46. cardId: {
  47. type: [String,Number],
  48. default: 1
  49. },
  50. },
  51. data() {
  52. return {
  53. pageData: null, //上个页面获取的视频参数(视频id)
  54. playAuth: "", //播放凭证
  55. progressMarkers: [],
  56. videoId: "", //阿里云视频id
  57. seekTime: '',
  58. hideFlag: 'show',
  59. data: {},
  60. }
  61. },
  62. onHide() {
  63. console.log('onHideonHideonHideonHide');
  64. this.hideFlag = 'hide'
  65. },
  66. onUnload() {
  67. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  68. this.hideFlag = 'hide'
  69. },
  70. methods: {
  71. showPopup(item) {
  72. this.data = item;
  73. if (item.jiangjie) {
  74. this.videoId = item.jiangjie
  75. this.getLive(); //获取播放凭证
  76. }
  77. this.$refs.popupRef.open()
  78. },
  79. handleBack(item) {
  80. this.$refs.popupRef.close()
  81. uni.$emit('question-jiexi-close')
  82. },
  83. getLive() {
  84. let req = {
  85. videoId: this.videoId
  86. }
  87. getVideoAuth(req).then(res => {
  88. this.playAuth = res.data
  89. })
  90. },
  91. markersClick(data) {
  92. this.seekTime = ""
  93. this.$nextTick(() => {
  94. this.seekTime = data.offset
  95. });
  96. },
  97. courseBjFun() {
  98. const cardId = Number(this.cardId);
  99. switch (cardId) {
  100. case 1:
  101. return 'static/images/course/couse-shuxue-bj.png'
  102. break;
  103. case 2:
  104. return 'static/images/course/course-yingyu-bj.png'
  105. break;
  106. default:
  107. break;
  108. }
  109. }
  110. },
  111. created() {
  112. // console.log("getLive")
  113. // this.getLive(); //获取播放凭证
  114. },
  115. }
  116. </script>
  117. <script module="renderScript" lang="renderjs">
  118. export default {
  119. mounted() {
  120. console.log("renderScript1")
  121. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  122. },
  123. data() {
  124. return {
  125. player: null,
  126. playAuth: '',
  127. videoId: '',
  128. progressMarkers: [],
  129. seekTime: '',
  130. isFirst: -1,
  131. }
  132. },
  133. methods: {
  134. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  135. if (newValue) {
  136. this.playAuth = newValue
  137. this.loadWebPlayerSDK()
  138. }
  139. },
  140. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  141. if (newValue) {
  142. this.videoId = newValue
  143. }
  144. },
  145. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  146. if (this.player) {
  147. this.player.pause()
  148. }
  149. },
  150. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  151. if (newValue) {
  152. this.progressMarkers = newValue
  153. }
  154. },
  155. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  156. if (newValue) {
  157. console.log(newValue, 'newValuenewValuenewValuenewValuenewValue')
  158. console.log(this.player.getStatus(), 'newValuenewValuenewValuenewValuenewValue')
  159. this.player.play()
  160. this.player.seek(newValue)
  161. // this.player.seek(newValue)
  162. }
  163. },
  164. playAli() {
  165. if (this.isFirst == 0) {
  166. this.isFirst = -1
  167. return;
  168. }
  169. this.player = null;
  170. //配置播放器
  171. var player = new Aliplayer({
  172. id: "wgy-player-test",
  173. "vid": this.videoId,
  174. "playauth": this.playAuth,
  175. extraInfo: { poster: 'noposter' },
  176. // "playConfig": {
  177. // "EncryptType": 'AliyunVoDEncryption'
  178. // },
  179. "skinLayout": [{
  180. "name": "bigPlayButton",
  181. "align": "blabs",
  182. "x": 30,
  183. "y": 80
  184. },
  185. {
  186. "name": "controlBar",
  187. "align": "blabs",
  188. "x": 0,
  189. "y": 0,
  190. "children": [{
  191. "name": "progress",
  192. "align": "blabs",
  193. "x": 0,
  194. "y": 44
  195. },
  196. {
  197. "name": "playButton",
  198. "align": "tl",
  199. "x": 15,
  200. "y": 12
  201. },
  202. {
  203. "name": "fullScreenButton",
  204. "align": "tr",
  205. "x": 10,
  206. "y": 12
  207. },
  208. {
  209. "name": "timeDisplay",
  210. "align": "tr",
  211. "x": 10,
  212. "y": 5
  213. }
  214. ]
  215. }
  216. ],
  217. "qualitySort": "asc",
  218. "format": "mp4",
  219. "mediaType": "video",
  220. "encryptType": 1,
  221. "progressMarkers": this.progressMarkers,
  222. "width": '100%',
  223. "height": '500px',
  224. "autoplay": false,
  225. "isLive": false,
  226. "rePlay": false,
  227. "playsinline": true,
  228. "preload": false,
  229. "controlBarVisibility": "hover",
  230. "useH5Prism": true
  231. }, function(player) {});
  232. this.player = player;
  233. player.one('canplay', function() {
  234. console.log('canplay', this.player.tag);
  235. player.tag.play();
  236. });
  237. this.isFirst ++;
  238. },
  239. loadWebPlayerSDK() {
  240. return new Promise((resolve, reject) => {
  241. const s_tag = document.createElement('script'); // 引入播放器js
  242. s_tag.type = 'text/javascript';
  243. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  244. s_tag.charset = 'utf-8';
  245. s_tag.onload = () => {
  246. this.playAli()
  247. resolve();
  248. }
  249. document.body.appendChild(s_tag);
  250. const l_tag = document.createElement('link'); // 引入播放器css
  251. l_tag.rel = 'stylesheet';
  252. l_tag.href =
  253. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  254. document.body.appendChild(l_tag);
  255. });
  256. },
  257. }
  258. }
  259. </script>