lookShipin.vue 14 KB

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