lookShipin.vue 12 KB

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