lookShipinNew.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. <template>
  2. <view class="ezy-course-page" :style="{backgroundImage: 'url(' + courseBjFun() + ')'}">
  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 class="course-body-box">
  8. <view class="ezy-video-box course-video-box">
  9. <view ref="videoContent" id="wgy-player-test" :playAuth="playAuth"
  10. :change:playAuth="renderScript.receiveMsg" :videoId="videoId"
  11. :change:videoId="renderScript.videoIdFun" :hideFlag="hideFlag"
  12. :change:hideFlag="renderScript.hideFlagFun" :progressMarkers="progressMarkers"
  13. :change:progressMarkers="renderScript.progressMarkersMsg" :seekTime="seekTime"
  14. :change:seekTime="renderScript.seekTimeFun" class="ezy-video">
  15. </view>
  16. </view>
  17. </view>
  18. <view class="course-content-border">
  19. <view class="course-content-box">
  20. <view v-for="(item,index) in progressMarkers" :key="index" @click="markersClick(item)">
  21. <view class="title-play-box">
  22. <icon class="course-icon" :style="{backgroundImage: 'url(' + courseIconFun() + ')'}"></icon>
  23. <view class="course-title">{{item.title}}</view>
  24. <!-- <view class="course-play-btn" @click="markersClick(item)">视频讲解</view> -->
  25. </view>
  26. <rich-text :nodes="item.describe" class="course-content-item"></rich-text>
  27. </view>
  28. </view>
  29. </view>
  30. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  31. mask-background-color="rgba(51, 137, 217, 0.95);">
  32. <view :class="courseClass">
  33. <view class="text-score">{{credit}}</view>
  34. <view class="course-btn-box">
  35. <view @click="goBack" class="return-btn"></view>
  36. <view @click="goNext" class="continue-btn"></view>
  37. </view>
  38. </view>
  39. </uni-popup>
  40. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  41. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. ref
  47. } from 'vue';
  48. import {
  49. onLoad,
  50. onReady
  51. } from '@dcloudio/uni-app';
  52. import {
  53. getVideoAuth,
  54. getVideoAuthYk,
  55. videoWancheng
  56. } from "@/api/shipin.js"
  57. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  58. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  59. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  60. import {
  61. toast,
  62. getUserIdentity
  63. } from "@/utils/common";
  64. import {
  65. userZhangNextInfo,
  66. } from "@/api/learnPlan.js"
  67. import cacheManager from "@/utils/cacheManager.js";
  68. export default {
  69. data() {
  70. return {
  71. pageData: null, //上个页面获取的视频参数(视频id)
  72. playAuth: "", //播放凭证
  73. progressMarkers: [],
  74. jieName: '',
  75. hideFlag: 'show',
  76. videoId: "", //阿里云视频id
  77. tipContent: '是否前往开通付费',
  78. subjectId: '',
  79. credit: '',
  80. tipFlag: '',
  81. typeId: '',
  82. levelId: '',
  83. seekTime: '',
  84. jieId: '',
  85. courseClass: '',
  86. shipinTitle: '',
  87. cacheZhangInfo: {},
  88. cacheCurrentZhangIndex: '',
  89. YouKeContent: '您当前的身份是游客,想要体验完整内容需注册成用户!'
  90. }
  91. },
  92. components: {
  93. tipMiddleDialog,
  94. tipBigDialog,
  95. tipSmallDialog
  96. },
  97. onLoad(options) {
  98. if (!cacheManager.get('auth')) {
  99. const youkeData = JSON.parse(options.youkePageData)
  100. // 游客
  101. this.videoId = youkeData.jieList.videoId
  102. this.subjectId = youkeData.subjectId
  103. this.levelId = youkeData.levelId
  104. this.typeId = youkeData.typeId
  105. this.tipFlag = youkeData.tipFlag
  106. this.shipinTitle = youkeData.jieName
  107. this.progressMarkers = youkeData.jieList.jiedianList || []
  108. this.getLiveYk(); //获取播放凭证
  109. } else {
  110. this.init(options)
  111. }
  112. },
  113. onHide() {
  114. console.log('onHideonHideonHideonHide');
  115. this.hideFlag = 'hide'
  116. },
  117. onUnload() {
  118. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  119. this.hideFlag = 'hide'
  120. },
  121. methods: {
  122. courseBjFun() {
  123. switch (Number(cacheManager.get('auth').cardId)) {
  124. case 1:
  125. return 'static/images/course/couse-shuxue-bj.png'
  126. break;
  127. case 2:
  128. return 'static/images/course/course-yingyu-bj.png'
  129. break;
  130. default:
  131. break;
  132. }
  133. },
  134. courseIconFun() {
  135. switch (Number(cacheManager.get('auth').cardId)) {
  136. case 1:
  137. return 'static/images/course/shuxue-icon.png'
  138. break;
  139. case 2:
  140. return 'static/images/course/yingyu-icon.png'
  141. break;
  142. default:
  143. break;
  144. }
  145. },
  146. init(options) {
  147. this.jieId = options.jieId
  148. if (!(cacheManager.get('zhangInfo') && options.jieId)) {
  149. toast('数据错误,缓存丢失/ jieId丢失')
  150. return false
  151. }
  152. this.cacheCurrentZhangIndex = cacheManager.get('auth').currentZhang
  153. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  154. // let zhang = this.cacheZhangInfo.zhangList.find(zhang => zhang.zhangId == this.zhangId);
  155. // if (!zhang) {
  156. // return
  157. // }
  158. let zhang = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex]
  159. let currentObject = zhang.jieList.find(item => item.jieId == options.jieId);
  160. console.log(currentObject);
  161. this.shipinTitle = currentObject.jieName
  162. this.pageData = {
  163. ...currentObject
  164. }
  165. console.log(this.pageData);
  166. this.videoId = this.pageData.videoId
  167. this.jieName = this.pageData.jieName
  168. this.credit = this.pageData.credit
  169. this.progressMarkers = this.pageData.jiedianList || []
  170. this.getLive(); //获取播放凭证
  171. },
  172. goNextZhang() {
  173. let that = this
  174. cacheManager.updateObject('auth', {
  175. currentZhang: this.cacheCurrentZhangIndex + 1
  176. })
  177. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  178. let zhang = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex + 1]
  179. uni.redirectTo({
  180. url: '/pages/study/lookShipin?jieId=' + zhang.jieList[0].jieId
  181. })
  182. },
  183. playEnd(data) {
  184. console.log('data', data);
  185. console.log('111111');
  186. // #ifdef APP-PLUS
  187. plus.screen.lockOrientation('portrait-primary');
  188. // #endif
  189. const AuthCode = getUserIdentity();
  190. console.log(AuthCode);
  191. if (AuthCode == 'Visitor') {
  192. return false
  193. } else {
  194. let currentJieData = cacheManager.getCurrentJieData('zhangInfo', this.cacheCurrentZhangIndex, this
  195. .jieId)
  196. if (currentJieData.studyFlag == 1) {
  197. // 学完一遍
  198. this.courseClass = 'course-finish-dialog'
  199. this.$refs.popupRef.open();
  200. } else {
  201. cacheManager.updateJieStatus('zhangInfo', this.cacheCurrentZhangIndex, this.jieId)
  202. this.courseClass = 'course-score-dialog'
  203. this.$refs.popupRef.open();
  204. let req = {
  205. credit: this.credit,
  206. jieId: this.jieId,
  207. }
  208. videoWancheng(req).then(res => {
  209. })
  210. }
  211. }
  212. },
  213. goBack() {
  214. // #ifdef APP-PLUS
  215. plus.screen.unlockOrientation();
  216. // #endif
  217. this.$refs.popupRef.close();
  218. this.goUpPage()
  219. },
  220. goNext() {
  221. // #ifdef APP-PLUS
  222. plus.screen.unlockOrientation();
  223. // #endif
  224. this.$refs.popupRef.close();
  225. if (!cacheManager.get('auth')) {
  226. console.log(this);
  227. this.$refs.youkeDialogRef.handleShow();
  228. } else {
  229. const AuthCode = getUserIdentity();
  230. console.log(AuthCode);
  231. if (AuthCode == 'Not-Vip') {
  232. this.$refs.goPayDialogRef.handleShow();
  233. return false
  234. }
  235. // debugger
  236. Number(this.jieId++)
  237. console.log('this.pageData', this.pageData);
  238. let currentObject = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex].jieList.find(item =>
  239. item.jieId == this.jieId);
  240. if (currentObject) {
  241. this.pageData = {
  242. ...currentObject
  243. }
  244. }
  245. // lastFlag是否是本章最后一节,0否1是 type,1视频,2试题
  246. if (this.pageData.lastFlag == 1 && this.pageData.type == 2) {
  247. uni.redirectTo({
  248. url: `/pages/unitTest/index?jieId=` + this.pageData.jieId
  249. })
  250. } else if (this.pageData.lastFlag == 1 && this.pageData.type == 1) {
  251. // 当前是本章最后一节,并且是 视频 切换下一章
  252. this.goNextZhang()
  253. } else {
  254. uni.redirectTo({
  255. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  256. url: '/pages/study/lookShipinNew?jieId=' + this.jieId
  257. })
  258. }
  259. }
  260. },
  261. getLiveYk() {
  262. if (!this.videoId) {
  263. toast("video缺失!")
  264. return false
  265. }
  266. let req = {
  267. videoId: this.videoId
  268. }
  269. getVideoAuthYk(req).then(res => {
  270. this.playAuth = res.data
  271. })
  272. },
  273. getLive() {
  274. if (!this.videoId) {
  275. toast("video缺失!")
  276. return false
  277. }
  278. let req = {
  279. videoId: this.videoId
  280. }
  281. getVideoAuth(req).then(res => {
  282. this.playAuth = res.data
  283. })
  284. },
  285. markersClick(data) {
  286. this.seekTime = ""
  287. this.$nextTick(() => {
  288. this.seekTime = data.offset
  289. });
  290. },
  291. goUpPage() {
  292. if (!cacheManager.get('auth')) {
  293. uni.redirectTo({
  294. url: '/pages/study/index?levelId=' + this.levelId + '&typeId=' + this.typeId +
  295. '&subjectId=' +
  296. this.subjectId + '&tipFlag=' + this.tipFlag
  297. })
  298. } else {
  299. uni.redirectTo({
  300. url: `/pages/study/index`
  301. })
  302. }
  303. },
  304. goPayPage() {
  305. let zhangInfoLocal = cacheManager.get('zhangInfo')
  306. if (!zhangInfoLocal.cardId) {
  307. toast("cardId 丢失请重新选择学科LevelId");
  308. return false
  309. }
  310. uni.redirectTo({
  311. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  312. zhangInfoLocal.subjectId
  313. })
  314. },
  315. ykConfirm() {
  316. uni.redirectTo({
  317. url: '/pages/login/index'
  318. });
  319. }
  320. },
  321. created() {
  322. // console.log("getLive")
  323. // this.getLive(); //获取播放凭证
  324. },
  325. }
  326. </script>
  327. <script module="renderScript" lang="renderjs">
  328. export default {
  329. mounted() {
  330. console.log("renderScript1")
  331. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  332. // this.loadWebPlayerSDK()
  333. },
  334. data() {
  335. return {
  336. player: null,
  337. playAuth: '',
  338. videoId: '',
  339. progressMarkers: [],
  340. isFullScreen: false,
  341. seekTime: ''
  342. }
  343. },
  344. methods: {
  345. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  346. // console.log('service层中的options发生变化')
  347. // console.log('新值', newValue)
  348. // console.log('旧值', oldValue)
  349. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  350. // instance和ownerInstance的区别是:
  351. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  352. // instance的作用目前尚不明确,官方没有给出用法
  353. if (newValue) {
  354. this.playAuth = ''
  355. this.playAuth = newValue
  356. this.loadWebPlayerSDK()
  357. }
  358. },
  359. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  360. if (newValue) {
  361. this.videoId = ''
  362. this.videoId = newValue
  363. }
  364. },
  365. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  366. if (this.player) {
  367. this.player.pause()
  368. }
  369. },
  370. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  371. if (newValue) {
  372. this.progressMarkers = newValue
  373. }
  374. },
  375. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  376. if (newValue) {
  377. this.player.play()
  378. this.player.seek(newValue)
  379. // switch (this.player.getStatus()) {
  380. // case 'init':
  381. // break;
  382. // case 'ready':
  383. // break;
  384. // case 'loading':
  385. // this.player.play()
  386. // this.player.seek(newValue)
  387. // break;
  388. // case 'play':
  389. // this.player.seek(newValue)
  390. // break;
  391. // case 'pause':
  392. // this.player.play()
  393. // this.player.seek(newValue)
  394. // break;
  395. // case 'playing':
  396. // this.player.seek(newValue)
  397. // break;
  398. // case 'waiting':
  399. // break;
  400. // case 'error':
  401. // break;
  402. // case 'ended':
  403. // break;
  404. // default:
  405. // break;
  406. // }
  407. // this.player.seek(newValue)
  408. }
  409. },
  410. playAli() {
  411. let that = this
  412. // console.log(this.videoId);
  413. // console.log(this.playAuth);
  414. //配置播放器
  415. if (!this.playAuth) {
  416. return false;
  417. }
  418. var player = new Aliplayer({
  419. id: "wgy-player-test",
  420. "vid": this.videoId,
  421. "playauth": this.playAuth,
  422. extraInfo: {
  423. poster: 'noposter'
  424. },
  425. fullscreenEvents: {
  426. fullscreenChange: (isFull) => {
  427. this.isFullScreen = isFull
  428. }
  429. },
  430. //cover: 'https://img.alicdn.com/tps/TB1EXIhOFXXXXcIaXXXXXXXXXXX-760-340.jpg',
  431. // "vid": '',
  432. // "playauth": '',
  433. // "playConfig": {
  434. // "EncryptType": 'AliyunVoDEncryption'
  435. // },
  436. "skinLayout": [{
  437. "name": "bigPlayButton",
  438. "align": "blabs",
  439. "x": 30,
  440. "y": 80
  441. },
  442. {
  443. "name": "H5Loading",
  444. "align": "cc"
  445. },
  446. {
  447. "name": "controlBar",
  448. "align": "blabs",
  449. "x": 0,
  450. "y": 0,
  451. "children": [{
  452. "name": "progress",
  453. "align": "blabs",
  454. "x": 0,
  455. "y": 44
  456. },
  457. {
  458. "name": "playButton",
  459. "align": "tl",
  460. "x": 15,
  461. "y": 12
  462. },
  463. {
  464. "name": "fullScreenButton",
  465. "align": "tr",
  466. "x": 10,
  467. "y": 12
  468. },
  469. {
  470. "name": "timeDisplay",
  471. "align": "tr",
  472. "x": 10,
  473. "y": 5
  474. }
  475. ]
  476. }
  477. ],
  478. "qualitySort": "asc",
  479. "format": "mp4",
  480. "mediaType": "video",
  481. "encryptType": 1,
  482. "progressMarkers": this.progressMarkers,
  483. "autoplay": false,
  484. "isLive": false,
  485. "rePlay": false,
  486. "playsinline": true,
  487. "preload": false,
  488. "controlBarVisibility": "hover",
  489. "useH5Prism": true
  490. }, function(player) {});
  491. this.player = player;
  492. player.on('canplay', function() {
  493. console.log('canplay', this.player.tag);
  494. player.tag.play();
  495. });
  496. player.on('ended', function(data) {
  497. that.exitFullScreen();
  498. that.$ownerInstance.callMethod('playEnd', {
  499. data: 'end'
  500. })
  501. // uni.$emit('playEnd', {
  502. // data: 'end'
  503. // });
  504. });
  505. },
  506. exitFullScreen() {
  507. if (document.exitFullscreen) {
  508. document.exitFullscreen(); // 标准方法
  509. } else if (document.mozCancelFullScreen) { // Firefox
  510. document.mozCancelFullScreen();
  511. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  512. document.webkitExitFullscreen();
  513. } else if (document.msExitFullscreen) { // IE/Edge
  514. document.msExitFullscreen();
  515. }
  516. },
  517. loadWebPlayerSDK() {
  518. return new Promise((resolve, reject) => {
  519. const s_tag = document.createElement('script'); // 引入播放器js
  520. s_tag.type = 'text/javascript';
  521. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  522. s_tag.charset = 'utf-8';
  523. s_tag.onload = () => {
  524. // console.log(this.playAuth);
  525. this.playAli()
  526. resolve();
  527. }
  528. document.body.appendChild(s_tag);
  529. const l_tag = document.createElement('link'); // 引入播放器css
  530. l_tag.rel = 'stylesheet';
  531. l_tag.href =
  532. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  533. document.body.appendChild(l_tag);
  534. });
  535. },
  536. }
  537. }
  538. </script>