danyuanInfo.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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() + ')'}">
  5. <view class="icon-title-navBar-box">
  6. <!-- 关闭按钮 -->
  7. <view @click="goUpPage" class="nav-bar-icon">x</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. },
  104. // 打开弹窗
  105. handleShow(danyuanId) {
  106. this.danyuanId = danyuanId;
  107. this.getDataInfo()
  108. },
  109. handleClose() {
  110. this.$refs.popupRef.close();
  111. },
  112. courseBjFun() {
  113. return 'static/images/course/couse-shuxue-bj.png'
  114. },
  115. courseIconFun() {
  116. return 'static/images/course/shuxue-icon.png'
  117. },
  118. getDataInfo() {
  119. httpApi.getShuxueChanpinDanyuanInfo({
  120. danyuanId: this.danyuanId
  121. }).then(res => {
  122. // 重新赋值
  123. Object.assign(this.danyuanInfo, res.data)
  124. this.$refs.popupRef.open();
  125. nextTick(() => {
  126. // 针对视频进行赋值
  127. this.videoId = this.danyuanInfo.video;
  128. // 执行方法
  129. this.getLive(); //获取播放凭证
  130. })
  131. })
  132. },
  133. init(options) {
  134. this.danyuanId = options.danyuanId;
  135. this.getDataInfo()
  136. },
  137. playEnd(data) {
  138. // #ifdef APP-PLUS
  139. plus.screen.lockOrientation('portrait-primary');
  140. // #endif
  141. },
  142. getLive() {
  143. if (!this.videoId) {
  144. toast("video缺失!")
  145. return false
  146. }
  147. let req = {
  148. videoId: this.videoId
  149. }
  150. getVideoAuth(req).then(res => {
  151. this.playAuth = res.data
  152. })
  153. },
  154. markersClick(data) {
  155. this.seekTime = ""
  156. this.$nextTick(() => {
  157. this.seekTime = data.offset
  158. });
  159. },
  160. },
  161. }
  162. </script>
  163. <script module="renderScript" lang="renderjs">
  164. export default {
  165. mounted() {
  166. console.log("renderScript1")
  167. // 在适合的生命周期,通过script和link标签引入播放器sdk、css
  168. // this.loadWebPlayerSDK()
  169. },
  170. data() {
  171. return {
  172. player: null,
  173. playAuth: '',
  174. videoId: '',
  175. progressMarkers: [],
  176. isFullScreen: false,
  177. seekTime: ''
  178. }
  179. },
  180. methods: {
  181. receiveMsg(newValue, oldValue, ownerInstance, instance) {
  182. // console.log('service层中的options发生变化')
  183. // console.log('新值', newValue)
  184. // console.log('旧值', oldValue)
  185. // ownerInstance和this.$ownerInstance一样,可用来向service层通信
  186. // instance和ownerInstance的区别是:
  187. // instance.$el指向的是触发事件的那个节点;ownerInstance.$el指向当前vue文件中的根节点;
  188. // instance的作用目前尚不明确,官方没有给出用法
  189. if (newValue) {
  190. this.playAuth = ''
  191. this.playAuth = newValue
  192. this.loadWebPlayerSDK()
  193. }
  194. },
  195. videoIdFun(newValue, oldValue, ownerInstance, instance) {
  196. if (newValue) {
  197. this.videoId = ''
  198. this.videoId = newValue
  199. }
  200. },
  201. hideFlagFun(newValue, oldValue, ownerInstance, instance) {
  202. if (this.player) {
  203. this.player.pause()
  204. }
  205. },
  206. progressMarkersMsg(newValue, oldValue, ownerInstance, instance) {
  207. if (newValue) {
  208. this.progressMarkers = newValue
  209. }
  210. },
  211. seekTimeFun(newValue, oldValue, ownerInstance, instance) {
  212. if (newValue) {
  213. this.player.play()
  214. this.player.seek(newValue)
  215. // switch (this.player.getStatus()) {
  216. // case 'init':
  217. // break;
  218. // case 'ready':
  219. // break;
  220. // case 'loading':
  221. // this.player.play()
  222. // this.player.seek(newValue)
  223. // break;
  224. // case 'play':
  225. // this.player.seek(newValue)
  226. // break;
  227. // case 'pause':
  228. // this.player.play()
  229. // this.player.seek(newValue)
  230. // break;
  231. // case 'playing':
  232. // this.player.seek(newValue)
  233. // break;
  234. // case 'waiting':
  235. // break;
  236. // case 'error':
  237. // break;
  238. // case 'ended':
  239. // break;
  240. // default:
  241. // break;
  242. // }
  243. // this.player.seek(newValue)
  244. }
  245. },
  246. playAli() {
  247. let that = this
  248. // console.log(this.videoId);
  249. // console.log(this.playAuth);
  250. //配置播放器
  251. if (!this.playAuth) {
  252. return false;
  253. }
  254. var player = new Aliplayer({
  255. id: "wgy-player-test",
  256. "vid": this.videoId,
  257. "playauth": this.playAuth,
  258. extraInfo: {
  259. poster: 'noposter'
  260. },
  261. fullscreenEvents: {
  262. fullscreenChange: (isFull) => {
  263. this.isFullScreen = isFull
  264. }
  265. },
  266. //cover: 'https://img.alicdn.com/tps/TB1EXIhOFXXXXcIaXXXXXXXXXXX-760-340.jpg',
  267. // "vid": '',
  268. // "playauth": '',
  269. // "playConfig": {
  270. // "EncryptType": 'AliyunVoDEncryption'
  271. // },
  272. "skinLayout": [{
  273. "name": "bigPlayButton",
  274. "align": "blabs",
  275. "x": 30,
  276. "y": 80
  277. },
  278. {
  279. "name": "H5Loading",
  280. "align": "cc"
  281. },
  282. {
  283. "name": "controlBar",
  284. "align": "blabs",
  285. "x": 0,
  286. "y": 0,
  287. "children": [{
  288. "name": "progress",
  289. "align": "blabs",
  290. "x": 0,
  291. "y": 44
  292. },
  293. {
  294. "name": "playButton",
  295. "align": "tl",
  296. "x": 15,
  297. "y": 12
  298. },
  299. {
  300. "name": "fullScreenButton",
  301. "align": "tr",
  302. "x": 10,
  303. "y": 12
  304. },
  305. {
  306. "name": "timeDisplay",
  307. "align": "tr",
  308. "x": 10,
  309. "y": 5
  310. }
  311. ]
  312. }
  313. ],
  314. "qualitySort": "asc",
  315. "format": "mp4",
  316. "mediaType": "video",
  317. "encryptType": 1,
  318. "progressMarkers": this.progressMarkers,
  319. "autoplay": false,
  320. "isLive": false,
  321. "rePlay": false,
  322. "playsinline": true,
  323. "preload": false,
  324. "controlBarVisibility": "hover",
  325. "useH5Prism": true
  326. }, function(player) {});
  327. this.player = player;
  328. player.on('canplay', function() {
  329. console.log('canplay', this.player.tag);
  330. player.tag.play();
  331. });
  332. player.on('ended', function(data) {
  333. that.exitFullScreen();
  334. that.$ownerInstance.callMethod('playEnd', {
  335. data: 'end'
  336. })
  337. // uni.$emit('playEnd', {
  338. // data: 'end'
  339. // });
  340. });
  341. },
  342. exitFullScreen() {
  343. if (document.exitFullscreen) {
  344. document.exitFullscreen(); // 标准方法
  345. } else if (document.mozCancelFullScreen) { // Firefox
  346. document.mozCancelFullScreen();
  347. } else if (document.webkitExitFullscreen) { // Chrome, Safari & Opera
  348. document.webkitExitFullscreen();
  349. } else if (document.msExitFullscreen) { // IE/Edge
  350. document.msExitFullscreen();
  351. }
  352. },
  353. loadWebPlayerSDK() {
  354. return new Promise((resolve, reject) => {
  355. const s_tag = document.createElement('script'); // 引入播放器js
  356. s_tag.type = 'text/javascript';
  357. s_tag.src = 'https://g.alicdn.com/de/prismplayer/2.9.6/aliplayer-min.js';
  358. s_tag.charset = 'utf-8';
  359. s_tag.onload = () => {
  360. // console.log(this.playAuth);
  361. this.playAli()
  362. resolve();
  363. }
  364. document.body.appendChild(s_tag);
  365. const l_tag = document.createElement('link'); // 引入播放器css
  366. l_tag.rel = 'stylesheet';
  367. l_tag.href =
  368. 'https://g.alicdn.com/de/prismplayer/2.9.6/skins/default/aliplayer-min.css';
  369. document.body.appendChild(l_tag);
  370. });
  371. },
  372. }
  373. }
  374. </script>