lookShipin.vue 12 KB

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