lookShipin.vue 12 KB

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