danyuanInfo.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
  3. mask-background-color="rgba(51, 137, 217, 0.95);">
  4. <view class="ezy-course-page" :style="{backgroundImage: 'url(' + courseBjFun() + ')'}" style="height: 80vh">
  5. <view class="icon-title-navBar-box">
  6. <!-- 关闭按钮 -->
  7. <view @click="goUpPage" class="nav-bar-icon2">返回</view>
  8. <text class="nav-bar-title">{{danyuanInfo.danyuanIntro}}</text>
  9. </view>
  10. <view class="ezy-video-box course-video-box">
  11. <view ref="videoContent" id="wgy-player-test" :playAuth="playAuth"
  12. :change:playAuth="renderScript.receiveMsg" :videoId="videoId"
  13. :change:videoId="renderScript.videoIdFun" :hideFlag="hideFlag"
  14. :change:hideFlag="renderScript.hideFlagFun" :progressMarkers="progressMarkers"
  15. :change:progressMarkers="renderScript.progressMarkersMsg" :seekTime="seekTime"
  16. :change:seekTime="renderScript.seekTimeFun" class="ezy-video">
  17. </view>
  18. </view>
  19. <!-- 核心基础题 -->
  20. <view class="course-content-border">
  21. <view class="course-content-box">
  22. <view>您将学会:</view>
  23. <view v-for="(item,index) in danyuanInfo.xuehui" :key="index">
  24. <view class="title-play-box">
  25. <icon class="course-icon"></icon>
  26. <view class="course-title">{{item}}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 能力提升题 -->
  32. <view class="course-content-border">
  33. <view class="course-content-box">
  34. <view>学习大纲</view>
  35. <view v-for="(item,index) in danyuanInfo.dagangList" :key="index">
  36. <view class="title-play-box">
  37. <icon class="course-icon"></icon>
  38. <!-- 封面 -->
  39. <!-- <image :src="item.cover" mode=""></image> -->
  40. <view class="course-title">{{item.jieName}}</view>
  41. <view class="course-title">{{item.jieIntro}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </uni-popup>
  48. </template>
  49. <script>
  50. import {
  51. nextTick,
  52. ref
  53. } from 'vue';
  54. import {
  55. onLoad,
  56. onReady
  57. } from '@dcloudio/uni-app';
  58. import {
  59. getVideoAuth,
  60. getVideoAuthYk,
  61. videoWancheng
  62. } from "@/api/shipin.js"
  63. import {
  64. toast,
  65. convertTimeToSeconds
  66. } from "@/utils/common";
  67. import cacheManager from "@/utils/cacheManager.js";
  68. import * as httpApi from "@/api/chanpinShuxue.js";
  69. export default {
  70. data() {
  71. return {
  72. danyuanId: null,
  73. danyuanInfo: {
  74. danyuanId: '',
  75. dagangList: [],
  76. danyuanIntro: '',
  77. number: '',
  78. video: '',
  79. xuehui: [],
  80. },
  81. pageData: null, //上个页面获取的视频参数(视频id)
  82. playAuth: "", //播放凭证
  83. progressMarkers: [],
  84. hideFlag: 'show',
  85. videoId: "", //阿里云视频id
  86. seekTime: '',
  87. danyuanId: '',
  88. shipinTitle: '',
  89. }
  90. },
  91. onLoad(options) {
  92. this.init(options)
  93. },
  94. onHide() {
  95. this.hideFlag = 'hide'
  96. },
  97. onUnload() {
  98. this.hideFlag = 'hide'
  99. },
  100. methods: {
  101. goUpPage() {
  102. this.$refs.popupRef.close();
  103. this.$emit('close')
  104. },
  105. // 打开弹窗
  106. handleShow(danyuanId) {
  107. this.danyuanId = danyuanId;
  108. this.getDataInfo()
  109. },
  110. handleClose() {
  111. this.$refs.popupRef.close();
  112. },
  113. courseBjFun() {
  114. return 'static/images/course/couse-shuxue-bj.png'
  115. },
  116. courseIconFun() {
  117. return 'static/images/course/shuxue-icon.png'
  118. },
  119. getDataInfo() {
  120. httpApi.getShuxueChanpinDanyuanInfo({
  121. danyuanId: this.danyuanId
  122. }).then(res => {
  123. // 重新赋值
  124. Object.assign(this.danyuanInfo, res.data)
  125. this.$refs.popupRef.open();
  126. nextTick(() => {
  127. // 针对视频进行赋值
  128. this.videoId = this.danyuanInfo.video;
  129. // 执行方法
  130. this.getLive(); //获取播放凭证
  131. })
  132. })
  133. },
  134. init(options) {
  135. this.danyuanId = options.danyuanId;
  136. this.getDataInfo()
  137. },
  138. playEnd(data) {
  139. // #ifdef APP-PLUS
  140. plus.screen.lockOrientation('portrait-primary');
  141. // #endif
  142. },
  143. getLive() {
  144. if (!this.videoId) {
  145. toast("video缺失!")
  146. return false
  147. }
  148. let req = {
  149. videoId: this.videoId
  150. }
  151. getVideoAuth(req).then(res => {
  152. this.playAuth = res.data
  153. })
  154. },
  155. markersClick(data) {
  156. this.seekTime = ""
  157. this.$nextTick(() => {
  158. this.seekTime = data.offset
  159. });
  160. },
  161. },
  162. }
  163. </script>
  164. <script module="renderScript" lang="renderjs">
  165. export default {
  166. mounted() {
  167. console.log("renderScript1")
  168. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  169. // this.loadWebPlayerSDK()
  170. },
  171. data() {
  172. return {
  173. player: null,
  174. playAuth: '',
  175. videoId: '',
  176. progressMarkers: [],
  177. isFullScreen: false,
  178. seekTime: ''
  179. }
  180. },
  181. methods: {
  182. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  183. // console.log('service层中的options发生变化')
  184. // console.log('新值', newValue)
  185. // console.log('旧值', oldValue)
  186. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  187. // instance和ownerInstance的区别是:
  188. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  189. // instance的作用目前尚不明确,官方没有给出用法
  190. if (newValue) {
  191. this.playAuth = ''
  192. this.playAuth = newValue
  193. this.loadWebPlayerSDK()
  194. }
  195. },
  196. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  197. if (newValue) {
  198. this.videoId = ''
  199. this.videoId = newValue
  200. }
  201. },
  202. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  203. if (this.player) {
  204. this.player.pause()
  205. }
  206. },
  207. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  208. if (newValue) {
  209. this.progressMarkers = newValue
  210. }
  211. },
  212. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  213. if (newValue) {
  214. this.player.play()
  215. this.player.seek(newValue)
  216. // switch (this.player.getStatus()) {
  217. // case 'init':
  218. // break;
  219. // case 'ready':
  220. // break;
  221. // case 'loading':
  222. // this.player.play()
  223. // this.player.seek(newValue)
  224. // break;
  225. // case 'play':
  226. // this.player.seek(newValue)
  227. // break;
  228. // case 'pause':
  229. // this.player.play()
  230. // this.player.seek(newValue)
  231. // break;
  232. // case 'playing':
  233. // this.player.seek(newValue)
  234. // break;
  235. // case 'waiting':
  236. // break;
  237. // case 'error':
  238. // break;
  239. // case 'ended':
  240. // break;
  241. // default:
  242. // break;
  243. // }
  244. // this.player.seek(newValue)
  245. }
  246. },
  247. playAli() {
  248. let that = this
  249. // console.log(this.videoId);
  250. // console.log(this.playAuth);
  251. //配置播放器
  252. if (!this.playAuth) {
  253. return false;
  254. }
  255. var player = new Aliplayer({
  256. id: "wgy-player-test",
  257. "vid": this.videoId,
  258. "playauth": this.playAuth,
  259. extraInfo: {
  260. poster: 'noposter'
  261. },
  262. fullscreenEvents: {
  263. fullscreenChange: (isFull) => {
  264. this.isFullScreen = isFull
  265. }
  266. },
  267. //cover: 'https://img.alicdn.com/tps/TB1EXIhOFXXXXcIaXXXXXXXXXXX-760-340.jpg',
  268. // "vid": '',
  269. // "playauth": '',
  270. // "playConfig": {
  271. // "EncryptType": 'AliyunVoDEncryption'
  272. // },
  273. "skinLayout": [{
  274. "name": "bigPlayButton",
  275. "align": "blabs",
  276. "x": 30,
  277. "y": 80
  278. },
  279. {
  280. "name": "H5Loading",
  281. "align": "cc"
  282. },
  283. {
  284. "name": "controlBar",
  285. "align": "blabs",
  286. "x": 0,
  287. "y": 0,
  288. "children": [{
  289. "name": "progress",
  290. "align": "blabs",
  291. "x": 0,
  292. "y": 44
  293. },
  294. {
  295. "name": "playButton",
  296. "align": "tl",
  297. "x": 15,
  298. "y": 12
  299. },
  300. {
  301. "name": "fullScreenButton",
  302. "align": "tr",
  303. "x": 10,
  304. "y": 12
  305. },
  306. {
  307. "name": "timeDisplay",
  308. "align": "tr",
  309. "x": 10,
  310. "y": 5
  311. }
  312. ]
  313. }
  314. ],
  315. "qualitySort": "asc",
  316. "format": "mp4",
  317. "mediaType": "video",
  318. "encryptType": 1,
  319. "progressMarkers": this.progressMarkers,
  320. "autoplay": false,
  321. "isLive": false,
  322. "rePlay": false,
  323. "playsinline": true,
  324. "preload": false,
  325. "controlBarVisibility": "hover",
  326. "useH5Prism": true
  327. }, function(player) {});
  328. this.player = player;
  329. player.on('canplay', function() {
  330. console.log('canplay', this.player.tag);
  331. player.tag.play();
  332. });
  333. player.on('ended', function(data) {
  334. that.exitFullScreen();
  335. that.$ownerInstance.callMethod('playEnd', {
  336. data: 'end'
  337. })
  338. // uni.$emit('playEnd', {
  339. // data: 'end'
  340. // });
  341. });
  342. },
  343. exitFullScreen() {
  344. if (document.exitFullscreen) {
  345. document.exitFullscreen(); // 标准方法
  346. } else if (document.mozCancelFullScreen) { // Firefox
  347. document.mozCancelFullScreen();
  348. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  349. document.webkitExitFullscreen();
  350. } else if (document.msExitFullscreen) { // IE/Edge
  351. document.msExitFullscreen();
  352. }
  353. },
  354. loadWebPlayerSDK() {
  355. return new Promise((resolve, reject) => {
  356. const s_tag = document.createElement('script'); // 引入播放器js
  357. s_tag.type = 'text/javascript';
  358. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  359. s_tag.charset = 'utf-8';
  360. s_tag.onload = () => {
  361. // console.log(this.playAuth);
  362. this.playAli()
  363. resolve();
  364. }
  365. document.body.appendChild(s_tag);
  366. const l_tag = document.createElement('link'); // 引入播放器css
  367. l_tag.rel = 'stylesheet';
  368. l_tag.href =
  369. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  370. document.body.appendChild(l_tag);
  371. });
  372. },
  373. }
  374. }
  375. </script>