lookShipin.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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. this.cacheCurrentZhangIndex = cacheManager.get('auth').currentZhang
  177. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  178. // let zhang = this.cacheZhangInfo.zhangList.find(zhang => zhang.zhangId == this.zhangId);
  179. // if (!zhang) {
  180. // return
  181. // }
  182. let zhang = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex]
  183. let currentObject = zhang.jieList.find(item => item.jieId == options.jieId);
  184. console.log(currentObject);
  185. this.shipinTitle = currentObject.jieName
  186. this.pageData = {
  187. ...currentObject
  188. }
  189. console.log(this.pageData);
  190. this.videoId = this.pageData.videoId
  191. this.jieName = this.pageData.jieName
  192. this.credit = this.pageData.credit
  193. this.progressMarkers = this.pageData.jiedianList || []
  194. this.getLive(); //获取播放凭证
  195. },
  196. goNextZhang() {
  197. let that = this
  198. cacheManager.updateObject('auth', {
  199. currentZhang: this.cacheCurrentZhangIndex + 1
  200. })
  201. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  202. let zhang = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex + 1]
  203. uni.redirectTo({
  204. url: '/pages/study/lookShipin?jieId=' + zhang.jieList[0].jieId
  205. })
  206. },
  207. playEnd(data) {
  208. console.log('data', data);
  209. console.log('111111');
  210. // #ifdef APP-PLUS
  211. plus.screen.lockOrientation('portrait-primary');
  212. // #endif
  213. const AuthCode = getUserIdentity();
  214. console.log(AuthCode);
  215. if (AuthCode == 'Visitor') {
  216. return false
  217. } else {
  218. let currentJieData = cacheManager.getCurrentJieData('zhangInfo', this.cacheCurrentZhangIndex, this
  219. .jieId)
  220. if (currentJieData.studyFlag == 1) {
  221. // 学完一遍
  222. this.courseClass = 'course-finish-dialog'
  223. this.$refs.popupRef.open();
  224. } else {
  225. cacheManager.updateJieStatus('zhangInfo', this.cacheCurrentZhangIndex, this.jieId)
  226. this.courseClass = 'course-score-dialog'
  227. this.$refs.popupRef.open();
  228. let req = {
  229. credit: this.credit,
  230. jieId: this.jieId,
  231. }
  232. videoWancheng(req).then(res => {
  233. })
  234. }
  235. }
  236. },
  237. goBack() {
  238. // #ifdef APP-PLUS
  239. plus.screen.unlockOrientation();
  240. // #endif
  241. this.$refs.popupRef.close();
  242. this.goUpPage()
  243. },
  244. goNext() {
  245. // #ifdef APP-PLUS
  246. plus.screen.unlockOrientation();
  247. // #endif
  248. this.$refs.popupRef.close();
  249. if (!cacheManager.get('auth')) {
  250. console.log(this);
  251. this.$refs.youkeDialogRef.handleShow();
  252. } else {
  253. const AuthCode = getUserIdentity();
  254. console.log(AuthCode);
  255. if (AuthCode == 'Not-Vip') {
  256. this.$refs.goPayDialogRef.handleShow();
  257. return false
  258. }
  259. // debugger
  260. Number(this.jieId++)
  261. console.log('this.pageData', this.pageData);
  262. let currentObject = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex].jieList.find(item =>
  263. item.jieId == this.jieId);
  264. if (currentObject) {
  265. this.pageData = {
  266. ...currentObject
  267. }
  268. }
  269. // lastFlag是否是本章最后一节,0否1是 type,1视频,2试题
  270. if (this.pageData.lastFlag == 1 && this.pageData.type == 2) {
  271. uni.redirectTo({
  272. url: `/pages/unitTest/index?jieId=` + this.pageData.jieId
  273. })
  274. } else if (this.pageData.lastFlag == 1 && this.pageData.type == 1) {
  275. // 当前是本章最后一节,并且是 视频 切换下一章
  276. this.goNextZhang()
  277. } else {
  278. uni.redirectTo({
  279. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  280. url: '/pages/study/lookShipin?jieId=' + this.jieId
  281. })
  282. }
  283. }
  284. },
  285. getLiveYk() {
  286. if (!this.videoId) {
  287. toast("video缺失!")
  288. return false
  289. }
  290. let req = {
  291. videoId: this.videoId
  292. }
  293. getVideoAuthYk(req).then(res => {
  294. this.playAuth = res.data
  295. })
  296. },
  297. getLive() {
  298. if (!this.videoId) {
  299. toast("video缺失!")
  300. return false
  301. }
  302. let req = {
  303. videoId: this.videoId
  304. }
  305. getVideoAuth(req).then(res => {
  306. this.playAuth = res.data
  307. })
  308. },
  309. markersClick(data) {
  310. this.seekTime = ""
  311. this.$nextTick(() => {
  312. this.seekTime = data.offset
  313. });
  314. },
  315. goUpPage() {
  316. if (!cacheManager.get('auth')) {
  317. uni.redirectTo({
  318. url: '/pages/study/index?levelId=' + this.levelId + '&typeId=' + this.typeId +
  319. '&subjectId=' +
  320. this.subjectId + '&tipFlag=' + this.tipFlag
  321. })
  322. } else {
  323. uni.redirectTo({
  324. url: `/pages/study/index`
  325. })
  326. }
  327. },
  328. goPayPage() {
  329. let zhangInfoLocal = cacheManager.get('zhangInfo')
  330. if (!zhangInfoLocal.cardId) {
  331. toast("cardId 丢失请重新选择学科LevelId");
  332. return false
  333. }
  334. uni.redirectTo({
  335. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  336. zhangInfoLocal.subjectId
  337. })
  338. },
  339. ykConfirm() {
  340. uni.redirectTo({
  341. url: '/pages/login/index'
  342. });
  343. }
  344. },
  345. created() {
  346. // console.log("getLive")
  347. // this.getLive(); //获取播放凭证
  348. },
  349. }
  350. </script>
  351. <script module="renderScript" lang="renderjs">
  352. export default {
  353. mounted() {
  354. console.log("renderScript1")
  355. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  356. // this.loadWebPlayerSDK()
  357. },
  358. data() {
  359. return {
  360. player: null,
  361. playAuth: '',
  362. videoId: '',
  363. progressMarkers: [],
  364. isFullScreen: false,
  365. seekTime: ''
  366. }
  367. },
  368. methods: {
  369. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  370. // console.log('service层中的options发生变化')
  371. // console.log('新值', newValue)
  372. // console.log('旧值', oldValue)
  373. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  374. // instance和ownerInstance的区别是:
  375. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  376. // instance的作用目前尚不明确,官方没有给出用法
  377. if (newValue) {
  378. this.playAuth = ''
  379. this.playAuth = newValue
  380. this.loadWebPlayerSDK()
  381. }
  382. },
  383. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  384. if (newValue) {
  385. this.videoId = ''
  386. this.videoId = newValue
  387. }
  388. },
  389. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  390. if (this.player) {
  391. this.player.pause()
  392. }
  393. },
  394. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  395. if (newValue) {
  396. this.progressMarkers = newValue
  397. }
  398. },
  399. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  400. if (newValue) {
  401. this.player.play()
  402. this.player.seek(newValue)
  403. // switch (this.player.getStatus()) {
  404. // case 'init':
  405. // break;
  406. // case 'ready':
  407. // break;
  408. // case 'loading':
  409. // this.player.play()
  410. // this.player.seek(newValue)
  411. // break;
  412. // case 'play':
  413. // this.player.seek(newValue)
  414. // break;
  415. // case 'pause':
  416. // this.player.play()
  417. // this.player.seek(newValue)
  418. // break;
  419. // case 'playing':
  420. // this.player.seek(newValue)
  421. // break;
  422. // case 'waiting':
  423. // break;
  424. // case 'error':
  425. // break;
  426. // case 'ended':
  427. // break;
  428. // default:
  429. // break;
  430. // }
  431. // this.player.seek(newValue)
  432. }
  433. },
  434. playAli() {
  435. let that = this
  436. // console.log(this.videoId);
  437. // console.log(this.playAuth);
  438. //配置播放器
  439. if (!this.playAuth) {
  440. return false;
  441. }
  442. var player = new Aliplayer({
  443. id: "wgy-player-test",
  444. "vid": this.videoId,
  445. "playauth": this.playAuth,
  446. extraInfo: {
  447. poster: 'noposter'
  448. },
  449. fullscreenEvents: {
  450. fullscreenChange: (isFull) => {
  451. this.isFullScreen = isFull
  452. }
  453. },
  454. //cover: 'https://img.alicdn.com/tps/TB1EXIhOFXXXXcIaXXXXXXXXXXX-760-340.jpg',
  455. // "vid": '',
  456. // "playauth": '',
  457. // "playConfig": {
  458. // "EncryptType": 'AliyunVoDEncryption'
  459. // },
  460. "skinLayout": [{
  461. "name": "bigPlayButton",
  462. "align": "blabs",
  463. "x": 30,
  464. "y": 80
  465. },
  466. {
  467. "name": "H5Loading",
  468. "align": "cc"
  469. },
  470. {
  471. "name": "controlBar",
  472. "align": "blabs",
  473. "x": 0,
  474. "y": 0,
  475. "children": [{
  476. "name": "progress",
  477. "align": "blabs",
  478. "x": 0,
  479. "y": 44
  480. },
  481. {
  482. "name": "playButton",
  483. "align": "tl",
  484. "x": 15,
  485. "y": 12
  486. },
  487. {
  488. "name": "fullScreenButton",
  489. "align": "tr",
  490. "x": 10,
  491. "y": 12
  492. },
  493. {
  494. "name": "timeDisplay",
  495. "align": "tr",
  496. "x": 10,
  497. "y": 5
  498. }
  499. ]
  500. }
  501. ],
  502. "qualitySort": "asc",
  503. "format": "mp4",
  504. "mediaType": "video",
  505. "encryptType": 1,
  506. "progressMarkers": this.progressMarkers,
  507. "autoplay": false,
  508. "isLive": false,
  509. "rePlay": false,
  510. "playsinline": true,
  511. "preload": false,
  512. "controlBarVisibility": "hover",
  513. "useH5Prism": true
  514. }, function(player) {});
  515. this.player = player;
  516. player.on('canplay', function() {
  517. console.log('canplay', this.player.tag);
  518. player.tag.play();
  519. });
  520. player.on('ended', function(data) {
  521. that.exitFullScreen();
  522. that.$ownerInstance.callMethod('playEnd', {
  523. data: 'end'
  524. })
  525. // uni.$emit('playEnd', {
  526. // data: 'end'
  527. // });
  528. });
  529. },
  530. exitFullScreen() {
  531. if (document.exitFullscreen) {
  532. document.exitFullscreen(); // 标准方法
  533. } else if (document.mozCancelFullScreen) { // Firefox
  534. document.mozCancelFullScreen();
  535. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  536. document.webkitExitFullscreen();
  537. } else if (document.msExitFullscreen) { // IE/Edge
  538. document.msExitFullscreen();
  539. }
  540. },
  541. loadWebPlayerSDK() {
  542. return new Promise((resolve, reject) => {
  543. const s_tag = document.createElement('script'); // 引入播放器js
  544. s_tag.type = 'text/javascript';
  545. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  546. s_tag.charset = 'utf-8';
  547. s_tag.onload = () => {
  548. // console.log(this.playAuth);
  549. this.playAli()
  550. resolve();
  551. }
  552. document.body.appendChild(s_tag);
  553. const l_tag = document.createElement('link'); // 引入播放器css
  554. l_tag.rel = 'stylesheet';
  555. l_tag.href =
  556. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  557. document.body.appendChild(l_tag);
  558. });
  559. },
  560. }
  561. }
  562. </script>