lookShipin.vue 13 KB

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