lookShipin.vue 16 KB

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