lookShipin.vue 11 KB

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