danyuanInfo.vue 9.5 KB

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