lookShipin.vue 13 KB

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