catalogue.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <view class="content">
  3. <es-nav-bg title="课程目录"></es-nav-bg>
  4. <!-- <view class="es-view-w-x es-mt-10">
  5. <view class="banner es-icon-auto es-br-20">
  6. <image :src="data.imgUrl"></image>
  7. </view>
  8. </view> -->
  9. <view class="video es-mt-10 es-ml-20 es-mr-20 es-mb-10 es-br-10">
  10. <video ref="myVideo" id="myVideo" :src="pickCatalog.videoUrl"
  11. @error="videoErrorCallback" :enable-progress-gesture="data.isFast==1" :enable-danmu="false" :danmu-btn="false" :danmu-list="danmuList" :initial-time="studyTimes"
  12. :poster="poster" objectFit="contain" :show-progress="data.isFast==1" :title="pickCatalog.courseName" :controls="true" :show-fullscreen-btn="true" @controlstoggle="toggleBarChange"
  13. @timeupdate="onTimeUpdate" @fullscreenchange="onFullscreenChange" @loadedmetadata="onLoadedMetadata" >
  14. </video>
  15. <!-- #ifdef APP-PLUS -->
  16. <cover-image src="/static/images/yuan-1.png" class="video-1"></cover-image>
  17. <cover-image src="/static/images/yuan-2.png" class="video-2"></cover-image>
  18. <cover-image src="/static/images/yuan-3.png" class="video-3"></cover-image>
  19. <cover-image src="/static/images/yuan-4.png" class="video-4"></cover-image>
  20. <!-- #endif -->
  21. </view>
  22. <view class="es-bc-white es-br-20" style="margin-top: -194rpx;min-height: 300rpx;">
  23. <view class="es-h-194"></view>
  24. <view class="es-view-w-x es-mt-25">
  25. <view class="es es-ac">
  26. <view class="es-icon es-w-35 es-h-31 es-icon-course-icon-6"></view>
  27. <view class="es-ml-20 es-fs-30 es-fw-600 es-f1">目录<text
  28. class="es-ml-1 es-fs-24 es-c-99">({{catalogueList.length}})</text></view>
  29. <!-- <view class="es-icon-25 es-icon-course-close"></view> -->
  30. </view>
  31. <view class="es-f1 es-bc-fa es-h-70 es-br es es-ac es-mt-30">
  32. <view class="es-icon-26 es-ml-27 es-icon-search-search"></view>
  33. <view class="es-f1 es-ipt">
  34. <input v-model="searchText" placeholder="请输入关键字搜索" class="es-fs-24" placeholder-class="es-c-b4" />
  35. </view>
  36. <view @tap="search()" class="es-w-108 es-h-58 es-br es-bc es-mr-7 es es-ac es-pc es-fw-500 es-fs-26 es-on-act">搜索
  37. </view>
  38. </view>
  39. <!-- 下面是目录列表 -->
  40. <view v-for="(item, index) in catalogueList" :key="index" @click="pickCatalogAction(index)" class="es-mt-20 es es-ac es-icon-auto es-h-100 es-view-w-x"
  41. :class="index==pickCatalogIdx?'es-icon-course-cate-bg1 es-c':'es-icon-course-cate-bg2'">
  42. <view class="es-f1">
  43. <view class="es-fs-28 es-fw-600">第{{item.courseSort}}讲</view>
  44. <view class="es-fs-22 es-mt-4">{{item.title}}</view>
  45. </view>
  46. <view class="es-w-60 es-h-31 es-icon-course-play-loading es-icon" v-if="index==pickCatalogIdx"></view>
  47. <view class="vip es-icon-auto es-icon-course-cate-bg3 es-h-42 es es-ac es-fs-22 es es-ac es-pc" v-if="index!=pickCatalogIdx">
  48. <view class="es-icon-22 es-icon-course-cate-vip"></view>
  49. <text class="es-ml-4 es-fs-22">{{ item.courseSort>2 && canShowVip(item) ? '限时特惠' : '免费'}}</text>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- #ifndef APP-PLUS -->
  55. <adMask :show="tipShow">
  56. <!-- 逐集观看提示弹窗 -->
  57. <view class="tipspop">
  58. <view class="jianyi_icon_box">
  59. <image class="jianyi_icon" src="@/static/images/ad/jianyi_icon.png" mode="aspectFill"></image>
  60. </view>
  61. <view class="tc_bg">
  62. <image src="@/static/images/ad/tc_bg.png" mode="widthFix" style="width: 100%;height: auto;"></image>
  63. </view>
  64. <view class="tipspop-con">
  65. <view class="tipspop-title">建议逐集观看,学习效果更佳</view>
  66. <view>是否返回逐集观看?</view>
  67. </view>
  68. <view class="tipspop-footer">
  69. <view class="tipspop-footer-l" @click="tipCancel">取消</view>
  70. <view @click="tipConfirm">确认</view>
  71. </view>
  72. </view>
  73. </adMask>
  74. <!-- #endif -->
  75. </view>
  76. </template>
  77. <script>
  78. import { getCourseById,getCourseVideoList,addDuration } from '@/api/course'
  79. export default {
  80. data() {
  81. return {
  82. catalogueList:[],
  83. pickCatalog:{videoUrl:"",thumbnail:"",duration:0,videoId:0,seconds:0},
  84. pickCatalogIdx:0,
  85. searchText:"",
  86. videoContext: null,
  87. video: {
  88. percent: 10, //进度百分比
  89. },
  90. data:{
  91. courseId:null,
  92. imgUrl:"",
  93. talentAvatar:"",
  94. price:"",
  95. remark:"",
  96. noteNum:0,
  97. courseName:"",
  98. description:"",
  99. cataIndex:0,
  100. isFast:false,
  101. isAutoPlay:false,
  102. },
  103. danmuList:[],
  104. tempStudyTimes:0,
  105. studyTimes:0,
  106. audioContext: null,
  107. audioPlayIng:false,
  108. showFullScreenBtn:true,
  109. isLearning:false,
  110. myVideo:null,
  111. showProgress:true,
  112. videoUrl:"https://1319721001.vod-qcloud.com/3525603bvodcq1319721001/2b3e76ac1253642698811158287/Hmod7JMfAowA.mp4",
  113. poster: "",
  114. videoId:null,
  115. isAutoPlay:false,
  116. tipShow: false,
  117. tipsIndex: null,
  118. isNext: 0
  119. }
  120. },
  121. onLoad(options) {
  122. this.courseId=options.courseId;
  123. this.videoId=options.videoId;
  124. this.isAutoPlay=options.isAutoPlay;
  125. this.tempStudyTimes=options.studyTimes;
  126. this.getCourseInfo();
  127. this.getCourseVideoList();
  128. },
  129. onShow(){
  130. // if(this.data!=null && !this.countdowning){
  131. // this.startCountsTime();
  132. // }
  133. },
  134. onReady() {
  135. this.videoContext = uni.createVideoContext("myVideo", this);
  136. },
  137. methods: {
  138. canShowVip(item){
  139. return true;
  140. if(this.myUserInfo.isVip){
  141. return false;
  142. }
  143. return item.isVip==1 && item.isBuy==0;
  144. },
  145. getCourseInfo(){
  146. getCourseById(this.courseId).then(res => {
  147. if(res.code==200){
  148. this.data=res.data;
  149. this.isNext = res.data.isNext;
  150. }
  151. },
  152. rej => {}
  153. );
  154. },
  155. search() {
  156. this.videoId = 0
  157. this.getCourseVideoList()
  158. },
  159. //课程目录
  160. getCourseVideoList(){
  161. let that=this;
  162. const params={"courseId":this.courseId,"keyword":this.searchText};
  163. getCourseVideoList(params,1,30).then(res => {
  164. if(res.code==200){
  165. this.catalogueList=res.data.list;
  166. if(this.catalogueList.length>0){
  167. if(this.videoId!=null &&this.videoId!= 0){
  168. console.log("qxj videoId="+this.videoId);
  169. this.pickCatalogIdx=this.getCatalogIdx();
  170. console.log("qxj pickCatalogIdx:"+this.pickCatalogIdx);
  171. this.pickCatalog=this.catalogueList[this.pickCatalogIdx];
  172. }else{
  173. this.pickCatalog=this.catalogueList[0];
  174. }
  175. if(this.tempStudyTimes>0){
  176. this.pickCatalog.studyTime=this.tempStudyTimes;
  177. this.initStudyTime(this.pickCatalog.studyTime);
  178. }else{
  179. if(this.pickCatalog.studyTime!=null){
  180. this.initStudyTime(this.pickCatalog.studyTime);
  181. }
  182. }
  183. //开始播放计时
  184. if(this.isAutoPlay==1){
  185. this.pickCatalogMethod(this.pickCatalogIdx);
  186. }
  187. this.poster=this.pickCatalog.thumbnail;
  188. }
  189. }
  190. },
  191. rej => {}
  192. );
  193. },
  194. addStudyCourse(){
  195. if(this.catalogueList.length==0){
  196. return;
  197. }
  198. this.pickCatalog=this.catalogueList[this.pickCatalogIdx];
  199. const parmas={"courseId":parseInt(this.courseId),"duration":this.courseDuration,"videoId":this.pickCatalog.videoId};
  200. addDuration(parmas).then(res => {
  201. if(res.code==200){
  202. this.courseDuration=0;
  203. }
  204. },
  205. rej => {}
  206. );
  207. },
  208. playVideo() {
  209. this.videoContext.play();
  210. },
  211. pauseVideo() {
  212. console.log("pause");
  213. // (uni.getElementById("myVideo"))?.pause(); //as写法测试。注意id不对时as会崩溃
  214. this.videoContext.pause();
  215. },
  216. pickCatalogAction(index){
  217. if(this.pickCatalogIdx == index) return
  218. if(this.isNext == 1 && this.pickCatalogIdx != index -1) {
  219. this.pauseVideo()
  220. this.openTips(index)
  221. return
  222. }
  223. //添加切换之前课程目录学习记录
  224. this.addStudyCourse();
  225. this.pickCatalogMethod(index);
  226. },
  227. pickCatalogMethod(index){
  228. this.pickCatalogIdx=index;
  229. this.pickCatalog=this.catalogueList[index];
  230. this.studyTimes=0;//当pickCatalog.studyTime=null 或者等于视频总时长时默认切为零
  231. if(this.pickCatalog.studyTime!=this.pickCatalog.seconds){
  232. this.studyTimes=this.pickCatalog.studyTime;
  233. }
  234. this.initStudyTime(this.studyTimes);
  235. this.poster=this.pickCatalog.thumbnail;
  236. let that=this;
  237. setTimeout(function(){
  238. that.playVideo();
  239. },200);
  240. },
  241. initStudyTime(times){
  242. this.studyTimes=times;
  243. this.courseDuration=times;
  244. },
  245. toggleBarChange(event){
  246. console.log("qxj toggleBarChange");
  247. this.showFullScreenBtn=!this.showFullScreenBtn;
  248. },
  249. onTimeUpdate(event){
  250. this.courseDuration = (event.detail.currentTime*1.0).toFixed(0);
  251. },
  252. onFullscreenChange(event){
  253. // 检查是否全屏
  254. if (event.fullscreen) {
  255. // 如果是全屏,则退出全屏
  256. //this.videoContext.exitFullScreen();
  257. }
  258. },
  259. onLoadedMetadata(e) {
  260. this.pickCatalog=this.catalogueList[this.pickCatalogIdx];
  261. if(this.pickCatalog.seconds==null){
  262. this.pickCatalog.seconds =(e.target.duration).toFixed(0);
  263. }
  264. },
  265. getCatalogIdx(){
  266. let index=0;
  267. for (var i = 0; i < this.catalogueList.length; i++) {
  268. let item=this.catalogueList[i];
  269. if(this.videoId==item.videoId){
  270. break;
  271. }
  272. index++;
  273. }
  274. return index;
  275. },
  276. videoErrorCallback(){
  277. },
  278. openTips(index){
  279. this.tipsIndex = index
  280. this.tipShow = true
  281. },
  282. tipConfirm() { // 提示确认
  283. this.tipsIndex = null
  284. this.tipShow = false
  285. // 继续播放
  286. this.playVideo()
  287. },
  288. tipCancel() { // 提示取消
  289. this.tipShow = false
  290. // 播放选择的一节
  291. //添加切换之前课程目录学习记录
  292. this.addStudyCourse();
  293. this.pickCatalogMethod(this.tipsIndex);
  294. },
  295. },
  296. onUnload() {
  297. this.addStudyCourse();
  298. let studyData={"studyTimes":this.courseDuration,"videoId":this.pickCatalog.videoId}
  299. uni.$emit('backStudyTime', studyData);
  300. }
  301. }
  302. </script>
  303. <style lang="scss" scoped>
  304. page {
  305. background-color: white;
  306. }
  307. @mixin u-flex($flexD, $alignI, $justifyC) {
  308. display: flex;
  309. flex-direction: $flexD;
  310. align-items: $alignI;
  311. justify-content: $justifyC;
  312. }
  313. .banner {
  314. height: 430rpx;
  315. }
  316. .es-icon-course-icon-6 {
  317. background-image: url(/static/images/course/icon-6.png);
  318. }
  319. .es-icon-course-close {
  320. background-image: url(/static/images/course/close.png);
  321. }
  322. .es-icon-course-cate-bg1 {
  323. background-image: url(/static/images/course/cate-bg1.png);
  324. }
  325. .es-icon-course-cate-bg2 {
  326. background-image: url(/static/images/course/cate-bg2.png);
  327. }
  328. .es-icon-course-cate-bg3 {
  329. background-image: url(/static/images/course/cate-bg3.png);
  330. }
  331. .es-icon-course-play-loading {
  332. background-image: url(/static/images/course/play-loading.png);
  333. }
  334. .es-icon-course-cate-vip {
  335. background-image: url(/static/images/course/vip.png);
  336. }
  337. .es-icon-search-search {
  338. background-image: url(/static/images/search.png);
  339. }
  340. .vip{
  341. word-break: keep-all;
  342. min-width: 87rpx;
  343. padding: 6rpx 10rpx;
  344. box-sizing: border-box;
  345. }
  346. .video {
  347. height: 380rpx;
  348. position: relative;
  349. display: flex;
  350. .cover{
  351. position: absolute;
  352. left: 0;
  353. top: 0;
  354. width: 100%;
  355. height: 100%;
  356. border-radius: 20rpx;
  357. }
  358. .playIcon{
  359. position: absolute;
  360. width:44rpx ;
  361. height: 44rpx;
  362. z-index: 10;
  363. right: 26rpx;
  364. bottom: 50rpx;
  365. }
  366. }
  367. .video video {
  368. width: 100%;
  369. height: 100%;
  370. border-radius: 20rpx;
  371. }
  372. .video .video-1,.video .video-2,.video .video-3,.video .video-4{
  373. position: absolute;
  374. width: 20rpx;
  375. height: 20rpx;
  376. z-index: 1;
  377. }
  378. .video .video-1{
  379. left:0;top:0;
  380. }
  381. .video .video-2{
  382. right:0;top:0;
  383. }
  384. .video .video-3{
  385. left:0;bottom:0;
  386. }
  387. .video .video-4{
  388. right:0;bottom:0;
  389. }
  390. .tipspop {
  391. width: 630rpx;
  392. // height: 376rpx;
  393. padding-bottom: 40rpx;
  394. background: linear-gradient( 180deg, #FFEDE3 0%, #FFFFFF 100%);
  395. border-radius: 32rpx 32rpx 32rpx 32rpx;
  396. position: relative;
  397. font-family: PingFang SC, PingFang SC;
  398. font-weight: 400;
  399. font-size: 28rpx;
  400. color: #757575;
  401. text-align: center;
  402. .jianyi_icon_box {
  403. width: 124rpx;
  404. height: 124rpx;
  405. border-radius: 50%;
  406. background: linear-gradient( 180deg, #FF9B45 0%, #FF5C03 100%);
  407. border: 12rpx solid #FFFFFF;
  408. @include u-flex(row, center, center);
  409. position: absolute;
  410. left: 50%;
  411. top: -74rpx;
  412. transform: translateX(-50%);
  413. }
  414. .jianyi_icon {
  415. height: 64rpx;
  416. width: 64rpx;
  417. }
  418. .tc_bg {
  419. width: 100%;
  420. height: auto;
  421. border-radius: 32rpx 32rpx 0 0;
  422. overflow: hidden;
  423. }
  424. &-con {
  425. padding: 0 48rpx;
  426. }
  427. &-title {
  428. margin: 14rpx 0 20rpx 0;
  429. font-weight: 500;
  430. font-size: 34rpx;
  431. color: #333333;
  432. }
  433. &-footer {
  434. padding-top: 34rpx;
  435. @include u-flex(row, center, center);
  436. view {
  437. width: 248rpx;
  438. height: 84rpx;
  439. line-height: 84rpx;
  440. text-align: center;
  441. background: #FF5C03;
  442. border-radius: 42rpx 42rpx 42rpx 42rpx;
  443. font-family: PingFang SC, PingFang SC;
  444. font-weight: 500;
  445. font-size: 32rpx;
  446. color: #FFFFFF;
  447. }
  448. .tipspop-footer-l{
  449. margin-right: 38rpx;
  450. background: #F4F4F4;
  451. color: #757575;
  452. }
  453. }
  454. }
  455. .tipsvip {
  456. width: 630rpx;
  457. // height: 624rpx;
  458. padding-bottom: 40rpx;
  459. box-sizing: border-box;
  460. background: #FFFFFF;
  461. border-radius: 32rpx 32rpx 32rpx 32rpx;
  462. overflow: hidden;
  463. font-family: PingFang SC, PingFang SC;
  464. font-weight: 400;
  465. font-size: 32rpx;
  466. color: #333333;
  467. line-height: 48rpx;
  468. .vipFrame {
  469. width: 100%;
  470. height: auto;
  471. }
  472. &-con {
  473. padding: 44rpx 48rpx;
  474. box-sizing: border-box;
  475. }
  476. &-footer {
  477. @include u-flex(row, center, center);
  478. &-btn {
  479. width: 534rpx;
  480. height: 84rpx;
  481. line-height: 84rpx;
  482. text-align: center;
  483. background: #FF5C03;
  484. border-radius: 42rpx 42rpx 42rpx 42rpx;
  485. font-family: PingFang SC, PingFang SC;
  486. font-weight: 500;
  487. font-size: 32rpx;
  488. color: #FFFFFF;
  489. }
  490. }
  491. }
  492. </style>