danyuanInfo.vue 9.4 KB

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