lookShipin.vue 12 KB

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