questionJiexiYingyu.vue 6.6 KB

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