lookShipin.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <view class="ezy-course-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="goUpPage" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">{{shipinTitle}}</text>
  6. </view>
  7. <view ref="videoContent" id="wgy-player-test" :playAuth="playAuth" :change:playAuth="renderScript.receiveMsg"
  8. :videoId="videoId" :change:videoId="renderScript.videoIdFun" :hideFlag="hideFlag"
  9. :change:hideFlag="renderScript.hideFlagFun" :progressMarkers="progressMarkers"
  10. :change:progressMarkers="renderScript.progressMarkersMsg" :seekTime="seekTime"
  11. :change:seekTime="renderScript.seekTimeFun" class="course-video-box">
  12. </view>
  13. <view class="course-content-border">
  14. <view class="course-content-box">
  15. <!-- <view class="course-title">{{jieName}}</view> -->
  16. <view v-for="(item,index) in progressMarkers" :key="index" @click="markersClick(item)">
  17. <view class="title-play-box">
  18. <text class="course-title">{{item.title}}</text>
  19. <view class="course-play-btn" @click="markersClick(item)"></view>
  20. </view>
  21. <rich-text :nodes="item.describe" class="course-content-item"></rich-text>
  22. </view>
  23. </view>
  24. </view>
  25. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  26. mask-background-color="rgba(255, 255, 255, 0.6);">
  27. <view class="course-score-dialog">
  28. <view class="text-score">20</view>
  29. <view class="course-btn-box">
  30. <view @click="goBack" class="return-btn"></view>
  31. <view @click="goNext" class="continue-btn"></view>
  32. </view>
  33. </view>
  34. </uni-popup>
  35. </view>
  36. </template>
  37. <script>
  38. import {
  39. ref
  40. } from 'vue';
  41. import {
  42. onLoad,
  43. onReady
  44. } from '@dcloudio/uni-app';
  45. import {
  46. getVideoAuth,
  47. } from "@/api/shipin.js"
  48. import {
  49. toast,
  50. getUserIdentity
  51. } from "@/utils/common";
  52. import {
  53. userZhangNextInfo,
  54. } from "@/api/learnPlan.js"
  55. import cacheManager from "@/utils/cacheManager.js";
  56. export default {
  57. data() {
  58. return {
  59. pageData: null, //上个页面获取的视频参数(视频id)
  60. playAuth: "", //播放凭证
  61. progressMarkers: [],
  62. jieName: '',
  63. hideFlag: 'show',
  64. videoId: "", //阿里云视频id
  65. cardId: '',
  66. nianji: '',
  67. zhangId: '',
  68. seekTime: '',
  69. jieNumber: '',
  70. shipinTitle: '',
  71. cacheZhangInfo: {}
  72. }
  73. },
  74. onLoad(options) {
  75. if (!cacheManager.get('auth')) {
  76. // 游客
  77. this.videoId = options.videoId
  78. this.nianji = options.nianji
  79. this.zhangId = options.zhangId
  80. this.cardId = options.cardId
  81. this.getLive(); //获取播放凭证
  82. } else {
  83. this.init(options)
  84. }
  85. },
  86. onHide() {
  87. console.log('onHideonHideonHideonHide');
  88. this.hideFlag = 'hide'
  89. },
  90. onUnload() {
  91. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  92. this.hideFlag = 'hide'
  93. },
  94. methods: {
  95. init(options) {
  96. this.jieNumber = options.jieNumber
  97. if (!(cacheManager.get('zhangInfo') && options.jieNumber)) {
  98. toast('数据错误,缓存丢失/ number丢失')
  99. return false
  100. }
  101. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  102. let currentObject = this.cacheZhangInfo.jieList.find(item => item.number == options.jieNumber);
  103. this.shipinTitle = this.cacheZhangInfo.numberStr + ' ' + this.cacheZhangInfo.zhangName
  104. // lastFlag是否是本章最后一节,0否1是 type,1视频,2试题
  105. if (currentObject.lastFlag == 1 && currentObject.type == 2) {
  106. uni.redirectTo({
  107. url: `/pages/unitTest/index?jieNumber=` + currentObject.number
  108. })
  109. } else if (currentObject.lastFlag == 1 && currentObject.type == 1) {
  110. // 当前是本章最后一节,并且是 视频 切换下一章
  111. this.goNextZhang()
  112. } else {
  113. this.pageData = {
  114. ...currentObject
  115. }
  116. console.log(this.pageData);
  117. this.videoId = this.pageData.videoId
  118. this.jieName = this.pageData.jieName
  119. this.progressMarkers = this.pageData.jiedianList
  120. this.getLive(); //获取播放凭证
  121. }
  122. },
  123. goNextZhang() {
  124. let that = this
  125. let req = {
  126. nianji: that.currentObject.nianji,
  127. zhangId: that.currentObject.zhangId,
  128. cardId: that.currentObject.cardId,
  129. }
  130. userZhangNextInfo(req).then(res => {
  131. cacheManager.set('zhangInfo', res.data)
  132. cacheManager.updateObject('auth', {
  133. zhangId: res.data.zhangId,
  134. cardId: res.data.cardId,
  135. nianji: res.data.nianji,
  136. })
  137. that.init({
  138. jieNumber: 1
  139. })
  140. })
  141. },
  142. playEnd(data) {
  143. this.$refs.popupRef.open();
  144. },
  145. goBack() {
  146. this.$refs.popupRef.close();
  147. this.goUpPage()
  148. },
  149. goNext() {
  150. this.$refs.popupRef.close();
  151. this.hideFlag = "show"
  152. this.videoId = ''
  153. this.progressMarkers = []
  154. this.pageData = null
  155. this.playAuth = ''
  156. this.cacheZhangInfo = {}
  157. Number(this.jieNumber++)
  158. // this.init({
  159. // jieNumber: this.jieNumber
  160. // })
  161. uni.redirectTo({
  162. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  163. url: '/pages/study/lookShipin?jieNumber=' + this.jieNumber
  164. })
  165. },
  166. getLive() {
  167. let req = {
  168. videoId: this.videoId
  169. }
  170. getVideoAuth(req).then(res => {
  171. this.playAuth = res.data
  172. })
  173. },
  174. markersClick(data) {
  175. this.seekTime = ""
  176. this.$nextTick(() => {
  177. this.seekTime = data.offset
  178. });
  179. },
  180. goUpPage() {
  181. if (!cacheManager.get('auth')) {
  182. uni.redirectTo({
  183. url: '/pages/study/index?cardId=' + this.cardId+ '&nianji=' + this.nianji+ '&zhangId=' + this.zhangId
  184. })
  185. } else {
  186. uni.redirectTo({
  187. url: `/pages/study/index`
  188. })
  189. }
  190. }
  191. },
  192. created() {
  193. // console.log("getLive")
  194. // this.getLive(); //获取播放凭证
  195. },
  196. }
  197. </script>
  198. <script module="renderScript" lang="renderjs">
  199. export default {
  200. mounted() {
  201. console.log("renderScript1")
  202. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  203. this.loadWebPlayerSDK()
  204. },
  205. data() {
  206. return {
  207. player: null,
  208. playAuth: '',
  209. videoId: '',
  210. progressMarkers: [],
  211. seekTime: ''
  212. }
  213. },
  214. methods: {
  215. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  216. // console.log('service层中的options发生变化')
  217. // console.log('新值', newValue)
  218. // console.log('旧值', oldValue)
  219. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  220. // instance和ownerInstance的区别是:
  221. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  222. // instance的作用目前尚不明确,官方没有给出用法
  223. if (newValue) {
  224. this.playAuth = ''
  225. this.playAuth = newValue
  226. this.playAli()
  227. }
  228. },
  229. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  230. if (newValue) {
  231. this.videoId = ''
  232. this.videoId = newValue
  233. }
  234. },
  235. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  236. if (this.player) {
  237. this.player.pause()
  238. }
  239. },
  240. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  241. if (newValue) {
  242. this.progressMarkers = newValue
  243. }
  244. },
  245. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  246. if (newValue) {
  247. this.player.play()
  248. this.player.seek(newValue)
  249. // switch (this.player.getStatus()) {
  250. // case 'init':
  251. // break;
  252. // case 'ready':
  253. // break;
  254. // case 'loading':
  255. // this.player.play()
  256. // this.player.seek(newValue)
  257. // break;
  258. // case 'play':
  259. // this.player.seek(newValue)
  260. // break;
  261. // case 'pause':
  262. // this.player.play()
  263. // this.player.seek(newValue)
  264. // break;
  265. // case 'playing':
  266. // this.player.seek(newValue)
  267. // break;
  268. // case 'waiting':
  269. // break;
  270. // case 'error':
  271. // break;
  272. // case 'ended':
  273. // break;
  274. // default:
  275. // break;
  276. // }
  277. // this.player.seek(newValue)
  278. }
  279. },
  280. playAli() {
  281. let that = this
  282. // console.log(this.videoId);
  283. // console.log(this.playAuth);
  284. //配置播放器
  285. var player = new Aliplayer({
  286. id: "wgy-player-test",
  287. "vid": this.videoId,
  288. "playauth": this.playAuth,
  289. // "playConfig": {
  290. // "EncryptType": 'AliyunVoDEncryption'
  291. // },
  292. "skinLayout": [{
  293. "name": "bigPlayButton",
  294. "align": "blabs",
  295. "x": 30,
  296. "y": 80
  297. },
  298. {
  299. "name": "controlBar",
  300. "align": "blabs",
  301. "x": 0,
  302. "y": 0,
  303. "children": [{
  304. "name": "progress",
  305. "align": "blabs",
  306. "x": 0,
  307. "y": 44
  308. },
  309. {
  310. "name": "playButton",
  311. "align": "tl",
  312. "x": 15,
  313. "y": 12
  314. },
  315. {
  316. "name": "fullScreenButton",
  317. "align": "tr",
  318. "x": 10,
  319. "y": 12
  320. }
  321. ]
  322. }
  323. ],
  324. "qualitySort": "asc",
  325. "format": "mp4",
  326. "mediaType": "video",
  327. "encryptType": 1,
  328. "progressMarkers": this.progressMarkers,
  329. "width": '100%',
  330. "height": '500px',
  331. "autoplay": false,
  332. "isLive": false,
  333. "rePlay": false,
  334. "playsinline": true,
  335. "preload": false,
  336. "controlBarVisibility": "hover",
  337. "useH5Prism": true
  338. }, function(player) {});
  339. this.player = player;
  340. player.on('canplay', function() {
  341. console.log('canplay', this.player.tag);
  342. player.tag.play();
  343. });
  344. player.on('ended', function() {
  345. that.$ownerInstance.callMethod('playEnd', {
  346. data: 'end'
  347. })
  348. // uni.$emit('playEnd', {
  349. // data: 'end'
  350. // });
  351. });
  352. },
  353. loadWebPlayerSDK() {
  354. return new Promise((resolve, reject) => {
  355. const s_tag = document.createElement('script'); // 引入播放器js
  356. s_tag.type = 'text/javascript';
  357. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  358. s_tag.charset = 'utf-8';
  359. s_tag.onload = () => {
  360. // this.playAli()
  361. resolve();
  362. }
  363. document.body.appendChild(s_tag);
  364. const l_tag = document.createElement('link'); // 引入播放器css
  365. l_tag.rel = 'stylesheet';
  366. l_tag.href =
  367. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  368. document.body.appendChild(l_tag);
  369. });
  370. },
  371. }
  372. }
  373. </script>