lookShipinNew.vue 15 KB

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