lookShipinNew.vue 15 KB

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