lookShipin.vue 13 KB

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