lookShipin.vue 15 KB

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