freeVideo.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="page">
  3. <van-nav-bar
  4. :title="title"
  5. left-text="返回"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. ></van-nav-bar>
  9. <div class="courseContent">
  10. <div class="previewImg">
  11. <video ref="vueMiniPlayer" :src="videoSrc" controls autoplay v-if="showVideo" controlsList="nodownload"></video>
  12. </div>
  13. <div class="title">
  14. <p>{{ video_info.name }}</p>
  15. </div>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import {learnerCourseDetail,getFreeVideoSrc} from '../api'
  21. import {setWxConfig} from "../utils"
  22. export default {
  23. name: "video",
  24. data() {
  25. return {
  26. video_info:{
  27. name:'免费课程'
  28. },
  29. showVideo:true,
  30. title: "免费课程",
  31. videoSrc:"",
  32. courseDetail: {
  33. thumb: "",
  34. name: "",
  35. images: [],
  36. sections: []
  37. }
  38. };
  39. },
  40. watch:{
  41. videoSrc(){
  42. this.showVideo = false;
  43. this.$nextTick(()=>{
  44. this.showVideo = true;
  45. this.$nextTick(()=>{
  46. this.$refs.vueMiniPlayer.play();//播放
  47. })
  48. })
  49. }
  50. },
  51. activated(){
  52. this.init();
  53. },
  54. created() {
  55. // this.init();
  56. if(this.$isWx){
  57. setWxConfig();
  58. }
  59. },
  60. methods: {
  61. // 章节切换获取视频地址
  62. toSectionVidio(item,i) {
  63. this.courseDetail.sections.forEach((item,index)=>{
  64. item.active = false;
  65. if(index == i){
  66. item.active = true;
  67. }
  68. })
  69. let data = {
  70. index: i,
  71. link: item.link
  72. };
  73. sessionStorage.setItem('vd_info',JSON.stringify(data))
  74. this.getVideoLink(item.link)
  75. // this.videoSrc = this.courseDetail.sections[index].link
  76. },
  77. // 获取视频地址
  78. getVideoLink(link){
  79. let data = {
  80. subjectId:this.$route.params.id,
  81. link:link
  82. }
  83. getFreeVideoSrc(data).then(res=>{
  84. this.videoSrc = res
  85. }).catch(err=>{
  86. this.$router.push('/courseError')
  87. })
  88. },
  89. // 返回
  90. onClickLeft() {
  91. this.$router.go(-1);
  92. },
  93. // 初始化
  94. init() {
  95. if(this.$route.query){
  96. this.video_info = this.$route.query;
  97. this.getVideoLink(this.video_info.link)
  98. }else{
  99. this.$toast.fail('视频似乎有点问题')
  100. setTimeout(() => {
  101. this.$router.go(-1)
  102. }, 2000);
  103. }
  104. },
  105. },
  106. };
  107. </script>
  108. <style scoped lang="scss">
  109. @import url('../utils/navBar.scss');
  110. * {
  111. margin: 0;
  112. padding: 0;
  113. }
  114. img {
  115. display: block;
  116. }
  117. .page {
  118. background-color: #fff;
  119. box-sizing: border-box;
  120. .courseContent {
  121. padding: 0 0.2rem;
  122. margin-top: 0.3rem;
  123. .previewImg {
  124. border-radius: 0.1rem;
  125. overflow: hidden;
  126. width: 100%;
  127. height: 4rem;
  128. video {
  129. width: 100%;
  130. height: 4rem;
  131. }
  132. }
  133. .title {
  134. p {
  135. font-size: 0.32rem;
  136. font-weight: 600;
  137. color: #000;
  138. line-height: .5rem;
  139. // overflow: hidden;
  140. // text-overflow: ellipsis;
  141. // white-space: nowrap;
  142. // word-break: break-all;
  143. }
  144. }
  145. .tabs {
  146. height: calc(100vh - 6.25rem);
  147. position: relative;
  148. .images {
  149. margin-top: 0.1rem;
  150. img {
  151. width: 100%;
  152. }
  153. }
  154. .catelog {
  155. margin-top: 1px;
  156. border-top: 1px solid #efefef;
  157. .sup {
  158. display: flex;
  159. justify-content: space-between;
  160. align-items: center;
  161. span {
  162. font-size: 0.24rem;
  163. color: #666;
  164. line-height: 3;
  165. }
  166. }
  167. .logConetent {
  168. .logLi {
  169. border: 1px solid #efefef;
  170. border-radius: 0.1rem;
  171. padding: 0 0.2rem;
  172. margin-bottom: 0.15rem;
  173. p {
  174. padding: .2rem 0;
  175. font-size: 0.3rem;
  176. color: #000;
  177. line-height: 1.3;
  178. // overflow: hidden;
  179. // text-overflow: ellipsis;
  180. // white-space: nowrap;
  181. // word-break: break-all;
  182. }
  183. &.active{
  184. box-shadow: 1px 4px #ddd;
  185. p{
  186. color: #26A2FF;
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. .getCourse {
  195. position: absolute;
  196. bottom: 0.1rem;
  197. left: 0.1rem;
  198. width: calc(100% - 0.2rem);
  199. .getBtn {
  200. width: 100%;
  201. background-color: #26A2FF;
  202. color: #fff;
  203. // animation: getFire 3s infinite linear;
  204. border-radius: .1rem;
  205. }
  206. }
  207. }
  208. @keyframes getFire {
  209. 0% {
  210. transform: scale(0.95);
  211. }
  212. 100% {
  213. transform: scale(1.05);
  214. }
  215. }
  216. </style>