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