lookShipin.vue 13 KB

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