lookShipin.vue 12 KB

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