lookShipinNew.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 v-for="(item,index) in progressMarkers" :key="index" @click="markersClick(item)">
  18. <view class="title-play-box">
  19. <icon class="course-icon" :style="{backgroundImage: 'url(' + courseIconFun() + ')'}"></icon>
  20. <view class="course-title">{{item.title}}</view>
  21. <!-- <view class="course-play-btn" @click="markersClick(item)">视频讲解</view> -->
  22. </view>
  23. <rich-text :nodes="item.describe" class="course-content-item"></rich-text>
  24. </view>
  25. </view>
  26. </view>
  27. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  28. mask-background-color="rgba(51, 137, 217, 0.95);">
  29. <view :class="courseClass">
  30. <view class="text-score">{{credit}}</view>
  31. <view class="course-btn-box">
  32. <view @click="goBack" class="return-btn"></view>
  33. <view @click="goNext" class="continue-btn"></view>
  34. </view>
  35. </view>
  36. </uni-popup>
  37. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  38. <tip-small-dialog ref="goPayDialogRef" @confirm-btn="goPayPage" :content="tipContent"></tip-small-dialog>
  39. </view>
  40. </template>
  41. <script>
  42. import {
  43. ref
  44. } from 'vue';
  45. import {
  46. onLoad,
  47. onReady
  48. } from '@dcloudio/uni-app';
  49. import {
  50. getVideoAuth,
  51. getVideoAuthYk,
  52. videoWancheng
  53. } from "@/api/shipin.js"
  54. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  55. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  56. import tipSmallDialog from '@/components/dialog/tipSmallDialog.vue'
  57. import {
  58. toast,
  59. getUserIdentity
  60. } from "@/utils/common";
  61. import {
  62. userZhangNextInfo,
  63. } from "@/api/learnPlan.js"
  64. import cacheManager from "@/utils/cacheManager.js";
  65. export default {
  66. data() {
  67. return {
  68. pageData: null, //上个页面获取的视频参数(视频id)
  69. playAuth: "", //播放凭证
  70. progressMarkers: [],
  71. jieName: '',
  72. hideFlag: 'show',
  73. videoId: "", //阿里云视频id
  74. tipContent: '是否前往开通付费',
  75. subjectId: '',
  76. credit: '',
  77. tipFlag: '',
  78. typeId: '',
  79. levelId: '',
  80. seekTime: '',
  81. jieId: '',
  82. courseClass: '',
  83. shipinTitle: '',
  84. cacheZhangInfo: {},
  85. cacheCurrentZhangIndex: '',
  86. YouKeContent: '您当前的身份是游客,想要体验完整内容需注册成用户!'
  87. }
  88. },
  89. components: {
  90. tipMiddleDialog,
  91. tipBigDialog,
  92. tipSmallDialog
  93. },
  94. onLoad(options) {
  95. if (!cacheManager.get('auth')) {
  96. const youkeData = JSON.parse(options.youkePageData)
  97. // 游客
  98. this.videoId = youkeData.jieList.videoId
  99. this.subjectId = youkeData.subjectId
  100. this.levelId = youkeData.levelId
  101. this.typeId = youkeData.typeId
  102. this.tipFlag = youkeData.tipFlag
  103. this.shipinTitle = youkeData.jieName
  104. this.progressMarkers = youkeData.jieList.jiedianList || []
  105. this.getLiveYk(); //获取播放凭证
  106. } else {
  107. this.init(options)
  108. }
  109. },
  110. onHide() {
  111. console.log('onHideonHideonHideonHide');
  112. this.hideFlag = 'hide'
  113. },
  114. onUnload() {
  115. console.log('onUnloadonUnloadonUnloadonUnloadonUnload');
  116. this.hideFlag = 'hide'
  117. },
  118. methods: {
  119. courseBjFun() {
  120. if (!cacheManager.get('auth')) {
  121. switch (Number(this.subjectId)) {
  122. case 1:
  123. return 'static/images/course/couse-shuxue-bj.png'
  124. break;
  125. case 2:
  126. return 'static/images/course/course-yingyu-bj.png'
  127. break;
  128. default:
  129. break;
  130. }
  131. } else {
  132. switch (Number(cacheManager.get('auth').subjectId)) {
  133. case 1:
  134. return 'static/images/course/couse-shuxue-bj.png'
  135. break;
  136. case 2:
  137. return 'static/images/course/course-yingyu-bj.png'
  138. break;
  139. default:
  140. break;
  141. }
  142. }
  143. },
  144. courseIconFun() {
  145. if (!cacheManager.get('auth')) {
  146. switch (Number(this.subjectId)) {
  147. case 1:
  148. return 'static/images/course/shuxue-icon.png'
  149. break;
  150. case 2:
  151. return 'static/images/course/yingyu-icon.png'
  152. break;
  153. default:
  154. break;
  155. }
  156. } else {
  157. switch (Number(cacheManager.get('auth').subjectId)) {
  158. case 1:
  159. return 'static/images/course/shuxue-icon.png'
  160. break;
  161. case 2:
  162. return 'static/images/course/yingyu-icon.png'
  163. break;
  164. default:
  165. break;
  166. }
  167. }
  168. },
  169. init(options) {
  170. this.jieId = options.jieId
  171. if (!(cacheManager.get('zhangInfo') && options.jieId)) {
  172. toast('数据错误,缓存丢失/ jieId丢失')
  173. return false
  174. }
  175. this.cacheCurrentZhangIndex = cacheManager.get('auth').currentZhang
  176. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  177. // let zhang = this.cacheZhangInfo.zhangList.find(zhang => zhang.zhangId == this.zhangId);
  178. // if (!zhang) {
  179. // return
  180. // }
  181. let zhang = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex]
  182. let currentObject = zhang.jieList.find(item => item.jieId == options.jieId);
  183. console.log(currentObject);
  184. this.shipinTitle = currentObject.jieName
  185. this.pageData = {
  186. ...currentObject
  187. }
  188. console.log(this.pageData);
  189. this.videoId = this.pageData.videoId
  190. this.jieName = this.pageData.jieName
  191. this.credit = this.pageData.credit
  192. this.progressMarkers = this.pageData.jiedianList || []
  193. this.getLive(); //获取播放凭证
  194. },
  195. goNextZhang() {
  196. let that = this
  197. cacheManager.updateObject('auth', {
  198. currentZhang: this.cacheCurrentZhangIndex + 1
  199. })
  200. this.cacheZhangInfo = cacheManager.get('zhangInfo')
  201. let zhang = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex + 1]
  202. uni.redirectTo({
  203. url: '/pages/study/lookShipin?jieId=' + zhang.jieList[0].jieId
  204. })
  205. },
  206. playEnd(data) {
  207. console.log('data', data);
  208. console.log('111111');
  209. // #ifdef APP-PLUS
  210. plus.screen.lockOrientation('portrait-primary');
  211. // #endif
  212. const AuthCode = getUserIdentity();
  213. console.log(AuthCode);
  214. if (AuthCode == 'Visitor') {
  215. return false
  216. } else {
  217. let currentJieData = cacheManager.getCurrentJieData('zhangInfo', this.cacheCurrentZhangIndex, this
  218. .jieId)
  219. if (currentJieData.studyFlag == 1) {
  220. // 学完一遍
  221. this.courseClass = 'course-finish-dialog'
  222. this.$refs.popupRef.open();
  223. } else {
  224. cacheManager.updateJieStatus('zhangInfo', this.cacheCurrentZhangIndex, this.jieId)
  225. this.courseClass = 'course-score-dialog'
  226. this.$refs.popupRef.open();
  227. let req = {
  228. credit: this.credit,
  229. jieId: this.jieId,
  230. }
  231. videoWancheng(req).then(res => {
  232. })
  233. }
  234. }
  235. },
  236. goBack() {
  237. // #ifdef APP-PLUS
  238. plus.screen.unlockOrientation();
  239. // #endif
  240. this.$refs.popupRef.close();
  241. this.goUpPage()
  242. },
  243. goNext() {
  244. // #ifdef APP-PLUS
  245. plus.screen.unlockOrientation();
  246. // #endif
  247. this.$refs.popupRef.close();
  248. if (!cacheManager.get('auth')) {
  249. console.log(this);
  250. this.$refs.youkeDialogRef.handleShow();
  251. } else {
  252. const AuthCode = getUserIdentity();
  253. console.log(AuthCode);
  254. if (AuthCode == 'Not-Vip') {
  255. this.$refs.goPayDialogRef.handleShow();
  256. return false
  257. }
  258. // debugger
  259. Number(this.jieId++)
  260. console.log('this.pageData', this.pageData);
  261. let currentObject = this.cacheZhangInfo.zhangList[this.cacheCurrentZhangIndex].jieList.find(item =>
  262. item.jieId == this.jieId);
  263. if (currentObject) {
  264. this.pageData = {
  265. ...currentObject
  266. }
  267. }
  268. // lastFlag是否是本章最后一节,0否1是 type,1视频,2试题
  269. if (this.pageData.lastFlag == 1 && this.pageData.type == 2) {
  270. uni.redirectTo({
  271. url: `/pages/unitTest/index?jieId=` + this.pageData.jieId
  272. })
  273. } else if (this.pageData.lastFlag == 1 && this.pageData.type == 1) {
  274. // 当前是本章最后一节,并且是 视频 切换下一章
  275. //this.goNextZhang()
  276. this.goUpPage()
  277. } else {
  278. uni.redirectTo({
  279. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  280. url: '/pages/study/lookShipinNew?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>