danyuanInfo.vue 9.3 KB

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