questionJiexiYingyu.vue 6.7 KB

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