lookShipin.vue 11 KB

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