lookShipinNew.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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" :change:videoId="renderScript.videoIdFun"
  11. :hideFlag="hideFlag" :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>
  17. <!-- <view class="course-content-border">
  18. <view class="course-content-box">
  19. <view v-for="(item,index) in progressMarkers" :key="index" @click="markersClick(item)">
  20. <view class="title-play-box">
  21. <icon class="course-icon" :style="{backgroundImage: 'url(' + courseIconFun() + ')'}"></icon>
  22. <view class="course-title">{{item.title}}</view>
  23. <view class="course-play-btn" @click="markersClick(item)">视频讲解</view>
  24. </view>
  25. <rich-text :nodes="item.describe" class="course-content-item"></rich-text>
  26. </view>
  27. </view>
  28. </view> -->
  29. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  30. mask-background-color="rgba(51, 137, 217, 0.95);">
  31. <view :class="courseClass">
  32. <view class="text-score">{{credit}}</view>
  33. <view class="course-btn-box">
  34. <view @click="goBack" class="return-btn"></view>
  35. <view @click="goNext" class="continue-btn"></view>
  36. </view>
  37. </view>
  38. </uni-popup>
  39. <tip-big-dialog ref="youkeDialogRef" @confirm-btn="ykConfirm" :imgShow="true"></tip-big-dialog>
  40. <svip-dialog ref="svipDialogRef" @confirm-btn="svipConfirm"></svip-dialog>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. ref
  46. } from 'vue';
  47. import {
  48. onLoad,
  49. onReady
  50. } from '@dcloudio/uni-app';
  51. import {
  52. getVideoAuth,
  53. getVideoAuthYk,
  54. videoWancheng
  55. } from "@/api/shipin.js"
  56. import tipMiddleDialog from '@/components/dialog/tipMiddleDialog.vue';
  57. import tipBigDialog from '@/components/dialog/tipBigDialog.vue';
  58. import svipDialog from './svipDialog.vue';
  59. import {
  60. toast,
  61. getUserIdentity
  62. } from "@/utils/common";
  63. import {
  64. userZhangNextInfo,
  65. } from "@/api/learnPlan.js"
  66. import cacheManager from "@/utils/cacheManager.js";
  67. export default {
  68. data() {
  69. return {
  70. pageData: null, //上个页面获取的视频参数(视频id)
  71. playAuth: "", //播放凭证
  72. progressMarkers: [],
  73. jieName: '',
  74. hideFlag: 'show',
  75. videoId: "", //阿里云视频id
  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. svipDialog
  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').cardId)) {
  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').cardId)) {
  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.svipDialogRef.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. } else {
  252. uni.redirectTo({
  253. //url: '/pages/study/lookShipin?studyData=' + JSON.stringify(pageData)
  254. url: '/pages/study/lookShipinNew?jieId=' + this.jieId
  255. })
  256. }
  257. }
  258. },
  259. getLiveYk() {
  260. if(!this.videoId){
  261. toast("video缺失!")
  262. return false
  263. }
  264. let req = {
  265. videoId: this.videoId
  266. }
  267. getVideoAuthYk(req).then(res => {
  268. this.playAuth = res.data
  269. })
  270. },
  271. getLive() {
  272. if(!this.videoId){
  273. toast("video缺失!")
  274. return false
  275. }
  276. let req = {
  277. videoId: this.videoId
  278. }
  279. getVideoAuth(req).then(res => {
  280. this.playAuth = res.data
  281. })
  282. },
  283. markersClick(data) {
  284. this.seekTime = ""
  285. this.$nextTick(() => {
  286. this.seekTime = data.offset
  287. });
  288. },
  289. goUpPage() {
  290. if (!cacheManager.get('auth')) {
  291. uni.redirectTo({
  292. url: '/pages/study/index?levelId=' + this.levelId + '&typeId=' + this.typeId + '&subjectId=' +
  293. this.subjectId + '&tipFlag=' + this.tipFlag
  294. })
  295. } else {
  296. uni.redirectTo({
  297. url: `/pages/study/index`
  298. })
  299. }
  300. },
  301. svipConfirm() {
  302. uni.redirectTo({
  303. url: '/pages/pay/svip?cardId=' + cacheManager.get('auth').cardId
  304. })
  305. },
  306. ykConfirm() {
  307. uni.redirectTo({
  308. url: '/pages/login/index'
  309. });
  310. }
  311. },
  312. created() {
  313. // console.log("getLive")
  314. // this.getLive(); //获取播放凭证
  315. },
  316. }
  317. </script>
  318. <script module="renderScript" lang="renderjs">
  319. export default {
  320. mounted() {
  321. console.log("renderScript1")
  322. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  323. // this.loadWebPlayerSDK()
  324. },
  325. data() {
  326. return {
  327. player: null,
  328. playAuth: '',
  329. videoId: '',
  330. progressMarkers: [],
  331. isFullScreen: false,
  332. seekTime: ''
  333. }
  334. },
  335. methods: {
  336. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  337. // console.log('service层中的options发生变化')
  338. // console.log('新值', newValue)
  339. // console.log('旧值', oldValue)
  340. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  341. // instance和ownerInstance的区别是:
  342. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  343. // instance的作用目前尚不明确,官方没有给出用法
  344. if (newValue) {
  345. this.playAuth = ''
  346. this.playAuth = newValue
  347. this.loadWebPlayerSDK()
  348. }
  349. },
  350. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  351. if (newValue) {
  352. this.videoId = ''
  353. this.videoId = newValue
  354. }
  355. },
  356. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  357. if (this.player) {
  358. this.player.pause()
  359. }
  360. },
  361. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  362. if (newValue) {
  363. this.progressMarkers = newValue
  364. }
  365. },
  366. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  367. if (newValue) {
  368. this.player.play()
  369. this.player.seek(newValue)
  370. // switch (this.player.getStatus()) {
  371. // case 'init':
  372. // break;
  373. // case 'ready':
  374. // break;
  375. // case 'loading':
  376. // this.player.play()
  377. // this.player.seek(newValue)
  378. // break;
  379. // case 'play':
  380. // this.player.seek(newValue)
  381. // break;
  382. // case 'pause':
  383. // this.player.play()
  384. // this.player.seek(newValue)
  385. // break;
  386. // case 'playing':
  387. // this.player.seek(newValue)
  388. // break;
  389. // case 'waiting':
  390. // break;
  391. // case 'error':
  392. // break;
  393. // case 'ended':
  394. // break;
  395. // default:
  396. // break;
  397. // }
  398. // this.player.seek(newValue)
  399. }
  400. },
  401. playAli() {
  402. let that = this
  403. // console.log(this.videoId);
  404. // console.log(this.playAuth);
  405. //配置播放器
  406. if (!this.playAuth) {
  407. return false;
  408. }
  409. var player = new Aliplayer({
  410. id: "wgy-player-test",
  411. "vid": this.videoId,
  412. "playauth": this.playAuth,
  413. extraInfo: {
  414. poster: 'noposter'
  415. },
  416. fullscreenEvents: {
  417. fullscreenChange: (isFull) => {
  418. this.isFullScreen = isFull
  419. }
  420. },
  421. //cover: 'https://img.alicdn.com/tps/TB1EXIhOFXXXXcIaXXXXXXXXXXX-760-340.jpg',
  422. // "vid": '',
  423. // "playauth": '',
  424. // "playConfig": {
  425. // "EncryptType": 'AliyunVoDEncryption'
  426. // },
  427. "skinLayout": [{
  428. "name": "bigPlayButton",
  429. "align": "blabs",
  430. "x": 30,
  431. "y": 80
  432. },
  433. {
  434. "name": "H5Loading",
  435. "align": "cc"
  436. },
  437. {
  438. "name": "controlBar",
  439. "align": "blabs",
  440. "x": 0,
  441. "y": 0,
  442. "children": [{
  443. "name": "progress",
  444. "align": "blabs",
  445. "x": 0,
  446. "y": 44
  447. },
  448. {
  449. "name": "playButton",
  450. "align": "tl",
  451. "x": 15,
  452. "y": 12
  453. },
  454. {
  455. "name": "fullScreenButton",
  456. "align": "tr",
  457. "x": 10,
  458. "y": 12
  459. },
  460. {
  461. "name": "timeDisplay",
  462. "align": "tr",
  463. "x": 10,
  464. "y": 5
  465. }
  466. ]
  467. }
  468. ],
  469. "qualitySort": "asc",
  470. "format": "mp4",
  471. "mediaType": "video",
  472. "encryptType": 1,
  473. "progressMarkers": this.progressMarkers,
  474. "autoplay": false,
  475. "isLive": false,
  476. "rePlay": false,
  477. "playsinline": true,
  478. "preload": false,
  479. "controlBarVisibility": "hover",
  480. "useH5Prism": true
  481. }, function(player) {});
  482. this.player = player;
  483. player.on('canplay', function() {
  484. console.log('canplay', this.player.tag);
  485. player.tag.play();
  486. });
  487. player.on('ended', function(data) {
  488. that.exitFullScreen();
  489. that.$ownerInstance.callMethod('playEnd', {
  490. data: 'end'
  491. })
  492. // uni.$emit('playEnd', {
  493. // data: 'end'
  494. // });
  495. });
  496. },
  497. exitFullScreen() {
  498. if (document.exitFullscreen) {
  499. document.exitFullscreen(); // 标准方法
  500. } else if (document.mozCancelFullScreen) { // Firefox
  501. document.mozCancelFullScreen();
  502. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  503. document.webkitExitFullscreen();
  504. } else if (document.msExitFullscreen) { // IE/Edge
  505. document.msExitFullscreen();
  506. }
  507. },
  508. loadWebPlayerSDK() {
  509. return new Promise((resolve, reject) => {
  510. const s_tag = document.createElement('script'); // 引入播放器js
  511. s_tag.type = 'text/javascript';
  512. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  513. s_tag.charset = 'utf-8';
  514. s_tag.onload = () => {
  515. // console.log(this.playAuth);
  516. this.playAli()
  517. resolve();
  518. }
  519. document.body.appendChild(s_tag);
  520. const l_tag = document.createElement('link'); // 引入播放器css
  521. l_tag.rel = 'stylesheet';
  522. l_tag.href =
  523. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  524. document.body.appendChild(l_tag);
  525. });
  526. },
  527. }
  528. }
  529. </script>