lookShipinNew.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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. this.goUpPage()
  254. } else {
  255. uni.redirectTo({
  256. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  257. url: '/pages/study/lookShipinNew?jieId=' + this.jieId
  258. })
  259. }
  260. }
  261. },
  262. getLiveYk() {
  263. if (!this.videoId) {
  264. toast("video缺失!")
  265. return false
  266. }
  267. let req = {
  268. videoId: this.videoId
  269. }
  270. getVideoAuthYk(req).then(res => {
  271. this.playAuth = res.data
  272. })
  273. },
  274. getLive() {
  275. if (!this.videoId) {
  276. toast("video缺失!")
  277. return false
  278. }
  279. let req = {
  280. videoId: this.videoId
  281. }
  282. getVideoAuth(req).then(res => {
  283. this.playAuth = res.data
  284. })
  285. },
  286. markersClick(data) {
  287. this.seekTime = ""
  288. this.$nextTick(() => {
  289. this.seekTime = data.offset
  290. });
  291. },
  292. goUpPage() {
  293. if (!cacheManager.get('auth')) {
  294. uni.redirectTo({
  295. url: '/pages/study/index?levelId=' + this.levelId + '&typeId=' + this.typeId +
  296. '&subjectId=' +
  297. this.subjectId + '&tipFlag=' + this.tipFlag
  298. })
  299. } else {
  300. uni.redirectTo({
  301. url: `/pages/study/index`
  302. })
  303. }
  304. },
  305. goPayPage() {
  306. let zhangInfoLocal = cacheManager.get('zhangInfo')
  307. if (!zhangInfoLocal.cardId) {
  308. toast("cardId 丢失请重新选择学科LevelId");
  309. return false
  310. }
  311. uni.redirectTo({
  312. url: '/pages/mall/mallPage?cardId=' + zhangInfoLocal.cardId + '&from=daoPage' + '&subjectId=' +
  313. zhangInfoLocal.subjectId
  314. })
  315. },
  316. ykConfirm() {
  317. uni.redirectTo({
  318. url: '/pages/login/index'
  319. });
  320. }
  321. },
  322. created() {
  323. // console.log("getLive")
  324. // this.getLive(); //获取播放凭证
  325. },
  326. }
  327. </script>
  328. <script module="renderScript" lang="renderjs">
  329. export default {
  330. mounted() {
  331. console.log("renderScript1")
  332. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  333. // this.loadWebPlayerSDK()
  334. },
  335. data() {
  336. return {
  337. player: null,
  338. playAuth: '',
  339. videoId: '',
  340. progressMarkers: [],
  341. isFullScreen: false,
  342. seekTime: ''
  343. }
  344. },
  345. methods: {
  346. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  347. // console.log('service层中的options发生变化')
  348. // console.log('新值', newValue)
  349. // console.log('旧值', oldValue)
  350. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  351. // instance和ownerInstance的区别是:
  352. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  353. // instance的作用目前尚不明确,官方没有给出用法
  354. if (newValue) {
  355. this.playAuth = ''
  356. this.playAuth = newValue
  357. this.loadWebPlayerSDK()
  358. }
  359. },
  360. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  361. if (newValue) {
  362. this.videoId = ''
  363. this.videoId = newValue
  364. }
  365. },
  366. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  367. if (this.player) {
  368. this.player.pause()
  369. }
  370. },
  371. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  372. if (newValue) {
  373. this.progressMarkers = newValue
  374. }
  375. },
  376. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  377. if (newValue) {
  378. this.player.play()
  379. this.player.seek(newValue)
  380. // switch (this.player.getStatus()) {
  381. // case 'init':
  382. // break;
  383. // case 'ready':
  384. // break;
  385. // case 'loading':
  386. // this.player.play()
  387. // this.player.seek(newValue)
  388. // break;
  389. // case 'play':
  390. // this.player.seek(newValue)
  391. // break;
  392. // case 'pause':
  393. // this.player.play()
  394. // this.player.seek(newValue)
  395. // break;
  396. // case 'playing':
  397. // this.player.seek(newValue)
  398. // break;
  399. // case 'waiting':
  400. // break;
  401. // case 'error':
  402. // break;
  403. // case 'ended':
  404. // break;
  405. // default:
  406. // break;
  407. // }
  408. // this.player.seek(newValue)
  409. }
  410. },
  411. playAli() {
  412. let that = this
  413. // console.log(this.videoId);
  414. // console.log(this.playAuth);
  415. //配置播放器
  416. if (!this.playAuth) {
  417. return false;
  418. }
  419. var player = new Aliplayer({
  420. id: "wgy-player-test",
  421. "vid": this.videoId,
  422. "playauth": this.playAuth,
  423. extraInfo: {
  424. poster: 'noposter'
  425. },
  426. fullscreenEvents: {
  427. fullscreenChange: (isFull) => {
  428. this.isFullScreen = isFull
  429. }
  430. },
  431. //cover: 'https://img.alicdn.com/tps/TB1EXIhOFXXXXcIaXXXXXXXXXXX-760-340.jpg',
  432. // "vid": '',
  433. // "playauth": '',
  434. // "playConfig": {
  435. // "EncryptType": 'AliyunVoDEncryption'
  436. // },
  437. "skinLayout": [{
  438. "name": "bigPlayButton",
  439. "align": "blabs",
  440. "x": 30,
  441. "y": 80
  442. },
  443. {
  444. "name": "H5Loading",
  445. "align": "cc"
  446. },
  447. {
  448. "name": "controlBar",
  449. "align": "blabs",
  450. "x": 0,
  451. "y": 0,
  452. "children": [{
  453. "name": "progress",
  454. "align": "blabs",
  455. "x": 0,
  456. "y": 44
  457. },
  458. {
  459. "name": "playButton",
  460. "align": "tl",
  461. "x": 15,
  462. "y": 12
  463. },
  464. {
  465. "name": "fullScreenButton",
  466. "align": "tr",
  467. "x": 10,
  468. "y": 12
  469. },
  470. {
  471. "name": "timeDisplay",
  472. "align": "tr",
  473. "x": 10,
  474. "y": 5
  475. }
  476. ]
  477. }
  478. ],
  479. "qualitySort": "asc",
  480. "format": "mp4",
  481. "mediaType": "video",
  482. "encryptType": 1,
  483. "progressMarkers": this.progressMarkers,
  484. "autoplay": false,
  485. "isLive": false,
  486. "rePlay": false,
  487. "playsinline": true,
  488. "preload": false,
  489. "controlBarVisibility": "hover",
  490. "useH5Prism": true
  491. }, function(player) {});
  492. this.player = player;
  493. player.on('canplay', function() {
  494. console.log('canplay', this.player.tag);
  495. player.tag.play();
  496. });
  497. player.on('ended', function(data) {
  498. that.exitFullScreen();
  499. that.$ownerInstance.callMethod('playEnd', {
  500. data: 'end'
  501. })
  502. // uni.$emit('playEnd', {
  503. // data: 'end'
  504. // });
  505. });
  506. },
  507. exitFullScreen() {
  508. if (document.exitFullscreen) {
  509. document.exitFullscreen(); // 标准方法
  510. } else if (document.mozCancelFullScreen) { // Firefox
  511. document.mozCancelFullScreen();
  512. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  513. document.webkitExitFullscreen();
  514. } else if (document.msExitFullscreen) { // IE/Edge
  515. document.msExitFullscreen();
  516. }
  517. },
  518. loadWebPlayerSDK() {
  519. return new Promise((resolve, reject) => {
  520. const s_tag = document.createElement('script'); // 引入播放器js
  521. s_tag.type = 'text/javascript';
  522. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  523. s_tag.charset = 'utf-8';
  524. s_tag.onload = () => {
  525. // console.log(this.playAuth);
  526. this.playAli()
  527. resolve();
  528. }
  529. document.body.appendChild(s_tag);
  530. const l_tag = document.createElement('link'); // 引入播放器css
  531. l_tag.rel = 'stylesheet';
  532. l_tag.href =
  533. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  534. document.body.appendChild(l_tag);
  535. });
  536. },
  537. }
  538. }
  539. </script>