lookShipinNew.vue 14 KB

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